From 2a84c92ad16c382038461606e9dab071e7286152 Mon Sep 17 00:00:00 2001 From: Eric Raio Date: Sat, 9 Jan 2016 13:47:44 +0700 Subject: [PATCH 1/3] adding the ability to reset the route stack --- index.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index e4e17fb..d65d3af 100644 --- a/index.js +++ b/index.js @@ -61,6 +61,12 @@ var Router = React.createClass({ navigator.popToTop(); }; + var goToRouteAndReset = function(route) { + var routeState = Object.assign({}, this.state.route, { index: 0 }); + this.setState({ route: routeState }); + navigator.resetTo(route); + }.bind(this); + var didStartDrag = function(evt) { var x = evt.nativeEvent.pageX; if (x < 28) { @@ -89,7 +95,7 @@ var Router = React.createClass({ var updateNavbarProps = function(props) { route.updateNavbarProps && route.updateNavbarProps(props); route.updateStaticNavbarProps && route.updateStaticNavbarProps(props); - } + }; var Content = route.component; return ( @@ -104,6 +110,7 @@ var Router = React.createClass({ push:goForward, pop:goBackwards, popToTop:goToFirstRoute, + replace:goToRouteAndReset, }} updateBarBackgroundStyle={ (style)=>{ @@ -156,4 +163,4 @@ var styles = StyleSheet.create({ }); -module.exports = Router; \ No newline at end of file +module.exports = Router; From 934e15329a8f185a32bd45f38d178bb8ef4bba54 Mon Sep 17 00:00:00 2001 From: Eric Raio Date: Sat, 9 Jan 2016 13:49:54 +0700 Subject: [PATCH 2/3] fixing method name --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index d65d3af..771d9eb 100644 --- a/index.js +++ b/index.js @@ -110,7 +110,7 @@ var Router = React.createClass({ push:goForward, pop:goBackwards, popToTop:goToFirstRoute, - replace:goToRouteAndReset, + reset:goToRouteAndReset, }} updateBarBackgroundStyle={ (style)=>{ From e62d4421ceef2c60dc2346a6b85ee8f02b6783f9 Mon Sep 17 00:00:00 2001 From: Eric Raio Date: Sun, 10 Jan 2016 11:50:20 +0700 Subject: [PATCH 3/3] erasing the previous nav title on reset --- components/NavBarContainer.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/NavBarContainer.js b/components/NavBarContainer.js index 1bb32ba..a26f6e7 100644 --- a/components/NavBarContainer.js +++ b/components/NavBarContainer.js @@ -18,6 +18,8 @@ var NavBarContainer = React.createClass({ }, componentWillReceiveProps: function(newProps) { + let previousRoute; + if (!this.props.currentRoute || (this.props.currentRoute.index === null)) { newProps.currentRoute.index = 0; } @@ -26,8 +28,12 @@ var NavBarContainer = React.createClass({ return; } + if (!this.props.currentRoute || newProps.currentRoute.index !== this.props.currentRoute.index) { + previousRoute = this.props.currentRoute; + } + this.setState({ - previousRoute: this.props.currentRoute, + previousRoute: previousRoute, currentRoute: newProps.currentRoute }); },