I'm using createStackNavigator
inside createBottomTabNavigator
from react-navigation
in my app. I want to have a title on my screen. Following React Navigation's tutorial I've implemented it this way:
createBottomTabNavigator(
{
Home: createStackNavigator(
{screen: HomePage, navigationOptions: () => { title: 'Home'}}),
...
},
However, nothing is displayed in the navigation bar. I've also tried headerTitle
though no avail.
What am I doing wrong?
To configure the header bar of a React Native application, the navigation options are used. The navigation options are a static property of the screen component which is either an object or a function. headerTitle: It is used to set the title of the active screen. headerStyle: It is used to add style to the header bar.
Provides a way for your app to transition between screens where each new screen is placed on top of a stack. By default the stack navigator is configured to have the familiar iOS and Android look & feel: new screens slide in from the right on iOS, fade in from the bottom on Android.
There are 2 ways of setting navigationOptions
, object or function
Object
{
screen: HomePage,
navigationOptions: { title: 'Home' }
}
Function that return an object
{
screen: HomePage,
navigationOptions: ({ navigation }) => {
return { title: 'Home' }
}
}
Your code doesn't work is due to you have error in your arrow function, you should add a bracket around the body so that it returning the object.
{ screen: HomePage, navigationOptions: () => ({ title: 'Home'}) }
navigationOptions shouldn't be a function, instead, is a JSON. So, remove the arrows and do it like this:
createBottomTabNavigator(
{
Home: createStackNavigator(
{screen: HomePage, navigationOptions: { title: 'Home'},
...
},
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With