1

I wish to make the stack navigator header title dynamic while having nested tab navigators. Here is the code

// ProjectDetailNavigator is a screen in a stack navigator
const ProjectDetailNavigator = TabNavigator(
{
    Overview: { screen: ProjectOverview },
    Detail: { screen: ProjectDetail },
},
{
tabBarOptions: {
    style: {
        backgroundColor: 'white',
    },
    labelStyle: {
        color: 'black'
    },
}
});


    ProjectDetailNavigator.navigationOptions = {    
       title: 'Dynamic Project Title',
        header: {
           style: {
              elevation: 0,
              shadowOpacity: 0,
             }
         }
      };

      export default ProjectDetailNavigator;

Possible solution i have tried but to no avail is as follows

    ProjectDetailNavigator.navigationOptions = function ({navigation}) {
    return {    
    title: `${navigation.state.params.title}` ,
header: {
    style: {
        elevation: 0,
        shadowOpacity: 0,
           }
        }
    };
};
2
  • What do you mean by nested tabs, from what i see you have an app containing a tabBar, do you want to have a title on navBar for each tab ? is this what your asking for ? Commented May 12, 2017 at 16:46
  • The tabBar is nested is nested under a stacknavigator whose title I want to make dynamic. Hence ProjectDetailNavigator is a screen in stack navigator Commented May 12, 2017 at 17:38

1 Answer 1

1

Inside the component:

static navigationOptions = ({ navigation }) => ({
    title: `${navigation.state.params.title}`
});
Sign up to request clarification or add additional context in comments.

3 Comments

inside which component ? ProjectDetailNavigator
Inside ProjectOverview or ProjectDetail... where you want to display it. Or do you want to display it in the tabBarLabel?
the header i wish to make dynamic is that of ProjectDetailNavigator not the one for ProjectOverview or ProjectDetail or tabBarLabels

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.