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
This commit is contained in:
Hedger Wang 2015-11-23 09:17:32 -08:00 committed by facebook-github-bot-4
parent e4dca7a1fa
commit e0d53e1c48
1 changed files with 13 additions and 13 deletions

View File

@ -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) {