Skip to content

Commit

Permalink
Fix of rotation and pinch gesture on android (#2983)
Browse files Browse the repository at this point in the history
## Description

Fixing rotation and pinch gesture to continue to work after releasing
one of a key pointers.

## Test plan

I've checked if each example on the test app still works.

---------

Co-authored-by: Dawid Małecki <[email protected]>
Co-authored-by: Michał Bert <[email protected]>
Co-authored-by: Jakub Piasecki <[email protected]>
  • Loading branch information
4 people authored Jul 9, 2024
1 parent 1256081 commit afa05ac
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,13 @@ class PinchGestureHandler : GestureHandler<PinchGestureHandler>() {
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()
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit afa05ac

Please sign in to comment.