React Native-向堆栈导航添加逻辑

问题描述 投票:0回答:1

我有以下堆栈导航:

const WelcomeStack = createStackNavigator({
    UpdateProfileScreen: {
        screen: UpdateProfileScreen,
    },
    SelectProfileScreen: {
        screen: SelectProfileScreen,
    },
    PresentationModal: {
        screen: PresentationModal,
    }
}, {
    initialRouteName: 'UpdateProfileScreen',
    headerMode: 'none'
})

[当用户是新用户时,我首先显示“ UpdateProfileScreen”,然后移至“ SelectProfileSecreen”,然后移至“ PresentationModal”。

[如果出于某种原因,“ UpdateProfileScreen”用户关闭应用程序后,下次他们登录时,我将显示“ SelectProfileSecreen”和“ PresentationModal”。如果他们下次完成数据,他们只会看到“ PresentationModal”

由于我已将“ UpdateProfileScreen”设置为initialRoute,因此即使未显示,它也将始终首先加载。

所以我想知道是否可以通过编程方式更改initialRoute和/或是否可以这样做:

this.props.navigation.navigate("WelcomeStack")

我可以在同一堆栈中添加一些逻辑来处理要显示的页面吗?

react-native react-navigation
1个回答
0
投票

[我认为您最好的选择是使用SwitchNavigator(RouteConfigs, SwitchNavigatorConfig),您可以简单地用createSwitchNavigator创建它,因为它控制了大多数反应本机应用程序中主要用于身份验证流程的所有导航器的切换。

话虽如此,对于您的情况,我认为这是实现所需行为的最合适方法。

[如果使用类似:来发布应用程序,请注意:>

this.props.navigation.navigate("WelcomeStack") 

因为它可能是一个严重的安全漏洞

docs:https://reactnavigation.org/docs/1.x/switch-navigator/

小吃示例:https://snack.expo.io/@react-navigation/auth-flow

© www.soinside.com 2019 - 2024. All rights reserved.