I have a bottom tab bar created with createBottomTabNavigator
, and when the user presses on one of the tabs I need to navigate to a particular stack (created with createStackNavigator
). I can do that already, but now I need to decide which screen in that stack to go to first, depending on a condition. I know about the initialRouteName property that can be set to ensure a particular screen always shows first, so maybe I can use that?
Basically I want the user to view a tutorial the first time when pressing the tab, and the actual screen from the second time onwards.
Here is what I have currently (not working):
const shouldGoToTutorial = async () => {
await AsyncStorage.getItem('hasSeenTutorial').then((hasSeenTutorial) => {
return hasSeenTutorial ? 'Screen1' : 'Tutorial';
});
}
const OtherStack = createStackNavigator({
Tutorial: TutorialScreen,
Other: OtherScreen
}, {
initialRouteName: shouldGoToTutorial
});