This is how I hide the tab bar in a specific screen in a stack (React Nav 5.x & 6.x)
import { getFocusedRouteNameFromRoute } from '@react-navigation/native';
const ProfileStack = createStackNavigator();
const ProfileNavigator = ({ navigation, route }) => {
React.useLayoutEffect(() => {
const routeName = getFocusedRouteNameFromRoute(route);
if (routeName === "Group"){
navigation.setOptions({tabBarVisible: false});
}else {
navigation.setOptions({tabBarVisible: true});
}
}, [navigation, route]);
return(
<ProfileStack.Navigator>
<ProfileStack.Screen name="Profile" component={ProfileScreen} />
<ProfileStack.Screen name="Group" component={GroupScreen} />
</ProfileStack.Navigator>
)};
If you guys have number of screens that need to hide the tabbar use a string array of those route names and hide tabbar if focused route name includes in that array
const tabHiddenRoutes = ["Group","Map"];
if(tabHiddenRoutes.includes(getFocusedRouteNameFromRoute(route))){
navigation.setOptions({tabBarVisible: false});
}else{
navigation.setOptions({tabBarVisible: true});
}
[Edit] – In case of v6, use display because tabBarVisible is deprecated in the favour of tabBarStyle–
if(tabHiddenRoutes.includes(getFocusedRouteNameFromRoute(route))){
navigation.setOptions({tabBarStyle: {display: 'none'}});
} else {
navigation.setOptions({tabBarStyle: {display: 'flex'}});
}