Reset TabNavigator story with navigation response

I have the following structure:

    const routeConfiguration = {
        Login: { screen: Login },
        Home: { screen: TabBar },
    };

    const stackNavigatorConfiguration = {
        headerMode: 'screen',
        navigationOptions: {
            header: { visible: false }
        }
    };

export const RootNav = StackNavigator(routeConfiguration, stackNavigatorConfiguration);

My TabBar, where each tab has its own StackNavigator:

const routeConfiguration = {
    TabOneNavigation: { screen: TabOneNavigation },
    TabTwoNavigation: { screen: TabTwoNavigation },
    TabThreeNavigation: { screen: TabThreeNavigation },
};

const tabBarConfiguration = {
    tabBarOptions: {
        activeTintColor: 'white',
        inactiveTintColor: 'lightgray',
        labelStyle: {
            fontSize: 10,
            fontFamily: Fonts.book
        },
        style: {
            backgroundColor: Colors.greenLightGradient,
            borderTopWidth: 1,
            borderTopColor: Colors.tabGreenLine
        },
    }
};

export const TabBar = TabNavigator(routeConfiguration, tabBarConfiguration);

When the application loads first, it goes to the login screen. After successfully logging in, I use actionTypes.TO_HOME to go to Home. There I have 3 tabs (Feed, Suggestion, Profile). The tab "Internal profile" I have a button "Exit" on which I reset the navigation history, and enter Login again (so far so good). But when I log back in and go to Home, it shows the first tab for a second and takes me to the last (Profile), which looks like the TabNavigator history is not reset. Do I have to do something special so that the TabNavigator history is also reset?

:

export const navReducer = (state = initialState, action = {}) => {
    let nextState;
    switch (action.type) {
        case actionTypes.TO_LOGIN:
            nextState = RootNav.router.getStateForAction(
                NavigationActions.reset({
                    index: 0,
                    actions: [NavigationActions.navigate({ type: NavigationActions.NAVIGATE, routeName: actionTypes.TO_LOGIN })],
                    key: null
                }), state);
            break;

        case actionTypes.TO_HOME:
            nextState = RootNav.router.getStateForAction(
                NavigationActions.reset({
                    index: 0,
                    actions: [NavigationActions.navigate({ type: NavigationActions.NAVIGATE, routeName: actionTypes.TO_HOME })],
                }), state);
            break;

        default:
            nextState = RootNav.router.getStateForAction(action, state);
            break;
    }

    return nextState || state;
};
+4
1

0

0

Source: https://habr.com/ru/post/1676267/


All Articles