Remove screen from stack navigator

后端 未结 2 694
野性不改
野性不改 2021-01-02 07:56

I’ve observed Back button logic works seeing the sequence of screens in the stack. I’ve a Drawer navigator placed inside stack navigator.

On top of the stack I’ve S

2条回答
  •  生来不讨喜
    2021-01-02 08:05

    I solved it using this

    code:

    const prevGetStateForActionHomeStack = HomeStack.router.getStateForAction;
    HomeStack.router = {
      ...HomeStack.router,
      getStateForAction(action, state) {
        if (state && action.type === 'ReplaceCurrentScreen') {
          const routes = state.routes.slice(0, state.routes.length - 1);
          routes.push(action);
          return {
            ...state,
            routes,
            index: routes.length - 1,
          };
        }
        return prevGetStateForActionHomeStack(action, state);
      },
    };
    replaceScreen = () => {
      const { locations, position } = this.props.navigation.state.params;
      this.props.navigation.dispatch({
        key: 'NearMeMap',
        type: 'ReplaceCurrentScreen',
        routeName: 'NearMeMap',
        params: { locations, position },
      });
    };
    

    Also if you need in-depth explanation of the code, watch this short video here

提交回复
热议问题