TabNavigator里面的StackNavigator添加了headerRight按钮

时间:2018-04-03 20:17:08

标签: react-native react-navigation

我无法在我的组件中添加headerRight按钮。

我有一个StackNavigator:

const profileNavigator = StackNavigator({
Profile: {
    screen: PFProfileAuthenicate,
    navigationOptions: {
        title: 'Profile',
        headerTintColor: 'white',
        headerStyle: {
            backgroundColor: Colors.primaryInput
        }
    }}
});

TabNavigator内部:

const iosTabs = TabNavigator({
Profile: {
    screen: profileNavigator,
    navigationOptions: {
        tabBarLabel: 'Profile',
        tabBarIcon: ({tintColor}) => (
            <Image
                source={require('../assets/face.png')}
                style={[styles.icon, {tintColor: tintColor}]}
            />
        )
    }
} [...other tabs]
}, {
tabBarPosition: 'bottom',
});

验证者组件只是呈现这个:

render() {

    if (this.props.authStore.isLoggedIn)
        return <PFProfile navigation={this.props.navigation}/>;
    else
        return <PFLogin/>;
}

我正在尝试向PFProfile组件中的标头添加一个右save按钮。我已经尝试了this以及我能找到的所有其他内容。

我认为它与如何在导航器中实际定义有问题的组件有关,但我尝试过的任何东西都无法使其工作。

我对这一切都是新手。我把一切都搞定了吗?这是呈现登录与配置文件的最佳方式吗?任何帮助都会受到赞赏。

1 个答案:

答案 0 :(得分:1)

要把它放在这里,并且所有人都可以告诉我它是否完全脱离了墙:

您在上面看到我如何将导航对象从PFProfileAuthentication传递给PFProfile?

好吧,在PFProfile中,我这样做(并且有效):

constructor(props)
{
    super(props);
    if (this.props.navigation.state.routeName === 'ProfileAuthenticator') {
        this.props.navigation.replace('Profile');
    }
}

现在PFProfile在堆栈中,我的navigationOptions应用于标题,以便显示我的按钮。