Skip to content

Commit

Permalink
Fix move gesture handling.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Hedger Wang authored and facebook-github-bot-4 committed Nov 23, 2015
1 parent e4dca7a commit e0d53e1
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions Libraries/CustomComponents/Navigator/Navigator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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;
},

Expand All @@ -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':
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit e0d53e1

Please sign in to comment.