forked from Expensify/App
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52ce458
commit 667a052
Showing
6 changed files
with
93 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import {findFocusedRoute, useNavigationState} from '@react-navigation/native'; | ||
import React, {useEffect, useRef, useState} from 'react'; | ||
import {InteractionManager, View} from 'react-native'; | ||
import useResponsiveLayout from '@hooks/useResponsiveLayout'; | ||
import useStyledSafeAreaInsets from '@hooks/useStyledSafeAreaInsets'; | ||
import useThemeStyles from '@hooks/useThemeStyles'; | ||
import {isFullScreenName, isSplitNavigatorName} from '@libs/Navigation/helpers/isNavigatorName'; | ||
import {FULLSCREEN_TO_TAB, SIDEBAR_TO_SPLIT} from '@libs/Navigation/linkingConfig/RELATIONS'; | ||
import type {FullScreenName} from '@libs/Navigation/types'; | ||
import NAVIGATORS from '@src/NAVIGATORS'; | ||
import SCREENS from '@src/SCREENS'; | ||
import BottomTabBar, {BOTTOM_TABS} from './BottomTabBar'; | ||
|
||
const SCREENS_WITH_BOTTOM_TAB_BAR = [...Object.keys(SIDEBAR_TO_SPLIT), SCREENS.SEARCH.ROOT, SCREENS.SETTINGS.WORKSPACES]; | ||
|
||
/** | ||
* TopLevelBottomTabBar is displayed when the user can interact with the bottom tab bar. | ||
* We hide it when: | ||
* 1. The bottom tab bar is not visible. | ||
* 2. There is transition between screens with and without the bottom tab bar. | ||
* 3. The bottom tab bar is under the overlay. | ||
* For cases 2 and 3, local bottom tab bar mounted on the screen will be displayed. | ||
*/ | ||
|
||
function TopLevelBottomTabBar() { | ||
const styles = useThemeStyles(); | ||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
const {paddingBottom} = useStyledSafeAreaInsets(); | ||
const [isAfterClosingTransition, setIsAfterClosingTransition] = useState(false); | ||
const cancelAfterInteractions = useRef<ReturnType<typeof InteractionManager.runAfterInteractions> | undefined>(); | ||
|
||
const selectedTab = useNavigationState((state) => { | ||
const topmostFullScreenRoute = state?.routes.findLast((route) => isFullScreenName(route.name)); | ||
return FULLSCREEN_TO_TAB[(topmostFullScreenRoute?.name as FullScreenName) ?? NAVIGATORS.REPORTS_SPLIT_NAVIGATOR]; | ||
}); | ||
|
||
// There always should be a focused screen. | ||
const isScreenWithBottomTabFocused = useNavigationState((state) => { | ||
const focusedRoute = findFocusedRoute(state); | ||
|
||
// We are checking if the focused route is a split navigator because there may be a brief moment where the navigator don't have state yet. | ||
// That mens we don't have screen with bottom tab focused. This caused glitching. | ||
return SCREENS_WITH_BOTTOM_TAB_BAR.includes(focusedRoute?.name ?? '') || isSplitNavigatorName(focusedRoute?.name); | ||
}); | ||
|
||
// Visible directly means not through the overlay. | ||
const isScreenWithBottomTabVisibleDirectly = useNavigationState((state) => isFullScreenName(state.routes.at(-1)?.name)); | ||
|
||
const shouldDisplayTopLevelBottomTabBar = (shouldUseNarrowLayout ? isScreenWithBottomTabFocused : isScreenWithBottomTabVisibleDirectly) && selectedTab !== BOTTOM_TABS.HOME; | ||
|
||
useEffect(() => { | ||
cancelAfterInteractions.current?.cancel(); | ||
|
||
if (!shouldDisplayTopLevelBottomTabBar) { | ||
// If the bottom tab is not visible, that means there is a screen covering it. | ||
// In that case we need to set the flag to true because there will be a transition for which we need to wait. | ||
setIsAfterClosingTransition(false); | ||
} else { | ||
// If the bottom tab should be visible, we want to wait for transition to finish. | ||
cancelAfterInteractions.current = InteractionManager.runAfterInteractions(() => { | ||
setIsAfterClosingTransition(true); | ||
}); | ||
} | ||
}, [shouldDisplayTopLevelBottomTabBar]); | ||
|
||
return ( | ||
<View style={styles.topLevelBottomTabBar(shouldDisplayTopLevelBottomTabBar && isAfterClosingTransition, shouldUseNarrowLayout, paddingBottom)}> | ||
<BottomTabBar | ||
selectedTab={selectedTab} | ||
shouldShowTooltip={shouldDisplayTopLevelBottomTabBar} | ||
/> | ||
</View> | ||
); | ||
} | ||
export default TopLevelBottomTabBar; |
42 changes: 0 additions & 42 deletions
42
src/libs/Navigation/AppNavigator/createRootStackNavigator/TopLevelBottomTabBar.tsx
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
src/libs/Navigation/AppNavigator/createRootStackNavigator/index.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters