如何在StackNavigator中使用“ backBehavior”作为bottomTabNavigator的子导航器?

时间:2019-07-16 06:44:48

标签: react-native react-navigation

我有一个带有5个标签的bottomTabbarNavigator,并且还有一个具有6页的子StackNavigatior,是其中一个“底”标签的子导航器, 这是我的问题: 当我在子导航器中更改子页面时,我必须有一个后退按钮才能返回上一个屏幕,但是我想如果用户单击父选项卡,它可以返回上一个屏幕,实际上我需要让该选项卡作为后退它的子导航器按钮,我在我的bottomTabBarNavigator选项中也使用了“ backBehavior”,但它根本没有帮助。 这是我的代码, 我的父母导航:

export default createBottomTabNavigator({

  store :{screen : AppStore},  
  leaderboard :{screen : Leaderboard},  
  home :{screen : Homeboard},  
  profile: {screen: ProfileUser},
  setting :{screen : Settings},    
},{
  tabBarOptions: {
      scrollEnabled : true,
      upperCaseLabel: false,
      activeTintColor: '#fff',
      activeBackgroundColor :'#1f1f3c',
      inactiveTintColor: '#8583a9',
      showLabel: false,
      style: {          
          backgroundColor: '#131332',
          height: 50,
          borderTopWidth: 2,
          borderTopColor: '#aeaeae',                      
      },      
      labelStyle: {
          fontSize: 12,
          fontFamily : 'Questrial-Regular',
          marginBottom: 5
      },      
      animationEnabled: true,
        swipeEnabled: true,
        unmountInactiveRoutes: true
  },
  initialRouteName : 'home',
  backBehavior : 'order',
  //resetOnBlur : true,  // reset stack routes
  tabBarComponent: TabBar,
});

在我的主页选项卡中,有一个子堆栈导航器,如下所示: 在我的home.js中,我有:

const BattleScreens = createStackNavigator({
  dashboard: HomeDashboard,
  battleboard: Battleboard,
  matchmaking: Matchmaking,
  matchhall: Matchhall,
  singlematchboard : SingleMatchBoard,
  avatar : Avatar,
});

BattleScreens.navigationOptions = ({ navigation }) => {
  let backBehavior = 'order';
  console.log('navigation-navigation',navigation)
  let tabBarVisible = true;   
  if (navigation.state.index > 0 && navigation.state.routes[1].routeName != 'avatar') {
    tabBarVisible = false;    
  }
  return {
    tabBarVisible,
    backBehavior        
  };
};

export default BattleScreens;

这也是子页面上的导航状态示例: 在头像页面(主页选项卡的子页面)

index: 1
isTransitioning: true
key: "home"
params: undefined
routeName: "home"
routes: Array(2)
0: {routeName: "dashboard", key: "id-1563258676771-0"}
1:
key: "id-1563258676771-3"
params: undefined
routeName: "avatar"

能否请您帮我解决此问题? 谢谢。

0 个答案:

没有答案