Created
February 4, 2019 16:21
-
-
Save Ribeiro-Tiago/682b7056c3ed18733786cceeb7bd0c42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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