Created
June 15, 2023 05:41
-
-
Save fturkyilmaz/ead9987744cbaadd893cba5f6a6e9b3b to your computer and use it in GitHub Desktop.
React Native - React Navigation v6 Tab Bar Hidden
This file contains hidden or 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
import {useLayoutEffect} from 'react'; | |
import { | |
useNavigation, | |
useRoute, | |
getFocusedRouteNameFromRoute, | |
} from '@react-navigation/native'; | |
export function useTabBarHidden( | |
hiddenTabRoutesArray: string[], | |
fallbackRoute: string | undefined, | |
) { | |
const navigation = useNavigation(); | |
const route = useRoute(); | |
useLayoutEffect(() => { | |
const routeName = getFocusedRouteNameFromRoute(route) ?? fallbackRoute; | |
const includesHiddenTabRoutes = routeName | |
? hiddenTabRoutesArray.includes(routeName) | |
: false; | |
navigation.setOptions({ | |
tabBarStyle: { | |
display: includesHiddenTabRoutes ? 'none' : 'flex', | |
}, | |
}); | |
}, [navigation, route, fallbackRoute, hiddenTabRoutesArray]); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment