Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Navigation how to hide tabbar from inside stack navigation

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

like image 781
Ahmad Abdullah Avatar asked Jul 15 '18 20:07

Ahmad Abdullah


People also ask

How do I hide the tab bar in react navigation 5?

Use setVisible from context to make the tabbar hidden.

How do I hide navigation bar in react navigation?

To hide the navigation navbar with React Native, we set the screenOptions. headerShown option to false .

How do I remove header from Tab Navigator?

(React Nav ver6. x) add this code snipet "options={{headerShown: false}}" in "<Tab. Screen />". It will delete header of each tab you add into.


1 Answers

The following code solved the problem:

HomeStack.navigationOptions = ({ navigation }) => {      let tabBarVisible = true;      let routeName = navigation.state.routes[navigation.state.index].routeName      if ( routeName == 'ProductDetails' ) {         tabBarVisible = false     }      return {         tabBarVisible,     } } 
like image 181
Ahmad Abdullah Avatar answered Oct 06 '22 05:10

Ahmad Abdullah