1

我觉得我的导航设置一团糟,我无法实现我想要的。

我有一个StackNavigator服务于一些页面一个DrawerNavigator处理一些其他页面一个BottomTabNavigator

大多数事情都有效,但似乎我不能在通过Drawer

这是我的代码,并带有一条评论,其中似乎没有处理我想要的内容:

const TabRoutes = createBottomTabNavigator({
    Dashboard: {
        screen: Dashboard,
        navigationOptions: {
            tabBarLabel: "Home",
            tabBarIcon: ({color}) => <Icon name='home' size={26} color={color} />
        }
    },
    Chat: {
        screen: Chat,
        navigationOptions: {
            tabBarLabel: "Chat",
            tabBarIcon: ({color}) => <Icon name='comments' size={26} color={color} />
        }
    }
})

const DrawerRoutes = createDrawerNavigator({
    Tabs: {
        screen: TabRoutes,
        navigationOptions: {
            drawerLabel: "Home",
            drawerIcon: ({color}) => <Icon name='home' size={24} />

            headerTitle: "Main" // *** Not handled
        }
    },
    Settings: {
        screen: Settings,
        navigationOptions: ({navigation}) => ({
            drawerLabel: "Settings",
            drawerIcon: ({color}) => <Icon name='cog' size={24} />,

            // *** This block is not handled
            // I expected it to override the headerLeft defined in the StackRoutes.Main 
            headerTitle: "Settings",
            headerLeft: (
                <Button onPress={() => navigation.goBack()}>
                    <Icon name='arrow-left' size={30} />
                </Button>
            ),
            // *** END ***
        })
    }
})


const StackRoutes = createStackNavigator({
    Splashscreen: {
        screen: Splashscreen,
        navigationOptions: {
            header: null
        }
    },
    Signin: {
        screen: Signin,
        navigationOptions: ({navigation}) => ({
            title: 'Sign in',
        })
    },
    Signup: {
        screen: Signup,
        navigationOptions: ({navigation}) => ({
            title: 'Sign up',
        })
    },
    Main: {
        screen: DrawerRoutes,
        navigationOptions: ({navigation}) => ({
            headerLeft: (
                <Button onPress={() => navigation.openDrawer()}>
                    <Icon name='bars' size={26} />
                </Button>
            )
        })
    }
})

export default StackRoutes

我究竟做错了什么?

4

0 回答 0