Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fturkyilmaz/ead9987744cbaadd893cba5f6a6e9b3b to your computer and use it in GitHub Desktop.
Save fturkyilmaz/ead9987744cbaadd893cba5f6a6e9b3b to your computer and use it in GitHub Desktop.
React Native - React Navigation v6 Tab Bar Hidden
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