From 1e3f31b43d97c463eeb735ea35a68a599f760714 Mon Sep 17 00:00:00 2001 From: nkdengineer Date: Wed, 7 May 2025 11:42:10 +0700 Subject: [PATCH] move scroll to onLayout --- src/components/Search/SearchList.tsx | 5 +++++ src/components/Search/index.tsx | 7 +++++-- src/hooks/useSearchHighlightAndScroll.ts | 2 +- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/components/Search/SearchList.tsx b/src/components/Search/SearchList.tsx index b193fb11cf71..aff5b5ae2704 100644 --- a/src/components/Search/SearchList.tsx +++ b/src/components/Search/SearchList.tsx @@ -77,6 +77,9 @@ type SearchListProps = Pick, '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 = () => {}; @@ -101,6 +104,7 @@ function SearchList( queryJSONHash, shouldGroupByReports, onViewableItemsChanged, + onLayout, }: SearchListProps, ref: ForwardedRef, ) { @@ -393,6 +397,7 @@ function SearchList( removeClippedSubviews onViewableItemsChanged={onViewableItemsChanged} onScrollToIndexFailed={onScrollToIndexFailed} + onLayout={onLayout} /> (null); + const shouldGroupByReports = groupBy === CONST.SEARCH.GROUP_BY.REPORTS; const {canUseTableReportView} = usePermissions(); @@ -540,7 +542,7 @@ function Search({queryJSON, currentSearchResults, lastNonEmptySearchResults, onS return ( handleSelectionListScroll(sortedSelectedData, searchListRef.current)} /> ); diff --git a/src/hooks/useSearchHighlightAndScroll.ts b/src/hooks/useSearchHighlightAndScroll.ts index 271bdd21e6cf..3c6f4d2e0d50 100644 --- a/src/hooks/useSearchHighlightAndScroll.ts +++ b/src/hooks/useSearchHighlightAndScroll.ts @@ -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) {