Skip to content

Commit 879c2ea

Browse files
committed
address ai comments pt 6
1 parent aadc532 commit 879c2ea

3 files changed

Lines changed: 12 additions & 7 deletions

File tree

src/hooks/useSearchOverlay.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import {useFocusEffect} from '@react-navigation/native';
22
import React, {useCallback, useEffect, useState} from 'react';
33
import type {StyleProp, ViewStyle} from 'react-native';
4-
import {View} from 'react-native';
54
import {useSession} from '@components/OnyxListItemProvider';
65
import SearchStaticList from '@components/Search/SearchStaticList';
76
import type {SearchQueryJSON} from '@components/Search/types';
@@ -30,6 +29,8 @@ type UseSearchOverlayParams = {
3029
type UseSearchOverlayResult = {
3130
searchOverlayContent: React.ReactNode;
3231
onSearchContentReady: () => void;
32+
/** Whether the overlay lifecycle is active (armed but not yet ready). */
33+
isOverlayActive: boolean;
3334
};
3435

3536
/**
@@ -80,7 +81,7 @@ function useSearchOverlay({
8081
// The hook subscriptions (useSession, useOnyx) must remain unconditional per
8182
// rules-of-hooks, but the derived work below is the expensive part.
8283
if (isSearchReady) {
83-
return {searchOverlayContent: null, onSearchContentReady};
84+
return {searchOverlayContent: null, onSearchContentReady, isOverlayActive: false};
8485
}
8586

8687
const isTransaction = isTransactionSearchType(queryJSON?.type);
@@ -116,11 +117,9 @@ function useSearchOverlay({
116117
columns={overlayColumns}
117118
contentContainerStyle={shouldUseNarrowLayout ? contentContainerStyle : undefined}
118119
/>
119-
) : (
120-
<View />
121-
);
120+
) : null;
122121

123-
return {searchOverlayContent, onSearchContentReady};
122+
return {searchOverlayContent, onSearchContentReady, isOverlayActive: true};
124123
}
125124

126125
export default useSearchOverlay;

src/pages/Search/SearchPage.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ function SearchPage({route}: SearchPageProps) {
137137
}, []);
138138

139139
const overlayContentContainerStyle = !isMobileSelectionModeEnabled ? styles.searchListContentContainerStyles(!!hasFilterBars) : undefined;
140-
const {searchOverlayContent, onSearchContentReady} = useSearchOverlay({
140+
const {searchOverlayContent, onSearchContentReady, isOverlayActive} = useSearchOverlay({
141141
searchResults,
142142
queryJSON: currentSearchQueryJSON,
143143
shouldUseNarrowLayout,
@@ -160,6 +160,7 @@ function SearchPage({route}: SearchPageProps) {
160160
searchOverlayContent={searchOverlayContent}
161161
onSearchContentReady={onSearchContentReady}
162162
hasFilterBars={hasFilterBars}
163+
isOverlayActive={isOverlayActive}
163164
/>
164165
) : (
165166
<SearchPageWide

src/pages/Search/SearchPageNarrow/index.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ type SearchPageNarrowProps = {
6363
searchOverlayContent: React.ReactNode;
6464
onSearchContentReady: () => void;
6565
hasFilterBars: boolean;
66+
/** Whether the overlay lifecycle is active (used to trigger onSearchLayout independently of overlay content). */
67+
isOverlayActive: boolean;
6668
};
6769

6870
const tabBarContent = <TabBarBottomContent selectedTab={NAVIGATION_TABS.SEARCH} />;
@@ -78,6 +80,7 @@ function SearchPageNarrow({
7880
searchOverlayContent,
7981
onSearchContentReady,
8082
hasFilterBars,
83+
isOverlayActive,
8184
}: SearchPageNarrowProps) {
8285
const shouldShowLoadingSkeleton = useSearchLoadingState(queryJSON, searchResults);
8386
const {translate} = useLocalize();
@@ -359,6 +362,7 @@ function SearchPageNarrow({
359362
hasFilterBars={hasFilterBars}
360363
/>
361364
)}
365+
{isOverlayActive && !searchOverlayContent && <View onLayout={onSearchLayout} />}
362366
{!!searchOverlayContent && (
363367
<View
364368
style={[StyleSheet.absoluteFill, styles.appBG]}
@@ -400,6 +404,7 @@ function SearchPageNarrow({
400404
hasFilterBars={hasFilterBars}
401405
/>
402406
)}
407+
{isOverlayActive && !searchOverlayContent && <View onLayout={onSearchLayout} />}
403408
{!!searchOverlayContent && (
404409
<View
405410
style={[StyleSheet.absoluteFill, styles.appBG]}

0 commit comments

Comments
 (0)