【问题标题】:BottomTabNavigator content is appearing twiceBottomTabNavigator 内容出现两次
【发布时间】:2020-05-11 09:21:43
【问题描述】:

我正在使用 Expo 构建一个 React-Native 应用程序。我尝试实现BottomTabNavigator,但由于某种原因,内容(TripsPage)出现了两次。

这是我的导航实现:

<NavigationContainer>
        <Stack.Navigator
          initialRouteName="TripsPage"
          screenOptions={{
            headerStyle: {
              backgroundColor: Colors.primary,
            },
            headerTintColor: 'black',
            headerTitleAlign: 'center',
            headerTitleStyle: {
              fontWeight: 'bold',
              fontSize: 18,
            },
          }}
        >
          <Stack.Screen
            name="TripDetails"
            component={TripDetails}
            options={{ title: 'Trip Details' }}
          />
          <Stack.Screen
            name="TripsPage"
            component={TripsPage}
            options={{ title: 'Home' }}
          />
          <Stack.Screen
            name="MVPForm"
            component={Form}
            options={{ title: 'Trippy' }}
          />
          <Stack.Screen
            name="Result"
            component={Result}
            options={{ title: 'Car Allocation' }}
          />
        </Stack.Navigator>
      </NavigationContainer>
      <NavigationContainer>
        <Tab.Navigator>
          <Tab.Screen name="Home" component={TripsPage} />
        </Tab.Navigator>
      </NavigationContainer>

有人熟悉这个问题吗?

【问题讨论】:

    标签: react-native react-navigation-bottom-tab


    【解决方案1】:

    您好尝试只使用一个&lt;NavigationContainer&gt; 并将所有导航器包装在其中,如下所示:

    <NavigationContainer>
        <Stack.Navigator
          initialRouteName="TripsPage"
          screenOptions={{
            headerStyle: {
              backgroundColor: Colors.primary,
            },
            headerTintColor: 'black',
            headerTitleAlign: 'center',
            headerTitleStyle: {
              fontWeight: 'bold',
              fontSize: 18,
            },
          }}
        >
          <Stack.Screen
            name="TripDetails"
            component={TripDetails}
            options={{ title: 'Trip Details' }}
          />
          <Stack.Screen
            name="TripsPage"
            component={TripsPage}
            options={{ title: 'Home' }}
          />
          <Stack.Screen
            name="MVPForm"
            component={Form}
            options={{ title: 'Trippy' }}
          />
          <Stack.Screen
            name="Result"
            component={Result}
            options={{ title: 'Car Allocation' }}
          />
        </Stack.Navigator>
        <Tab.Navigator>
          <Tab.Screen name="Home" component={TripsPage} />
        </Tab.Navigator>
      </NavigationContainer>
    

    【讨论】:

      猜你喜欢
      • 2014-06-19
      • 2017-07-01
      • 1970-01-01
      • 2014-11-27
      • 1970-01-01
      • 2021-07-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多