Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removing multiple screens from stack #2992

Closed
ghost opened this issue Apr 12, 2018 · 2 comments
Closed

Removing multiple screens from stack #2992

ghost opened this issue Apr 12, 2018 · 2 comments

Comments

@ghost
Copy link

ghost commented Apr 12, 2018

Version

  • react-native-router-flux 4.0.0-beta.14
  • react-native v0.46.4

Expected behaviour

Is it possible remove from stack some screens with the same name?
For example, my screens:
ScreenA -> ScreenB -> ScreenC -> ScreenA -> ScreenD
and i would like to receive the next stack without ScreenA:
ScreenB -> ScreenC -> ScreenD

@AlexDM0
Copy link

AlexDM0 commented May 30, 2018

I have a similar issue.

ScreenA -> ScreenB -> ScreenC -> ScreenD

I'd like a normal transition between ScreenC and ScreenD, then back from ScreenD should be ScreenA.

What is the best way to do this? I'd need to pop ScreenB and ScreenC when the transition to D is completed?

@AlexDM0
Copy link

AlexDM0 commented May 30, 2018

I solved this by changing the reducer you pass to Router.createReducer

export const reducerCreate = (params) => {
  const defaultReducer = Reducer(params, {});
  return (state, action)=>{
    if (action && action.type == "REACT_NATIVE_ROUTER_FLUX_PUSH") {
      if (action.params && action.params.__popBeforeAddCount) {
        let newState = {...state};
        for (let i = 0; i < action.params.__popBeforeAddCount; i++) {
          newState.routes.pop();
          newState.index -= 1;
        }
        return defaultReducer(newState, action);
      }
    }
    return defaultReducer(state, action);
  }
};

I added a custom field to the action params __popBeforeAddCount which I filter for in the reducer (yes, that IS a little ugly ;)). If this is the case I pop a few items off the routing stack before continuing. Similarly, when you'd want to remove screenA from the stack, you can change the stack in the reducer you provide.

Hope it helps!

edit:
usage:

<Router createReducer={reducerCreate} ... >

@aksonov aksonov closed this as completed Aug 8, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants