Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React navigation tabBarVisible: false not working for StackNavigator inside TabNavigator

I am totally confused to achieve something like below, this is working fine but can't hide tab bar for EditPage and PageTwo

  • Login
  • SignUp
  • TabNavigator(TabNavigator)
    • FirstTab
    • SecondTab(StackNavigator)
      • ListPage
      • EditPage
    • ThirdTab(StackNavigator)
      • PageOne
      • PageTwo
    • Settings

Below is my configuration for it.

import { createStackNavigator, createSwitchNavigator, createBottomTabNavigator } from 'react-navigation';
//Other required imports here

const SignedOut = createStackNavigator({
  Signup: { screen : Signup},
  Login: { screen : Login}
});

const SignedIn = createBottomTabNavigator({
    Dashboard: {
      screen: Dashboard
    },
    Rewards: {
      screen: createStackNavigator({
        Rewards:{
          screen: Rewards,
          navigationOptions:{
            header:null
          }
        },
        AddReward:{
          screen: AddReward,
          navigationOptions:{
            header:null,
            tabBarVisible: false
          }
        }
      })
    },
    Activities: {
      screen: createStackNavigator({
        Rewards:{
          screen: Activities,
          navigationOptions:{
            header:null
          }
        },
        NewActivity:{
          screen: NewActivity,
          navigationOptions:{
            header:null,
            tabBarVisible: false
          }
        }
      })
    },
    Settings: {
      screen: Settings
    }
},{
  tabBarComponent: ({navigation}) => <FooterComponent navigation={navigation} />,
  tabBarPosition: 'bottom',
  animationEnabled: false,
  swipeEnabled: false
});

export const createRootNavigator = (signedIn) => {
    return createSwitchNavigator(
        {
            SignedIn: {
                screen: SignedIn
            },
            SignedOut: {
                screen: SignedOut
            }
        },
        {
            initialRouteName: (signedIn) ? "SignedIn" :"SignedOut",
            headerMode: 'none'
        }
    );
};

Problems

  • I can't hide tab bar for AddReward and NewActivity
  • tabBarVisible: false not working for StackNavigator inside TabNavigator

Thanks

like image 485
Javascript Hupp Technologies Avatar asked Jun 05 '18 13:06

Javascript Hupp Technologies


2 Answers

You could use one StackNavigator with all your stacks, and set the TabNavigator as default route :

  • SwitchNavigator
    • Login
    • SignUp
    • StackNavigator
      • TabNavigator
        • FirstTab
        • ListPage
        • Settings
      • EditPage
      • PageTwo
like image 166
sanjar Avatar answered Oct 03 '22 04:10

sanjar


The problem is that your screens (Rewards and AddRewards are inside a Stack Navigator)

OLD:

 Rewards: {
          screen: createStackNavigator({
            Rewards:{
              screen: Rewards,
              navigationOptions:{
                header:null
              }
            },
            AddReward:{
              screen: AddReward,
              navigationOptions:{
                header:null,
                tabBarVisible: false
              }
            }
          })
        }

FIX:

    Rewards: {
          screen: createStackNavigator({
            Rewards,
            AddReward,
          }),
          navigationOptions:{
            header:null,
            tabBarVisible: false
          }
        }
like image 43
MarianIordache Avatar answered Oct 03 '22 04:10

MarianIordache