堆栈导航器之间的反应导航 goBack

Dmi*_*hev 6 react-native react-navigation

在我的 React 原生应用程序中,我使用的是“react-navigation”:“^3.11.0”。我有顶级bottomTabNavigator

const TabNavigator = createBottomTabNavigator({
    Main: {
        screen: balanceStack,
        navigationOptions: {
            tabBarLabel: I18n.t("balanceTabLabel"),
            tabBarIcon: ({ tintColor}: {tintColor: string}) => (
                <Icon name="home" style={{color: tintColor}} />
            )
        }
    },
    ServicesStack: {
        screen: servicesStack,
        navigationOptions: {
            tabBarLabel: I18n.t("servicesTabLabel"),
            tabBarIcon: ({ tintColor}: {tintColor: string}) => (
                <Icon name="list-box" style={{color: tintColor}} />
            )
        }
    },

}, {
    tabBarOptions: {
        activeTintColor: WHITE_COLOR,
        inactiveTintColor: WHITE_COLOR,
        style: {
            backgroundColor: PRIMARY_COLOR,
        }
    },
    backBehavior: 'history',
    swipeEnabled: true,
});
Run Code Online (Sandbox Code Playgroud)

每个选项卡的堆栈导航器:

const balanceStack = createStackNavigator({
    Balance: {
        screen: MainScreen,
    },
    FullBalance: {
        screen: FullBalanceScreen,
    },
    Payment: {
        screen: PaymentScreen,
    },
    ServiceView: {
        screen: ViewServiceScreen,
    },
}, {
    initialRouteName: 'Balance',
    headerMode: 'none',
});

const servicesStack = createStackNavigator({
    AllServices: {
        screen: AllServicesScreen,
    },
    ServiceView: {
        screen: ViewServiceScreen,
    },
    ServiceOptionAction: {
        screen: ServiceOptionsActionScreen,
    }
}, {
    initialRouteName: 'AllServices',
    headerMode: 'none',
});
Run Code Online (Sandbox Code Playgroud)

我希望所有选项卡的导航都是通用的,而不是按堆栈划分。

例如,当我导航时

Balance->FullBalanceScreen->AllServices(通过单击服务选项卡)->ServiceView

如果我单击后退按钮(调用 goBack())一次,我将返回到 AllServices。但是如果我第二次点击返回,我不会导航到 FullBalanceScreen,因为它在另一个堆栈中。我怎样才能做到这一点?

Dmi*_*hev 0

最后,我没有找到 TabNavigator 的解决方案,并将其替换为顶级 StackNavigator。\n此外,我使用自定义底部选项卡组件并将选项卡按钮的 onPress 设置为

\n\n
onPress () {\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0this.props.navigation.navigate (this.props.navigateRouteName)\n\xc2\xa0\xc2\xa0\xc2\xa0\xc2\xa0}\n
Run Code Online (Sandbox Code Playgroud)\n\n

其中navigateRouteName 是目标堆栈路由的routeName。

\n