From 5162eb32546b42a017adac1e1bf9b4196affc7c5 Mon Sep 17 00:00:00 2001 From: Eric Vicenti Date: Wed, 6 Apr 2016 02:51:27 -0700 Subject: [PATCH] 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 --- .../NavigationCardStackPanResponder.js | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStackPanResponder.js b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStackPanResponder.js index edf1ec02e3e..4776ac5c451 100644 --- a/Libraries/CustomComponents/NavigationExperimental/NavigationCardStackPanResponder.js +++ b/Libraries/CustomComponents/NavigationExperimental/NavigationCardStackPanResponder.js @@ -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 ); }