Skip to content

move scroll to onLayout #61547

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/components/Search/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ type SearchListProps = Pick<FlatListPropsWithLayout<SearchListItem>, 'onScroll'

/** Called when the viewability of rows changes, as defined by the viewabilityConfig prop. */
onViewableItemsChanged?: (info: {changed: ViewToken[]; viewableItems: ViewToken[]}) => void;

/** Invoked on mount and layout changes */
onLayout?: () => void;
};

const onScrollToIndexFailed = () => {};
Expand All @@ -101,6 +104,7 @@ function SearchList(
queryJSONHash,
shouldGroupByReports,
onViewableItemsChanged,
onLayout,
}: SearchListProps,
ref: ForwardedRef<SearchListHandle>,
) {
Expand Down Expand Up @@ -393,6 +397,7 @@ function SearchList(
removeClippedSubviews
onViewableItemsChanged={onViewableItemsChanged}
onScrollToIndexFailed={onScrollToIndexFailed}
onLayout={onLayout}
/>
<Modal
isVisible={isModalVisible}
Expand Down
7 changes: 5 additions & 2 deletions src/components/Search/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {useOnyx} from 'react-native-onyx';
import FullPageErrorView from '@components/BlockingViews/FullPageErrorView';
import FullPageOfflineBlockingView from '@components/BlockingViews/FullPageOfflineBlockingView';
import SearchTableHeader from '@components/SelectionList/SearchTableHeader';
import type {ReportActionListItemType, ReportListItemType, SearchListItem, TransactionListItemType} from '@components/SelectionList/types';
import type {ReportActionListItemType, ReportListItemType, SearchListItem, SelectionListHandle, TransactionListItemType} from '@components/SelectionList/types';
import SearchRowSkeleton from '@components/Skeletons/SearchRowSkeleton';
import useLocalize from '@hooks/useLocalize';
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
Expand Down Expand Up @@ -158,6 +158,8 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
const [reportActions] = useOnyx(ONYXKEYS.COLLECTION.REPORT_ACTIONS, {canBeMissing: true});
const previousReportActions = usePrevious(reportActions);
const {translate} = useLocalize();
const searchListRef = useRef<SelectionListHandle | null>(null);

const shouldGroupByReports = groupBy === CONST.SEARCH.GROUP_BY.REPORTS;

const {canUseTableReportView} = usePermissions();
Expand Down Expand Up @@ -540,7 +542,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
return (
<SearchScopeProvider isOnSearch>
<SearchList
ref={handleSelectionListScroll(sortedSelectedData)}
ref={searchListRef}
data={sortedSelectedData}
ListItem={ListItem}
onSelectRow={openReport}
Expand Down Expand Up @@ -579,6 +581,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS
}
queryJSONHash={hash}
onViewableItemsChanged={onViewableItemsChanged}
onLayout={() => handleSelectionListScroll(sortedSelectedData, searchListRef.current)}
/>
</SearchScopeProvider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/hooks/useSearchHighlightAndScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ function useSearchHighlightAndScroll({searchResults, transactions, previousTrans
* Callback to handle scrolling to the new search result.
*/
const handleSelectionListScroll = useCallback(
(data: SearchListItem[]) => (ref: SelectionListHandle | null) => {
(data: SearchListItem[], ref: SelectionListHandle | null) => {
// Early return if there's no ref, new transaction wasn't brought in by this hook
// or there's no new search result key
if (!ref || !triggeredByHookRef.current || newSearchResultKey === null) {
Expand Down