I have a Tab Navigator inside a Stack Navigator and I want the header title to be dynamically configured as the title of the tab selected. Like there's 3 tabs: Home, Profile, Add Item and I want the header title to be "Home" when in the home tab, "Profile" when in the profile tab.
I tried using onStateChange on the root navigator and setOptions on the tab navigator but onStateChange is only available in the and not in the nested navigators.
Is their anyway I can archieve this?
The navigator config is:
const TabNav = (
<Tab.Navigator>
<Tab.Screen name='Home' component={HomeScreen}/>
<Tab.Screen name='Profile' component={ProfileScreen}/>
<Tab.Screen name='Add Item' component={AddItemScreen}/>
</Tab.Navigator>
)
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen name='Login' component={LoginScreen}/>
<Stack.Screen name='App' component={TabNav}/>
</Stack.Navigator>
</NavigationContainer>