使用createBottomTabNavigator时是否可以从第二个选项卡开始?

问题描述

我想使标签导航器保持可视化,以保持此顺序:“首页标签,“连接”标签,“聊天”标签

但是我想让“连接”选项卡(第二个选项卡)成为加载应用程序时打开的第一个选项卡。我看不到一种在不重新排列选项卡顺序的情况下将其添加到堆栈导航器的方法。除了第一个标签以外,还有其他方法可以定位此标签

const switchNavigator = createSwitchNavigator({
  LoadingScreen,FirstLoginScreen,loginFlow: createStackNavigator({
    Main: MainScreen,EmailLogin: EmailLoginScreen,PhoneLogin: RegisterScreens,}),mainFlow: createBottomTabNavigator(
    {
      Home: createStackNavigator({
        HomeScreen,EditaccountScreen,EditPreferencesScreen,EditProfileScreen,ProfileCardScreen,Connect: ConnectionsScreen,Chat: createStackNavigator({
        AllChatScreen,SingleChat,})
    },{
      defaultNavigationoptions: ({navigation}) => ({
        tabBarIcon: ({tintColor}) => {
          const {routeName} = navigation.state;
          if (routeName === "Home") {
            return <MaterialIcons name={"home"} size={20} color={tintColor} />;
          } else if (routeName === "Connect") {
            return <MaterialIcons name={"link"} size={20} color={tintColor} />;
          } else if (routeName === "Chat") {
            return <MaterialIcons name={"chat"} size={20} color={tintColor} />;
          }
        },tabBarOptions: {
        activeTintColor: Colors.Brick,inactiveTintColor: Colors.Gray,},}
  ),});

解决方法

您可以传递名称为 “ initialRouteName” 的道具,该道具的名称是您在首次进入导航时要显示的路线的名称。

here you can fine more details with React Navigation V5