1

我正在编写一个使用反应导航的应用程序。我的应用程序有一个底部 TabNavigator,其中每个选项卡都由一个 stackNavigator 组成,如下所示:

路线.js:

const FirstStack = createStackNavigator({
    First: {
        screen: FirstScreen,
        navigationOptions: {
            header: props => <AppToolbar />
        }
    }
});

const SecondStack = createStackNavigator({
    Second: {
        screen: SecondScreen,
        navigationOptions: {
            header: props => <AppToolbar />
        }
    }
});

const ThirdStack = createStackNavigator({
    Third: {
        screen: ThirdScreen,
        navigationOptions: {
            header: props => <AppToolbar />
        }
    }
});

const FourthStack = createStackNavigator({
    Fourth: {
        screen: FourthScreen,
        navigationOptions: {
            header: props => <AppToolbar />
        }
    }
});

const FifthStack = createStackNavigator({
    Fifth: {
        screen: FifthScreen,
        navigationOptions: {
            header: props => <AppToolbar />
        }
    }
});

export const AppStack = createBottomTabNavigator(
    {
        First: {
            screen: FirstStack,
            navigationOptions: {
                title: "First",
                tabBarLabel: "First",
                tabBarIcon: ({ tintColor }) => (
                    <Icon name="ios-home" color={tintColor} size={24} />
                )
            }
        },
        Second: {
            screen: SecondStack,
            navigationOptions: {
                title: "Second",
                tabBarLabel: "Second",
                tabBarIcon: ({ tintColor }) => (
                    <Icon name="ios-clock" color={tintColor} size={24} />
                )
            }
        },
        Third: {
            screen: ThirdStack,
            navigationOptions: {
                title: "Third",
                tabBarLabel: "Third",
                tabBarIcon: ({ tintColor }) => (
                    <Icon name="ios-fitness" color={tintColor} size={24} />
                )
            }
        },
        Fourth: {
            screen: FourthStack,
            navigationOptions: {
                title: "Fourth",
                tabBarLabel: "Fourth",
                tabBarIcon: ({ tintColor }) => (
                    <Icon
                        name="ios-cloud-download"
                        color={tintColor}
                        size={24}
                    />
                )
            }
        },
        Fifth: {
            screen: FifthStack,
            navigationOptions: {
                title: "Fifth",
                tabBarLabel: "Fifth",
                tabBarIcon: ({ tintColor }) => (
                    <Icon name="ios-person" color={tintColor} size={24} />
                )
            }
        }
    },
    {
        initialRouteName: "First",
        order: ["First", "Second", "Third", "Fourth", "Fifth"],
        tabBarOptions: {
            activeTintColor: "white",
            inactiveTintColor: "grey",
            style: {
                backgroundColor: "#121212",
                borderTopColor: "#303030"
            }
        }
    }
);

tabNavigator 中的选项卡内的每个 stackNavigator 都有自己的标题,以便我可以自定义每个选项卡的标题,但所有标题都有一个按钮,该按钮应该导航到配置文件屏幕(在本示例中为联系人图标)。

应用工具栏.js:

const appToolbar = props => {
    return (
        <View style={styles.toolbar}>
            <Text style={styles.toolbarTitle}>Title</Text>
            <TouchableOpacity onPress={...}>
                <Icon
                    name="ios-contact"
                    color="grey"
                    size={30}
                    style={{ padding: 0, margin: 0, marginRight: 10 }}
                />
            </TouchableOpacity>
        </View>
    );
};

我想要做的是,通过按下联系人图标,应用程序应该导航到配置文件屏幕,我不知道它是否可以定义为可以从任何地方访问的全局路由,或者我是否必须添加配置文件屏幕到所有stackNavigator,以便从每个堆栈中的每个屏幕都可以访问它?

提前致谢!

4

1 回答 1

1

在这里找到答案https://stackoverflow.com/a/50701940/1276438

使用带有配置文件堆栈的 stackNavigator 并将 tabNavigator 作为子项,使 tabNavigator 成为默认路由。

于 2018-10-12T23:35:06.870 回答