简体   繁体   English

React Native Navigation v5 底部导航导航到新堆栈

[英]React Native Navigation v5 bottom navigation navigate to new stack

Learning React Native and I've run into a navigation issue using createBottomTabNavigator.学习 React Native 后,我遇到了使用 createBottomTabNavigator 的导航问题。 I have my screen displayed with 2 links on the bottom tab.我的屏幕在底部选项卡上显示了 2 个链接。 Link 1 - Novels, Link 2 - Profile.链接 1 - 小说,链接 2 - 简介。 When I click on Link 2, I want to go to my profile screen (which it does) but I want to replace the bottom tab with a new one (which it doesn't).当我点击链接 2 时,我想转到我的个人资料屏幕(它确实如此),但我想用一个新的(它没有)替换底部选项卡。 I've tried using the tabPress event and I can see using console.log that it catches the event, but when I add the navigation param it stops working.我试过使用 tabPress 事件,我可以看到使用 console.log 捕获事件,但是当我添加导航参数时,它停止工作。

here's the relevant code:这是相关代码:



const Stack = createStackNavigator();
const BottomTab = createBottomTabNavigator();
const headerTitle = "My Title";


function NovelsStack() {
    return (
        <Stack.Navigator screenOptions={{
            headerStyle: {
                backgroundColor: '#000',
            },
            headerTintColor: '#fff',
            headerTitleStyle: {
                fontWeight: 'bold',
                fontSize: 16,
            },
        }}>
            <Stack.Screen name="Home" component={HomeScreen} options={{ headerTitle: () => <HeaderTitle title={headerTitle} /> }} />
            <Stack.Screen name="Novels" component={TabNavigation} options={{ headerTitle: () => <HeaderTitle title={headerTitle} /> }}  />
            <Stack.Screen name="Novel" component={SelectedNovelNavigation} options={{ headerTitle: () => <HeaderTitle /> }} />
            <Stack.Screen name="Profile" component={ProfileNavigation} options={{ headerTitle: () => <HeaderTitle title={headerTitle} /> }} />
        </Stack.Navigator>
    );
}


function TabNavigation() {
    return (
        <BottomTab.Navigator
            tabBarOptions={{
                labelStyle: styles.mainTabBarLabels
            }}
        >
            <BottomTab.Screen name="Novels" options={{ title: "Novels" }} component={NovelsScreen} />
            {isAuthenticatedUser() ? (<BottomTab.Screen name="Profile" component={ProfileScreen} />)
                : (<BottomTab.Screen name="Login" component={LoginScreen} listeners={({ navigation, route }) => ({
                    tabPress: e => {
                      // Prevent default action                      
                      console.log(navigation)
                      e.preventDefault();
                
                    },
                  })}  />)
            }
        </BottomTab.Navigator>
    );
}


function ProfileNavigation() {
    return (
        <BottomTab.Navigator
            tabBarOptions={{
                labelStyle: styles.novelsTabBarLabels
            }}>
            <BottomTab.Screen name="Profile" component={ProfileScreen} options={{ title: "Profile" }} />
        </BottomTab.Navigator>
    );
}

function SelectedNovelNavigation() {
    return (
        <BottomTab.Navigator
            tabBarOptions={{
                labelStyle: styles.novelsTabBarLabels
            }}>
            <BottomTab.Screen name="Novel" component={NovelScreen} />
            <BottomTab.Screen name="Comments" component={CommentsScreen} options={{ title: "Comments" }} />
            <BottomTab.Screen name="Ratings" component={RatingsScreen} options={{ title: "Ratings" }} />
            <BottomTab.Screen name="Related" component={RelatedNovelsScreen} options={{ title: "Related" }} />
        </BottomTab.Navigator>
    )
}

What I want to happen is when the user presses the "Profile" tab on the TabNavigation Stack, that the navigation takes the user to show the ProfileNavigation where I can add additional profile tabs, but I just can't get that hooked up correctly.我想要发生的是,当用户按下 TabNavigation 堆栈上的“配置文件”选项卡时,导航会引导用户显示 ProfileNavigation,我可以在其中添加其他配置文件选项卡,但我无法正确连接。 Been looking at the docs and other posts about it, but still stuck.一直在查看有关它的文档和其他帖子,但仍然卡住了。

Thanks in advance for any help在此先感谢您的帮助

As usual, once you reach out for help you get the answer.像往常一样,一旦你寻求帮助,你就会得到答案。 In the docs here ( https://reactnavigation.org/docs/bottom-tab-navigator/ ) and here ( https://reactnavigation.org/docs/stack-actions/#replace ) I can customize the tabBar and use the navigation.replace.在此处的文档( https://reactnavigation.org/docs/bottom-tab-navigator/ )和此处( https://reactnavigation.org/docs/stack-actions/#replace )中,我可以自定义 tabBar 并使用导航.替换。 The good ole docs, I was all around it, just didn't see it.好的 ole 文档,我到处都是,只是没有看到它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM