【问题标题】:Opening the Drawer navigator from the bottom tab从底部选项卡打开抽屉导航器
【发布时间】:2021-02-28 02:17:57
【问题描述】:

我正在将我的应用从 react-navigation 4 升级到 5。

在版本 4 中,我有一个使用以下代码打开抽屉的选项卡

const MainNavigator = createBottomTabNavigator(
  {
More: {      
      screen: AdminNavigator,
      navigationOptions: {
        tabBarIcon: (tabInfo) => {
          //return <Ionicons name="ios-star" size={25} color={tabInfo.tintColor} />;
          return (
            <Icon
              name="tune"
              color={tabInfo.tintColor}
              size={tabInfo.focused ? 32 : 28}
              style={{
                paddingTop: 10,
              }}
            />
          );
        },
        tabBarColor: Colors.primary,       
        tabBarOnPress: ({ navigation }) => {
          navigation.openDrawer();
        },
      },
    },
}

在新版本 5 中,我有以下导航配置

<NavigationContainer>          
    <Drawer.Navigator>
       <Drawer.Screen name="Home" component={TabsScreen} />
       <Drawer.Screen name="Favorites" component={FavoritesStackScreen} />
       <Drawer.Screen name="Language" component={LanguageStackScreen} />
    </Drawer.Navigator>
</NavigationContainer>

TabScreen 是我的底部标签导航器

const TabsScreen = () => (
    <Tabs.Navigator>
        <Tabs.Screen name={"Home"} component={HomeStackScreen} />
        <Tabs.Screen name={"Cocktails"} component={CocktailsStackScreen} />
        <Tabs.Screen 
            name={"More"} 
            component={HomeStackScreen} 
            options={{
                ...
            }}
        />
    </Tabs.Navigator>
);

我正在寻找以下 V5 中的等价物

tabBarOnPress: ({ navigation }) => {
          navigation.openDrawer();
        },

【问题讨论】:

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


    【解决方案1】:

    尝试以下方法:

    <Tabs.Screen 
      name={"More"} 
      component={HomeStackScreen} 
      listeners={({ navigation }) => ({
        tabPress: e => {
          e.preventDefault();
          navigation.openDrawer();
        }
      })}
    />
    

    https://reactnavigation.org/docs/navigation-events/#listeners-prop-on-screen

    【讨论】:

    • 优秀..谢谢
    猜你喜欢
    • 2020-03-14
    • 2021-03-09
    • 2021-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多