Skip to content

Commit 54a5972

Browse files
committed
allow top bar to hide on scroll with empty state
1 parent 549a8e5 commit 54a5972

2 files changed

Lines changed: 31 additions & 7 deletions

File tree

src/components/Search/index.tsx

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ function Search({
282282
const {isOffline} = useNetwork();
283283
const prevIsOffline = usePrevious(isOffline);
284284
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
285-
const {shouldUseNarrowLayout, isSmallScreenWidth, isLargeScreenWidth} = useResponsiveLayout();
285+
const {shouldUseNarrowLayout, isSmallScreenWidth, isLargeScreenWidth, isInLandscapeMode} = useResponsiveLayout();
286286
const styles = useThemeStyles();
287287
const navigation = useNavigation<PlatformStackNavigationProp<SearchFullscreenNavigatorParamList>>();
288288
const isFocused = useIsFocused();
@@ -1546,6 +1546,20 @@ function Search({
15461546
!isAnyVisibleActionLoading
15471547
) {
15481548
cancelNavigationSpans();
1549+
if (isInLandscapeMode) {
1550+
return (
1551+
<View style={[styles.flex1]}>
1552+
<EmptySearchView
1553+
similarSearchHash={similarSearchHash}
1554+
type={type}
1555+
hasResults={searchResults?.search?.hasResults}
1556+
queryJSON={queryJSON}
1557+
onScroll={onSearchListScroll}
1558+
contentContainerStyle={shouldUseNarrowLayout ? styles.searchListContentContainerStyles : styles.mt3}
1559+
/>
1560+
</View>
1561+
);
1562+
}
15491563
return (
15501564
<View style={[shouldUseNarrowLayout ? styles.searchListContentContainerStyles : styles.mt3, styles.flex1]}>
15511565
<EmptySearchView

src/pages/Search/EmptySearchView.tsx

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import {accountIDSelector} from '@selectors/Session';
33
import {validTransactionDraftIDsSelector} from '@selectors/TransactionDraft';
44
import React from 'react';
55
// eslint-disable-next-line no-restricted-imports
6-
import type {ImageStyle, TextStyle, ViewStyle} from 'react-native';
6+
import type {ImageStyle, NativeScrollEvent, NativeSyntheticEvent, StyleProp, TextStyle, ViewStyle} from 'react-native';
77
import {Linking, View} from 'react-native';
88
import type {OnyxCollection, OnyxEntry} from 'react-native-onyx';
9+
import Animated from 'react-native-reanimated';
910
import BookTravelButton from '@components/BookTravelButton';
1011
import GenericEmptyStateComponent from '@components/EmptyStateComponent/GenericEmptyStateComponent';
1112
import type {EmptyStateButton, HeaderMedia} from '@components/EmptyStateComponent/types';
1213
import {ModalActions} from '@components/Modal/Global/ModalContext';
13-
import ScrollView from '@components/ScrollView';
1414
import {SearchScopeProvider} from '@components/Search/SearchScopeProvider';
1515
import type {SearchQueryJSON} from '@components/Search/types';
1616
import Text from '@components/Text';
@@ -25,6 +25,7 @@ import useOnyx from '@hooks/useOnyx';
2525
import usePermissions from '@hooks/usePermissions';
2626
import useSearchTypeMenuSections from '@hooks/useSearchTypeMenuSections';
2727
import useThemeStyles from '@hooks/useThemeStyles';
28+
import useWindowDimensions from '@hooks/useWindowDimensions';
2829
import {startMoneyRequest} from '@libs/actions/IOU';
2930
import {openOldDotLink} from '@libs/actions/Link';
3031
import {createNewReport} from '@libs/actions/Report';
@@ -48,6 +49,8 @@ type EmptySearchViewProps = {
4849
type: SearchDataTypes;
4950
hasResults: boolean;
5051
queryJSON?: SearchQueryJSON;
52+
onScroll?: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
53+
contentContainerStyle?: StyleProp<ViewStyle>;
5154
};
5255

5356
type EmptySearchViewContentProps = EmptySearchViewProps & {
@@ -70,7 +73,7 @@ type EmptySearchViewItem = {
7073
children?: React.ReactNode;
7174
};
7275

73-
function EmptySearchView({similarSearchHash, type, hasResults, queryJSON}: EmptySearchViewProps) {
76+
function EmptySearchView({similarSearchHash, type, hasResults, queryJSON, onScroll, contentContainerStyle}: EmptySearchViewProps) {
7477
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
7578
const {typeMenuSections} = useSearchTypeMenuSections();
7679

@@ -98,6 +101,8 @@ function EmptySearchView({similarSearchHash, type, hasResults, queryJSON}: Empty
98101
groupPoliciesWithChatEnabled={groupPoliciesWithChatEnabled}
99102
hasSeenTour={hasSeenTour}
100103
queryJSON={queryJSON}
104+
onScroll={onScroll}
105+
contentContainerStyle={contentContainerStyle}
101106
/>
102107
</SearchScopeProvider>
103108
);
@@ -120,9 +125,12 @@ function EmptySearchViewContent({
120125
groupPoliciesWithChatEnabled,
121126
hasSeenTour,
122127
queryJSON,
128+
onScroll,
129+
contentContainerStyle,
123130
}: EmptySearchViewContentProps) {
124131
const {translate} = useLocalize();
125132
const styles = useThemeStyles();
133+
const {windowHeight} = useWindowDimensions();
126134

127135
const illustrations = useMemoizedLazyIllustrations(['EmptyStateTravel']);
128136
const {showConfirmModal} = useConfirmModal();
@@ -433,9 +441,11 @@ function EmptySearchViewContent({
433441
}
434442

435443
return (
436-
<ScrollView
444+
<Animated.ScrollView
437445
showsVerticalScrollIndicator={false}
438-
contentContainerStyle={[styles.flexGrow1, styles.flexShrink0]}
446+
contentContainerStyle={[styles.flexGrow1, styles.flexShrink0, contentContainerStyle, {minHeight: windowHeight}]}
447+
scrollEventThrottle={16}
448+
onScroll={onScroll}
439449
>
440450
<GenericEmptyStateComponent
441451
headerMedia={content.headerMedia}
@@ -449,7 +459,7 @@ function EmptySearchViewContent({
449459
>
450460
{content.children}
451461
</GenericEmptyStateComponent>
452-
</ScrollView>
462+
</Animated.ScrollView>
453463
);
454464
}
455465

0 commit comments

Comments
 (0)