From bb163118e1e423e86a15aead27930eb3344e7db6 Mon Sep 17 00:00:00 2001 From: Nishan Date: Sun, 2 Jan 2022 13:34:14 +0530 Subject: [PATCH 1/5] fix: android single finger behaviour in pinch --- .../swmansion/gesturehandler/PinchGestureHandler.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt index 965c8fa941..6805ba27de 100644 --- a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +++ b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt @@ -57,14 +57,13 @@ class PinchGestureHandler : GestureHandler() { scaleGestureDetector = ScaleGestureDetector(context, gestureListener) val configuration = ViewConfiguration.get(context) spanSlop = configuration.scaledTouchSlop.toFloat() - begin() } - scaleGestureDetector?.onTouchEvent(event) - var activePointers = event.pointerCount - if (event.actionMasked == MotionEvent.ACTION_POINTER_UP) { - activePointers -= 1 + + if(event.actionMasked != MotionEvent.ACTION_POINTER_UP){ + scaleGestureDetector?.onTouchEvent(event) } - if (state == STATE_ACTIVE && activePointers < 2) { + + if (state == STATE_ACTIVE && event.actionMasked == MotionEvent.ACTION_UP) { end() } else if (event.actionMasked == MotionEvent.ACTION_UP) { fail() From aad9c874f793165629268d57f9111b9ff6793eb8 Mon Sep 17 00:00:00 2001 From: Nishan Date: Sun, 2 Jan 2022 13:51:27 +0530 Subject: [PATCH 2/5] fix: android single finger behaviour in pinch --- .../java/com/swmansion/gesturehandler/PinchGestureHandler.kt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt index 6805ba27de..f805bed5b8 100644 --- a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +++ b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt @@ -57,9 +57,10 @@ class PinchGestureHandler : GestureHandler() { scaleGestureDetector = ScaleGestureDetector(context, gestureListener) val configuration = ViewConfiguration.get(context) spanSlop = configuration.scaledTouchSlop.toFloat() + begin() } - - if(event.actionMasked != MotionEvent.ACTION_POINTER_UP){ + + if(event.actionMasked != MotionEvent.ACTION_POINTER_UP){ scaleGestureDetector?.onTouchEvent(event) } From dc6d6e72b0fd310149d6b215735e3c8f637f5f0e Mon Sep 17 00:00:00 2001 From: Nishan Date: Mon, 3 Jan 2022 09:55:20 +0530 Subject: [PATCH 3/5] fix: android single finger pinch --- .../swmansion/gesturehandler/PinchGestureHandler.kt | 12 +++++++++--- .../gesturehandler/react/RNGestureHandlerModule.kt | 1 + 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt index f805bed5b8..1132b52211 100644 --- a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +++ b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt @@ -13,6 +13,8 @@ class PinchGestureHandler : GestureHandler() { private set val focalPointX: Float get() = scaleGestureDetector?.focusX ?: Float.NaN + var activePointers = 0 + private set val focalPointY: Float get() = scaleGestureDetector?.focusY ?: Float.NaN @@ -59,9 +61,13 @@ class PinchGestureHandler : GestureHandler() { spanSlop = configuration.scaledTouchSlop.toFloat() begin() } - - if(event.actionMasked != MotionEvent.ACTION_POINTER_UP){ - scaleGestureDetector?.onTouchEvent(event) + + activePointers = event.pointerCount; + + scaleGestureDetector?.onTouchEvent(event) + + if (event.actionMasked == MotionEvent.ACTION_POINTER_UP) { + activePointers -= 1 } if (state == STATE_ACTIVE && event.actionMasked == MotionEvent.ACTION_UP) { diff --git a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt index 0f15e35be6..a7700e257f 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/react/RNGestureHandlerModule.kt @@ -248,6 +248,7 @@ class RNGestureHandlerModule(reactContext: ReactApplicationContext?) putDouble("focalX", PixelUtil.toDIPFromPixel(handler.focalPointX).toDouble()) putDouble("focalY", PixelUtil.toDIPFromPixel(handler.focalPointY).toDouble()) putDouble("velocity", handler.velocity) + putDouble("numberOfPointers", handler.activePointers.toDouble()) } } } From 14b17da41d061f0e3331af6549899e7817144760 Mon Sep 17 00:00:00 2001 From: Nishan Date: Mon, 3 Jan 2022 10:00:58 +0530 Subject: [PATCH 4/5] fix: android single finger pinch --- .../com/swmansion/gesturehandler/PinchGestureHandler.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt index 1132b52211..02df251fa5 100644 --- a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +++ b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt @@ -61,15 +61,11 @@ class PinchGestureHandler : GestureHandler() { spanSlop = configuration.scaledTouchSlop.toFloat() begin() } - - activePointers = event.pointerCount; - scaleGestureDetector?.onTouchEvent(event) - + activePointers = event.pointerCount; if (event.actionMasked == MotionEvent.ACTION_POINTER_UP) { activePointers -= 1 } - if (state == STATE_ACTIVE && event.actionMasked == MotionEvent.ACTION_UP) { end() } else if (event.actionMasked == MotionEvent.ACTION_UP) { From 9fecfbb54eed8093c3ab11d724c4f6304783a75b Mon Sep 17 00:00:00 2001 From: Nishan Date: Mon, 3 Jan 2022 10:04:13 +0530 Subject: [PATCH 5/5] chore: remove semicolon --- .../java/com/swmansion/gesturehandler/PinchGestureHandler.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt index 02df251fa5..7d7f5456b6 100644 --- a/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt +++ b/android/lib/src/main/java/com/swmansion/gesturehandler/PinchGestureHandler.kt @@ -62,7 +62,7 @@ class PinchGestureHandler : GestureHandler() { begin() } scaleGestureDetector?.onTouchEvent(event) - activePointers = event.pointerCount; + activePointers = event.pointerCount if (event.actionMasked == MotionEvent.ACTION_POINTER_UP) { activePointers -= 1 }