So, I'm trying to use React Navigation and I want to use the same Header component across all my screens.
I used the expo-cli to create the project.
In my MainTabNavigator.js file, I have a HomeStack and SettingsStack, and they look like this:
const config = Platform.select({
web: { headerMode: "screen" },
default: {}
});
const HomeStack = createStackNavigator(
{
Home: HomeScreen
},
config
);
HomeStack.navigationOptions = {
tabBarIcon: ({ focused }) => (
<NavButton
focused={focused}
name={focused ? "star" : "create"}
label={focused ? "Save" : "New"}
/>
)
};
HomeStack.path = "";
At the bottom of the file, I have my tabNavigator
const tabNavigator = createBottomTabNavigator(
{
HomeStack,
SettingsStack
},
{
tabBarOptions: {
inactiveTintColor: "#fff",
labelStyle: {
fontSize: 14
},
showLabel: false,
style: {
backgroundColor: "#fff",
borderTopColor: "#fff",
height: 70,
paddingBottom: 10,
paddingTop: 10
}
}
}
);
tabNavigator.path = "";
export default tabNavigator;
I tried adding a <Header /> component in the navigatorOptions and defaultNavigationOption above the tabBarOptions in the createBottomTabNavigator function.
Similar to this:
...
{
navigationOptions: {
header: <Header />
},
tabBarOptions: {
inactiveTintColor: "#fff",
labelStyle: {
fontSize: 14
},
...
but this just gives me a blank header... not using my component.
I currently have the functionality I want, but I have to go into each Screen file and add:
HomeScreen.navigationOptions = {
header: <Header />
};
Currently using "react-navigation": "^3.11.0"
Any help is appreciated!