Skip to content

Commit 88e9426

Browse files
committed
move whole logic to hook
1 parent 4edb1ae commit 88e9426

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

src/components/Search/index.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ function Search({
402402
// eslint-disable-next-line react-hooks/exhaustive-deps
403403
}, [isSmallScreenWidth]);
404404

405-
const {newSearchResultKeys, handleSelectionListScroll, newTransactions} = useSearchHighlightAndScroll({
405+
const {newSearchResultKeys, handleSelectionListScroll, newTransactions, hasQueuedHighlights} = useSearchHighlightAndScroll({
406406
searchResults,
407407
transactions,
408408
previousTransactions,
@@ -415,15 +415,15 @@ function Search({
415415
shouldUseLiveData,
416416
});
417417

418-
// Mirror `newSearchResultKeys` into a ref so the post-create-flow `useFocusEffect`
418+
// Mirror `hasQueuedHighlights` into a ref so the post-create-flow `useFocusEffect`
419419
// (which has empty deps) can read the latest value without re-creating its callback.
420420
// Used to skip the deferral that would otherwise hide the freshly-added row from
421421
// FlashList during the RHP dismiss transition, which would prevent the highlight
422422
// animation from ever firing on it.
423-
const newSearchResultKeysRef = useRef(newSearchResultKeys);
423+
const hasQueuedHighlightsRef = useRef(hasQueuedHighlights);
424424
useEffect(() => {
425-
newSearchResultKeysRef.current = newSearchResultKeys;
426-
}, [newSearchResultKeys]);
425+
hasQueuedHighlightsRef.current = hasQueuedHighlights;
426+
}, [hasQueuedHighlights]);
427427

428428
// There's a race condition in Onyx which makes it return data from the previous Search, so in addition to checking that the data is loaded
429429
// we also need to check that the searchResults matches the type and status of the current search
@@ -484,7 +484,7 @@ function Search({
484484
// skip the skeleton-during-transition defer. Otherwise FlashList stays empty
485485
// for ~1s while the RHP dismiss transition runs, the row never mounts inside
486486
// the 300ms highlight window, and `useAnimatedHighlightStyle` never fires.
487-
if (newSearchResultKeysRef.current && newSearchResultKeysRef.current.size > 0) {
487+
if (hasQueuedHighlightsRef.current) {
488488
return;
489489
}
490490

src/hooks/useSearchHighlightAndScroll.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ function useSearchHighlightAndScroll({
312312
triggeredByHookRef.current = false;
313313
};
314314

315-
return {newSearchResultKeys, handleSelectionListScroll, newTransactions};
315+
const hasQueuedHighlights = newSearchResultKeys !== null && newSearchResultKeys.size > 0;
316+
317+
return {newSearchResultKeys, handleSelectionListScroll, newTransactions, hasQueuedHighlights};
316318
}
317319

318320
/**

0 commit comments

Comments
 (0)