Skip to content

Commit

Permalink
Updating the header title for the nested child navigator
Browse files Browse the repository at this point in the history
  • Loading branch information
amandeepmittal committed Feb 10, 2020
1 parent 9dabe80 commit 2c1a987
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion reactnav5-tab-navigator/src/navigation/AppNavigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,19 @@ import Profile from '../screens/Profile'
const Stack = createStackNavigator()
const Tab = createBottomTabNavigator()

function getHeaderTitle(route) {
const routeName = route.state
? route.state.routes[route.state.index].name
: route.params?.screen || 'Home'

switch (routeName) {
case 'Home':
return 'Home'
case 'Profile':
return 'Profile'
}
}

function MainTabNavigator() {
return (
<Tab.Navigator
Expand Down Expand Up @@ -55,7 +68,13 @@ function MainStackNavigator() {
headerBackTitleVisible: false
}}
headerMode='float'>
<Stack.Screen name='Home' component={MainTabNavigator} />
<Stack.Screen
name='Home'
component={MainTabNavigator}
options={({ route }) => ({
headerTitle: getHeaderTitle(route)
})}
/>
<Stack.Screen
name='Detail'
component={Detail}
Expand Down

0 comments on commit 2c1a987

Please sign in to comment.