Noname
Noname

Reputation: 185

Navigation lifecycle ReactNative

Follow the instruction of ReactNative, when "we start on the HomeScreen and navigate to DetailsScreen. Then we use the tab bar to switch to the SettingsScreen and navigate to ProfileScreen. After this sequence of operations is done, all 4 of the screens are mounted! If you use the tab bar to switch back to the HomeStack, you'll notice you'll be presented with the DetailsScreen - the navigation state of the HomeStack has been preserved!"

But I want when I switch back to the HomeStack, it will be presented with the HomeScreen, not the DetailsScreen. Someone can help me, thankss <3

function App() {
return (
<NavigationContainer>
  <Tab.Navigator>
    <Tab.Screen name="First">
      {() => (
        <SettingsStack.Navigator>
          <SettingsStack.Screen
            name="Settings"
            component={SettingsScreen}
          />
          <SettingsStack.Screen name="Profile" component={ProfileScreen} />
        </SettingsStack.Navigator>
      )}
    </Tab.Screen>
    <Tab.Screen name="Second">
      {() => (
        <HomeStack.Navigator>
          <HomeStack.Screen name="Home" component={HomeScreen} />
          <HomeStack.Screen name="Details" component={DetailsScreen} />
        </HomeStack.Navigator>
      )}
    </Tab.Screen>
  </Tab.Navigator>
</NavigationContainer>
);
}

Upvotes: 0

Views: 330

Answers (1)

Ashish Sahu
Ashish Sahu

Reputation: 388

You can use onTabPress method, like below:

OnTabPress({navigation})=>{
    navigation.navigate("HomeStack",{
     screen: "Home"
   }).
}

Upvotes: 1

Related Questions