diff --git a/index.js b/index.js index 38d1db5..ed21f09 100644 --- a/index.js +++ b/index.js @@ -42,13 +42,13 @@ class GestureRecognizer extends Component { onPanResponderTerminate: responderEnd }); } - + componentDidUpdate(prevProps) { if (this.props.config !== prevProps.config) { this.swipeConfig = Object.assign(swipeConfig, this.props.config); } } - + _handleShouldSetPanResponder(evt, gestureState) { return ( evt.nativeEvent.touches.length === 1 && @@ -97,10 +97,27 @@ class GestureRecognizer extends Component { _getSwipeDirection(gestureState) { const { SWIPE_LEFT, SWIPE_RIGHT, SWIPE_UP, SWIPE_DOWN } = swipeDirections; const { dx, dy } = gestureState; - if (this._isValidHorizontalSwipe(gestureState)) { - return dx > 0 ? SWIPE_RIGHT : SWIPE_LEFT; - } else if (this._isValidVerticalSwipe(gestureState)) { - return dy > 0 ? SWIPE_DOWN : SWIPE_UP; + const absDx = Math.abs(dx); + const absDy = Math.abs(dy); + const validHorizontal = this._isValidHorizontalSwipe(gestureState); + const validVertical = this._isValidVerticalSwipe(gestureState); + const horizontalDirection = dx > 0 ? SWIPE_RIGHT : SWIPE_LEFT; + const verticalDirection = dy > 0 ? SWIPE_DOWN : SWIPE_UP; + //check which delta is larger and choose that order to evaluate + if (absDx > absDy) { + if (validHorizontal) { + return horizontalDirection; + } else if (validVertical) { + return verticalDirection; + } + } + else { + if (validVertical) { + return verticalDirection; + } + else if (validHorizontal) { + return horizontalDirection; + } } return null; }