I have the following stack navigation and screens:
export const HomeStack = createStackNavigator({
Home: HomeScreen,
Categories: CategoriesScreen,
Products: ProductsScreen,
ProductDetails: ProductDetailsScreen,
})
I want to hide tabs only in ProductDetailsScreen
export const hideTabBarComponents = [
'ProductDetails',
]
export const MainTabs = createBottomTabNavigator(
{
Home: HomeStack,
Favorite: FavoriteScreen,
Account: AccountScreen,
Help: HelpScreen,
Events: EventsScreen
},
{
navigationOptions: ({ navigation }) => ({
tabBarIcon: ({ focused, tintColor }) => {
...
},
tabBarLabel: ({ focused, tintColor }) => {
...
},
tabBarVisible: ! hideTabBarComponents.includes(navigation.state.routeName)
}),
}
);
The problem that can't pass any options to Tab navigation from Stack Navigation
Not all of the stack screens only one of them
This is the solution that I used in my project.
I have a bottom tab navigator, with 2 routes: Home and Profile. The ProfileHomePage route brings to a stack navigation ProfileStackNavigation.
Then, in the ProfileStackNavigation, I have the ProfileHomePage where the bottom tab should appears, and other child pages, where the bottom tabs should not be visible. I added a param
tabBarVisible: false
in that pages.Finally, in the MainTabNavigator ProfileHomePage route, I added the navigationOptions function, to test if the current route has the param tabBarVisible.
first let's creat a stack navigator and call it StackHome
With createBottomTabNavigator you can hide it with the defaultNavigationOptions
After a little search, The following code solved the problem:
This is how I did. Select the stack in which you want to hide the tab bar. You can select it based on the index.
Here is the link of the docs of React navigation
For React Navigation 5, you can do this inside of the stack component:
https://reactnavigation.org/docs/en/navigation-prop.html#setoptions---update-screen-options-from-the-component
Be careful with using this though, you'll want to reset the tabBarVisible to true once unmounting the component.
For example, with React hooks inside the Stack component:
Or you can reset the tabBarVisible in the Stack.Screen component with the back button press like this:
(The second approach works better.)