反应导航安装组件两次

时间:2020-06-25 13:57:03

标签: reactjs react-native react-navigation

我有一个react-native应用程序,但在react-navigation两次安装组件时遇到了麻烦。该问题与createStackNavigator有关,我找到了一个修复程序here,但是由于我使用的是与之不同的createSwitchNavigator,所以无法在我的代码中实现它。这是我的代码。

// package.json
{
  ...
  "react-native": "0.59.10",
  "react-navigation": "3.9.1",
  ...
  
}
const SignedOut = createStackNavigator({
    Register: {
        screen: RegisterContainer,
        navigationOptions: {
            header: (props: any) => <Header {...props} />
        }
    },
    Login: {
        screen: Login, navigationOptions: {
            header: (props: any) => <Header {...props} />
        }
    },
}, {
        initialRouteName: 'Login',
        navigationOptions: {
            gesturesEnabled: false,
            swipeEnabled: true,
            header: null,
        },
})
const SignedIn = createStackNavigator({
    Account: {
        screen: VerificationProcessContainer,
        navigationOptions: {
            header: (props: any) => <Header {...props} />
        },
    },
    Checkout: {
        screen: CheckoutContainer,
        navigationOptions: {
            header: (props: any) => <Header {...props} />
        },
    },
}, {
        initialRouteName: 'Account',
        navigationOptions: {
            gesturesEnabled: false,
            swipeEnabled: true,
            header: null,
        },
})

const SignedOutWithfooter = createBottomTabNavigator(
    {
        Login: SignedOut
    },
    {
        tabBarComponent: props => (<Footer {...props} />)
    }
);
const SignedInWithfooter = createBottomTabNavigator(
    {
        Account: SignedIn
    },
    {
        tabBarComponent: props => (<Footer {...props} />)

    }
);
const DrawerMenu = createDrawerNavigator({
    Home: {
        screen: createSwitchNavigator({
            Login: { screen: SignedOutWithfooter },
            Account: { screen: SignedInWithfooter, path: 'account' },

        }, {
                initialRouteName: 'Login',
            }), path: ''
    }
}, {
        contentComponent: Sidenav,
        backBehavior: 'Home',

});
const AppNavigator = createAppContainer(
    DrawerMenu
);

0 个答案:

没有答案