From 94efb466b01a62c61c960a04e37c0d240987f2d3 Mon Sep 17 00:00:00 2001 From: cdbridger Date: Wed, 4 Mar 2020 12:35:38 +1300 Subject: [PATCH 1/4] check which delta is larger and evaluate in that order for swipe direction --- index.js | 35 +++++++++++++++++++++++++++++------ 1 file changed, 29 insertions(+), 6 deletions(-) diff --git a/index.js b/index.js index 38d1db5..aaf1060 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,33 @@ 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._isValidHorizontalSwipe(gestureState); + //check which delta is larger and choose that order to evaluate + if (absDx > absDy) { + if (validHorizontal) { + return (dx > 0) + ? SWIPE_RIGHT + : SWIPE_LEFT; + } else if (validVertical) { + return (dy > 0) + ? SWIPE_DOWN + : SWIPE_UP; + } + } + else { + if (validHorizontal) { + return (dy > 0) + ? SWIPE_DOWN + : SWIPE_UP; + } + else if (validVertical) { + return (dx > 0) + ? SWIPE_RIGHT + : SWIPE_LEFT; + } } return null; } From 2ae2275fdaed51d8d648756e4198191c5ad1cfe6 Mon Sep 17 00:00:00 2001 From: cdbridger Date: Wed, 4 Mar 2020 12:41:34 +1300 Subject: [PATCH 2/4] tidy up previous commit --- index.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/index.js b/index.js index aaf1060..7ec450e 100644 --- a/index.js +++ b/index.js @@ -101,28 +101,22 @@ class GestureRecognizer extends Component { const absDy = Math.abs(dy); const validHorizontal = this._isValidHorizontalSwipe(gestureState); const validVertical = this._isValidHorizontalSwipe(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 (dx > 0) - ? SWIPE_RIGHT - : SWIPE_LEFT; + return horizontalDirection; } else if (validVertical) { - return (dy > 0) - ? SWIPE_DOWN - : SWIPE_UP; + return verticalDirection; } } else { if (validHorizontal) { - return (dy > 0) - ? SWIPE_DOWN - : SWIPE_UP; + return horizontalDirection; } else if (validVertical) { - return (dx > 0) - ? SWIPE_RIGHT - : SWIPE_LEFT; + return verticalDirection; } } return null; From 7026fc77471ebcf17074839ae1ea763a9efab473 Mon Sep 17 00:00:00 2001 From: cdbridger Date: Wed, 4 Mar 2020 12:43:34 +1300 Subject: [PATCH 3/4] fix incorrect logic --- index.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index 7ec450e..e66ca28 100644 --- a/index.js +++ b/index.js @@ -112,12 +112,12 @@ class GestureRecognizer extends Component { } } else { - if (validHorizontal) { - return horizontalDirection; - } - else if (validVertical) { + if (validVertical) { return verticalDirection; } + else if (validHorizontal) { + return horizontalDirection; + } } return null; } From 50fff2fcba6d5c0cbca24407f7fb703ce48d177c Mon Sep 17 00:00:00 2001 From: cdbridger Date: Wed, 4 Mar 2020 12:57:37 +1300 Subject: [PATCH 4/4] oops --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index e66ca28..ed21f09 100644 --- a/index.js +++ b/index.js @@ -100,7 +100,7 @@ class GestureRecognizer extends Component { const absDx = Math.abs(dx); const absDy = Math.abs(dy); const validHorizontal = this._isValidHorizontalSwipe(gestureState); - const validVertical = 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