[Navigator: Prevent user from over-popping the routes.

Summary:
If user taps the back button quickly, the app crashes becuase "pop"
internally only checks `this.state.presentedIndex` which does not
always update when transtion happens.

This diff addresses this issue.
This commit is contained in:
Hedger Wang 2015-07-29 11:29:01 -07:00
parent 8416691719
commit 809a2dc1d6
1 changed files with 13 additions and 1 deletions

View File

@ -922,7 +922,19 @@ var Navigator = React.createClass({
},
pop: function() {
this._popN(1);
if (this.state.transitionQueue.length) {
// This is the workaround to prevent user from firing multiple `pop()`
// calls that may pop the routes beyond the limit.
// Because `this.state.presentedIndex` does not update until the
// transition starts, we can't reliably use `this.state.presentedIndex`
// to know whether we can safely keep popping the routes or not at this
// moment.
return;
}
if (this.state.presentedIndex > 0) {
this._popN(1);
}
},
/**