Bhaumik Surani
Bhaumik Surani

Reputation: 1833

react native tabbar not hide for specific screen

I'm using react-navigation.
I'm using createStackNavigator inside createBottomTabNavigator.

I want to hide tab bar for SignInScreen that is inside AccountTab but it's not working.

export default createBottomTabNavigator({
    HomeTab: { screen: createStackNavigator ({
      HomeTabScreen     : { screen:HomeTabScreen },
      ProductScreen     : { screen:ProductScreen },
    }),
      initialRouteName: 'HomeTabScreen',
    },

    AccountTab: { screen: createStackNavigator ({
      AccountTabScreen  : { screen:AccountTabScreen },
      RegisterScreen    : { screen:RegisterScreen },
      SignInScreen      : { screen:SignInScreen },
    }),
      initialRouteName: 'AccountTabScreen',
    },

  },
    {
        initialRouteName: 'HomeTab',        
        navigationOptions: ({ navigation }) => ({
            tabBarLabel: ({ focused, tintColor }) => {
                const { routeName } = navigation.state;
                let name;
                if (routeName === 'HomeTab') {
                  name = "Home";
                } else {
                  name = "Account";
                }
                return <Text style={[styles.titleStyle, focused ? styles.titleSelectedStyle : {}]}>{name}</Text>;
            },
        }),
});

I'm try three method but it's not working.
methods are following

1) I was applied tabBarVisible:false in above code so it hide tab bar for all screen.

2) I was applied function for tabBarVisible like tabBarLabel function in above code.

3) I was applied tabBarVisible:false in navigationOptions inside SignInScreen.

How to hide tabbar for SignInScreen?

Upvotes: 0

Views: 1806

Answers (3)

Pavan
Pavan

Reputation: 1289

If you want to hide tabNavigation in the screen2(part of the StackNavigator then,

navigationOptions: ({navigation}) => {
      let {routeName} = navigation.state.routes[navigation.state.index];
      let navigationOptions = {};
      console.log('Route Name=' + JSON.stringify(routeName));

      if (routeName === 'Screen') {
        navigationOptions.tabBarVisible = false;
      }

      return navigationOptions;

Upvotes: 0

needsleep
needsleep

Reputation: 2715

There is a git thread that might help you: https://github.com/react-navigation/react-navigation-tabs/issues/19#issuecomment-410857516

Basically you should try changing your AccountTab navigation options like this:

AccountTab: { 
  screen: createStackNavigator ({
        AccountTabScreen  : { screen:AccountTabScreen },
        RegisterScreen    : { screen:RegisterScreen },
        SignInScreen      : { screen:SignInScreen },
  }),
  initialRouteName: 'AccountTabScreen',
  navigationOptions: ({navigation}) => {
    let { routeName } = navigation.state.routes[navigation.state.index];
    let navigationOptions = {};

    if (routeName === 'SignInScreen') {
        navigationOptions.tabBarVisible = false;
    }

    return navigationOptions;
  }
},

Upvotes: 2

Ganesh Khartode
Ganesh Khartode

Reputation: 71

const NestedNavigator = StackNavigator({
    ScreenOne: {
        screen: ScreenOneComponent
    },
    ScreenTwo: {
        screen: ScreenTwoComponent
    }
});

class NestedNavigatorWrapper extends React.Component {
    constructor(props)  {
        super(props);
    }
    render() {
        return (
            <DashboardNavigator screenProps={{ rootNavigation: this.props.navigation }} />
        );
    }
}
const AppNavigator = StackNavigator({
    Home: {
        screen: HomeComponent
    },
    Nested: {
        screen: NestedNavigatorWrapper
    }
});

Upvotes: 0

Related Questions