反应本机标签栏不隐藏特定屏幕

react native tabbar not hide for specific screen

我正在使用反应导航。
我在 createBottomTabNavigator 中使用 createStackNavigator。

我想为 SignInScreen 隐藏 tab bar,它位于 AccountTab 中,但它不是正在工作。

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>;
            },
        }),
});

我尝试了三种方法,但都不起作用。
方法如下

1) 我在上面的代码中应用了 tabBarVisible:false 所以它隐藏了所有屏幕的 tab bar

2) 我在上面的代码中为 tabBarVisible 应用了函数,例如 tabBarLabel 函数

3) 我在 navigationOptions 中应用 tabBarVisible:falseSignInScreen.

How to hide tabbar for SignInScreen?

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
    }
});

有一个 git 话题可能会对您有所帮助: https://github.com/react-navigation/react-navigation-tabs/issues/19#issuecomment-410857516

基本上您应该尝试像这样更改您的 AccountTab 导航选项:

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;
  }
},

如果你想隐藏 screen2 中的 tabNavigation(那么 StackNavigator 的一部分,

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;