From 809a2dc1d65b12e895bd48043de0fa6ba0093838 Mon Sep 17 00:00:00 2001 From: Hedger Wang Date: Wed, 29 Jul 2015 11:29:01 -0700 Subject: [PATCH] [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. --- Libraries/CustomComponents/Navigator/Navigator.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Libraries/CustomComponents/Navigator/Navigator.js b/Libraries/CustomComponents/Navigator/Navigator.js index 6589e7d78..dc9c99ca6 100644 --- a/Libraries/CustomComponents/Navigator/Navigator.js +++ b/Libraries/CustomComponents/Navigator/Navigator.js @@ -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); + } }, /**