-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor FloatingActionButton to use useBottomTabIsFocused hook and a…
…dd new useBottomTabIsFocused hook for better navigation state management
- Loading branch information
1 parent
ef25dd7
commit b74ab71
Showing
3 changed files
with
77 additions
and
42 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,23 @@ | ||
import {useIsFocused, useNavigationState} from '@react-navigation/native'; | ||
import CENTRAL_PANE_SCREENS from '@libs/Navigation/AppNavigator/CENTRAL_PANE_SCREENS'; | ||
import getTopmostCentralPaneRoute from '@libs/Navigation/getTopmostCentralPaneRoute'; | ||
import getTopmostFullScreenRoute from '@libs/Navigation/getTopmostFullScreenRoute'; | ||
import type {CentralPaneName, FullScreenName, NavigationPartialRoute, RootStackParamList} from '@libs/Navigation/types'; | ||
import SCREENS from '@src/SCREENS'; | ||
import useResponsiveLayout from './useResponsiveLayout'; | ||
|
||
const useBottomTabIsFocused = () => { | ||
const {shouldUseNarrowLayout} = useResponsiveLayout(); | ||
const isFocused = useIsFocused(); | ||
const topmostFullScreenName = useNavigationState<RootStackParamList, NavigationPartialRoute<FullScreenName> | undefined>(getTopmostFullScreenRoute); | ||
const topmostCentralPane = useNavigationState<RootStackParamList, NavigationPartialRoute<CentralPaneName> | undefined>(getTopmostCentralPaneRoute); | ||
if (topmostFullScreenName) { | ||
return false; | ||
} | ||
if (shouldUseNarrowLayout) { | ||
return isFocused || topmostCentralPane?.name === SCREENS.SEARCH.CENTRAL_PANE; | ||
} | ||
return isFocused || Object.keys(CENTRAL_PANE_SCREENS).includes(topmostCentralPane?.name ?? ''); | ||
}; | ||
|
||
export default useBottomTabIsFocused; |
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