diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt b/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt index 28e8589382..55bd282eda 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/PinchGestureHandler.kt @@ -70,14 +70,13 @@ class PinchGestureHandler : GestureHandler() { this.focalPointX = point.x this.focalPointY = point.y } - var activePointers = sourceEvent.pointerCount - if (sourceEvent.actionMasked == MotionEvent.ACTION_POINTER_UP) { - activePointers -= 1 - } - if (state == STATE_ACTIVE && activePointers < 2) { - end() - } else if (sourceEvent.actionMasked == MotionEvent.ACTION_UP) { - fail() + + if (sourceEvent.actionMasked == MotionEvent.ACTION_UP) { + if (state == STATE_ACTIVE) { + end() + } else { + fail() + } } } diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/RotationGestureDetector.kt b/android/src/main/java/com/swmansion/gesturehandler/core/RotationGestureDetector.kt index 48cdccd60e..553d24168e 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/RotationGestureDetector.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/RotationGestureDetector.kt @@ -111,11 +111,21 @@ class RotationGestureDetector(private val gestureListener: OnRotationGestureList updateCurrent(event) gestureListener?.onRotation(this) } - MotionEvent.ACTION_POINTER_UP -> if (isInProgress) { + MotionEvent.ACTION_POINTER_UP -> { val pointerId = event.getPointerId(event.actionIndex) - if (pointerId == pointerIds[0] || pointerId == pointerIds[1]) { - // One of the key pointer has been lifted up, we have to end the gesture - finish() + + // All key pointers are up + if (!isInProgress && pointerId == pointerIds[0]) { + gestureListener?.onRotationEnd(this) + } + + // One of the key pointers is up + if (isInProgress && pointerIds.contains(pointerId)) { + if (pointerId == pointerIds[0]) { + pointerIds[0] = pointerIds[1] + } + pointerIds[1] = MotionEvent.INVALID_POINTER_ID + isInProgress = false } } MotionEvent.ACTION_UP -> finish()