From e0d53e1c48d34419ea9a0622bd9b360c51ec3b78 Mon Sep 17 00:00:00 2001 From: Hedger Wang Date: Mon, 23 Nov 2015 09:17:32 -0800 Subject: [PATCH] Fix move gesture handling. Summary: public The gesture that moves scene around should only be attached when the move starts at the moment that the first move is granted. No move would ever be granted if the move event is prevented by the decendent children (e.g. a slider component). For now, the move gesture is attached at `onPanResponderGrant` instead of `onPanResponderMove` thus we'd create "ghost-move-gesture" when no actual moves is received my the navigator. Reviewed By: fkgozali Differential Revision: D2683802 fb-gh-sync-id: 50ae877787167511df48378304bd2ad665c73300 --- .../CustomComponents/Navigator/Navigator.js | 26 +++++++++---------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/Libraries/CustomComponents/Navigator/Navigator.js b/Libraries/CustomComponents/Navigator/Navigator.js index 8bfd55457a3d31..ff7ff2c632f772 100644 --- a/Libraries/CustomComponents/Navigator/Navigator.js +++ b/Libraries/CustomComponents/Navigator/Navigator.js @@ -329,7 +329,6 @@ var Navigator = React.createClass({ }); this.panGesture = PanResponder.create({ onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder, - onPanResponderGrant: this._handlePanResponderGrant, onPanResponderRelease: this._handlePanResponderRelease, onPanResponderMove: this._handlePanResponderMove, onPanResponderTerminate: this._handlePanResponderTerminate, @@ -609,7 +608,8 @@ var Navigator = React.createClass({ if (!sceneConfig) { return false; } - this._expectingGestureGrant = this._matchGestureAction(this._eligibleGestures, sceneConfig.gestures, gestureState); + this._expectingGestureGrant = + this._matchGestureAction(this._eligibleGestures, sceneConfig.gestures, gestureState); return !!this._expectingGestureGrant; }, @@ -621,16 +621,6 @@ var Navigator = React.createClass({ return wouldOverswipeForward || wouldOverswipeBack; }, - _handlePanResponderGrant: function(e, gestureState) { - invariant( - this._expectingGestureGrant, - 'Responder granted unexpectedly.' - ); - this._attachGesture(this._expectingGestureGrant); - this._onAnimationStart(); - this._expectingGestureGrant = null; - }, - _deltaForGestureAction: function(gestureAction) { switch (gestureAction) { case 'pop': @@ -735,6 +725,16 @@ var Navigator = React.createClass({ }, _handlePanResponderMove: function(e, gestureState) { + if (this._isMoveGestureAttached !== undefined) { + invariant( + this._expectingGestureGrant, + 'Responder granted unexpectedly.' + ); + this._attachGesture(this._expectingGestureGrant); + this._onAnimationStart(); + this._expectingGestureGrant = undefined; + } + var sceneConfig = this.state.sceneConfigStack[this.state.presentedIndex]; if (this.state.activeGesture) { var gesture = sceneConfig.gestures[this.state.activeGesture]; @@ -825,7 +825,7 @@ var Navigator = React.createClass({ this._eligibleGestures = this._eligibleGestures.slice().splice(gestureIndex, 1); } }); - return matchedGesture; + return matchedGesture || null; }, _transitionSceneStyle: function(fromIndex, toIndex, progress, index) {