Skip to content

Instantly share code, notes, and snippets.

@Ribeiro-Tiago
Created February 4, 2019 16:21
Show Gist options
  • Save Ribeiro-Tiago/682b7056c3ed18733786cceeb7bd0c42 to your computer and use it in GitHub Desktop.
Save Ribeiro-Tiago/682b7056c3ed18733786cceeb7bd0c42 to your computer and use it in GitHub Desktop.
const prevGetStateForAction = myStack.router.getStateForAction;
myStack.router.getStateForAction = (action, state) => {
if (state && action.type === "Navigation/COMPLETE_TRANSITION") {
let routes = state.routes;
if (routes.length === 1) {
return {
...state,
index: 0,
};
}
const lastScene: NavigationRoute = routes.slice(-1)[0];
const lastSceneName = lastScene.routeName;
routes = routes.filter((item: NavigationRoute, index: number) => {
if (index === 0) {
return true;
}
return (item.routeName !== lastSceneName)
});
routes.push(lastScene);
return {
...state,
index: routes.length - 1,
routes
};
}
return prevGetStateForAction(action, state);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment