diff --git a/src/Navigator.js b/src/Navigator.js index b714e99..28449ed 100644 --- a/src/Navigator.js +++ b/src/Navigator.js @@ -1186,6 +1186,33 @@ var Navigator = React.createClass({ cb && cb(); }); }, + + /** + * Replace the previous scene with transition Animations. + * @param {object} route Route that replaces the previous scene. + */ + replaceWithAnimation: function (route) { + const currentLength = this.state.presentedIndex + 1; + const currentRouteStack = this.state.routeStack.slice(0, currentLength); + const animationConfigFromSceneConfigStack = this.state.sceneConfigStack.slice(0, currentLength); + const nextStack = currentRouteStack.concat([route]); + const destIndex = nextStack.length - 1; + const nextSceneConfig = this.props.configureScene(route, nextStack); + const nextAnimationConfigStack = animationConfigFromSceneConfigStack.concat([nextSceneConfig]); + + const newStack = currentRouteStack.slice(0, currentLength - 1).concat([route]); + this._emitWillFocus(nextStack[destIndex]); + this.setState({ + routeStack: nextStack, + sceneConfigStack: nextAnimationConfigStack, + },() => { + this._enableScene(destIndex); + this._transitionTo(destIndex, nextSceneConfig.defaultTransitionVelocity, null, () => { + // Immediately reset the route stack after the transition is completed + this.immediatelyResetRouteStack(newStack); + }); + }); + }, /** * Replace the current scene with a new route.