Here is my project file hierarchy
RootTabNavigator
| AuthStackNavigator // I want to go back to this navigator
| AuthoScreen
| Welcome Screen
| MainTabNavigator // I want to reset MainTabNavigator
| FeedStacknavigator
| Screen A
| OtherStackNavigatorOne
| Screen E
| OtherStackNavigatorTwo
| Screen D
| MenuStackNavigator
| Menuo <-I'm here and want to reset to 'MainTabNavigator'
and go BACK to 'AuthScreen'
| Screen B
| Screen C
Problem
The user is on Menuo Screen under MenuStackNavigator and MainTabNavigator.
If user doesn't have a token (when user logs out), user goes back to the Auth Screen.
But at the same time I want to RESET MainTabNavigator. You can unmount , perform NavigationActions.init() or whatever you can. I prefer NavigationActions.init()
I just want to set MainTabNavigator to its very first time.
Code
if there is no token, I go back to Auth Screen (This is working)
This code if the part of Menuo Screen
componentWillReceiveProps(nextProps) {
if ( nextProps.token == undefined || _.isNil(nextProps.token) ) {
const backAction = NavigationActions.back({
key: null
})
nextProps.navigation.dispatch(backAction);
...
(Question) How can we reset MainTabNavigator including child StackNavigators?
MainTabNavigator.js
export default TabNavigator(
{
Feed: {
screen: FeedStacknavigator,
},
OtherOne: {
screen: OtherStackNavigatorOne,
}
...
}, {
navigationOptions: ({navigation}) => ){
header: null,
tabBarIcon: ({focused}) => ...
...
}
Possible Solution
I can maybe change MainTabNavigator from function to class and deal with resetting TabNavigator there. (I'm not sure).
This time, I need a concrete working example. I've been reading doc and applying to my app but I couldn't solve this.
Please let me know if anything is unclear.
UPDATE
const RootTabNavigator = TabNavigator ({
Auth: {
screen: AuthStackNavigator,
},
Welcome: {
screen: WelcomeScreen,
},
Main: {
screen: MainTabNavigator,
},
}, {
navigationOptions: () => ({
...
}
);
export default class RootNavigator extends React.Component {
componentDidMount() {
this._notificationSubscription = this._registerForPushNotifications();
}