I am building an app whose navigation is based on a DrawerNavigator from the react-navigation library.
This navigator has 3 tabs:
The StackNavigator consists of one screen that lets the user search for an item, and a second screen where the user sees the search results.
I do not want the search results page to be a tab of a DrawerNavigator, this is why I implemented this structure.
The problem is: if the user has already performed a search, when he clicks on the "Search" tab, he does not come back to the search screen but to the search results screen. I would prefer that the user comes back to the search screen.
How can I achieve that?
Drawer navigator nested inside the initial screen of stack navigator with the initial screen's stack header hidden - The drawer can only be opened from the first screen of the stack. Stack navigators nested inside each screen of drawer navigator - The drawer appears over the header from the stack.
StackNavigator: When user taps a link, a new screen is put on top of old screens. TabNavigator: User navigates to different screens by tapping on tabs along the top or bottom of the screen.
You can achive this using navigation dispatch with navigationActions
import { NavigationActions } from 'react-navigation';
const resetAction = NavigationActions.reset({
index: 0,
actions: [
NavigationActions.navigate({
routeName: 'DrawerScreen',
params: {},
action: NavigationActions.navigate({ routeName: 'SearchScreen' }),
}),
],
})
navigation.dispatch(resetAction)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With