0

I am unable to add a headerRight button to my component.

I have a StackNavigator:

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

inside of a 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',
});

The authenticator component is just rendering this:

render() {

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

I am trying to add a right save button to the header in the PFProfile component. I've tried this and everything else I can find.

I'm thinking it has something to do with how the component in question isn't actually defined in navigator but nothing I've tried has been able to make this work.

I'm new to all this. Am I setting everything up right? Is that the best way to render the login vs. the profile? Any help would appreciated.

5
  • What is the problem that you are facing? Commented Apr 3, 2018 at 20:30
  • One hacky way can be to use headerMode: 'none' in your Profile stack and then put a header View manually at the top of PFProfile component Commented Apr 3, 2018 at 21:50
  • @MukeshSoni yeah, I'm not a giant fan of that idea Commented Apr 5, 2018 at 16:01
  • @PritishVaidya I've edited my question, I can't add a button or menu to the nav bar in my stacknavigator Commented Apr 5, 2018 at 16:01
  • @PritishVaidya - thanks for your answer. I'm still new to all this, I'm using Mobx so I'm looking into a Mobx solution like you describe. I've confirmed that the problem is when I use the conditional to render <PFProfile> then <PFProfile> has no navigation prop (except the one I pass to it and that one doesn't recognize the navigationOptions when I declare it in PFProfile. I wish there was a way to just replace the <PFLogin> with <PFProfile> in the render when the auth prop returns true. Commented Apr 5, 2018 at 20:32

1 Answer 1

1

Just gonna put this out here and y'all can tell me if it's totally off the wall:

You see above how I passed the navigation object from PFProfileAuthentication to PFProfile?

Well, in PFProfile I do this (and it works):

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

Now PFProfile is in the stack and my navigationOptions are applied to the header so my button shows up.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks fine, as long as it helps you solve your problem, I'm am unclear about the navigation structure and the components layout, therefore I've decided to delete my answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.