Only accept card gestures within a certain range, 30px

Summary: The iOS native card stack only responds if the gesture starts on the left 30 px on the screen.

Reviewed By: hedgerwang

Differential Revision: D3137201

fb-gh-sync-id: 40e28d5696870b98731e92d6e42d00638b9bb15f
fbshipit-source-id: 40e28d5696870b98731e92d6e42d00638b9bb15f
This commit is contained in:
Eric Vicenti 2016-04-06 02:51:27 -07:00 committed by Facebook Github Bot 3
parent 804791e086
commit 5162eb3254
1 changed files with 21 additions and 4 deletions

View File

@ -39,6 +39,14 @@ const POSITION_THRESHOLD = 1 / 3;
*/
const RESPOND_THRESHOLD = 15;
/**
* The distance from the edge of the navigator which gesture response can start for.
* For horizontal scroll views, a distance of 30 from the left of the screen is the
* standard maximum position to start touch responsiveness.
*/
const RESPOND_POSITION_MAX_HORIZONTAL = 30;
const RESPOND_POSITION_MAX_VERTICAL = null;
/**
* The threshold (in pixels) to finish the gesture action.
*/
@ -105,15 +113,24 @@ class NavigationCardStackPanResponder extends NavigationAbstractPanResponder {
const layout = props.layout;
const isVertical = this._isVertical;
const axis = isVertical ? 'dy' : 'dx';
const index = props.navigationState.index;
const distance = isVertical ?
const currentDragDistance = gesture[isVertical ? 'dy' : 'dx'];
const currentDragPosition = gesture[isVertical ? 'moveY' : 'moveX'];
const maxDragDistance = isVertical ?
layout.height.__getValue() :
layout.width.__getValue();
const positionMax = isVertical ?
RESPOND_POSITION_MAX_VERTICAL :
RESPOND_POSITION_MAX_HORIZONTAL;
if (positionMax != null && currentDragPosition > positionMax) {
return false;
}
return (
Math.abs(gesture[axis]) > RESPOND_THRESHOLD &&
distance > 0 &&
Math.abs(currentDragDistance) > RESPOND_THRESHOLD &&
maxDragDistance > 0 &&
index > 0
);
}