gpt4 book ai didi

react-native - 如何使用 react 导航 v5 从另一个选项卡导航到一个选项卡

转载 作者:行者123 更新时间:2023-12-04 11:51:08 25 4
gpt4 key购买 nike

我有 3 个选项卡,每个选项卡都包含一组堆栈导航器。

  • 首页|堆栈
  •     const HomeNavigator = createStackNavigator();

    const HomeStackNavigator = ({navigation, route}) => {
    return (
    <HomeNavigator.Navigator>
    <HomeNavigator.Screen
    name="Home"
    component={Home}
    />
    <HomeNavigator.Screen
    name="Profile"
    component={Profile}
    />
    <HomeNavigator.Screen
    name="Settings"
    component={Settings}
    />
    </HomeNavigator.Navigator>
    );
    };

  • 存储堆栈

  • const StoreNavigator = createStackNavigator();

    const StoreStackNavigator = ({navigation, route}) => {
    return (
    <StoreNavigator.Navigator>
    <StoreNavigator.Screen
    name="OurStore"
    component={Store}
    />
    </StoreNavigator.Navigator>
    );
    };

  • 社区栈
  •     const CommunityNavigator = createStackNavigator();

    const CommunityStackNavigator = ({navigation, route}) => {
    return (
    <CommunityNavigator.Navigator>
    <CommunityNavigator.Screen
    name="Community"
    component={Community}
    />
    <CommunityNavigator.Screen
    name="CommunityReply"
    component={CommunityReply}
    options={communityReplyOptions}
    />
    <CommunityNavigator.Screen
    name="AskCommunity"
    component={AskCommunity}
    />
    </CommunityNavigator.Navigator>
    );
    };

    标签导航器

    const MainNavigator = createBottomTabNavigator();

    const MainTabNavigator = () => {
    return (
    <MainNavigator.Navigator
    screenOptions={tabScreenOptions}
    tabBarOptions={tabBarOptions}>
    <MainNavigator.Screen
    name="HomeTab"
    component={HomeStackNavigator}
    options={{tabBarLabel: 'Home'}}
    />
    <MainNavigator.Screen
    name="StoreTab"
    component={StoreStackNavigator}
    options={{tabBarLabel: 'Store'}}
    />
    <MainNavigator.Screen
    name="CommunityTab"
    component={CommunityStackNavigator}
    options={{tabBarLabel: 'Community'}}
    />
    </MainNavigator.Navigator>
    );
    };

    现在单击按钮时的主页选项卡我需要导航到社区选项卡导航器中的 CommunityReply 屏幕。有人可以帮我解决这个问题吗
    React 导航版本
    "@react-navigation/bottom-tabs": "^5.8.0"
    "@react-navigation/native": "^5.7.3"
    "@react-navigation/stack": "^5.9.0"

    最佳答案

    下面应该在这种情况下工作:

    this.props.navigation.navigate('CommunityTab', { screen: 'CommunityReply' });

    关于react-native - 如何使用 react 导航 v5 从另一个选项卡导航到一个选项卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63566372/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com