Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix of rotation and pinch gesture on android #2983

Merged
merged 7 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class PinchGestureHandler : GestureHandler<PinchGestureHandler>() {
if (sourceEvent.actionMasked == MotionEvent.ACTION_POINTER_UP) {
activePointers -= 1
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think activePointers is being used anymore, can you remove it?

}
if (state == STATE_ACTIVE && activePointers < 2) {
if (state == STATE_ACTIVE && activePointers == 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you check which state the gesture goes to after lifting all the fingers? I'm not sure whether this branch will get evaluated in this form (activePointers may never equal 0, I think on ACTION_UP the pointer being lifted is still counted in the event)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct, this if statement is useless at this point.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can be simply changed to something like this:

if action is ACTION_UP:
  if (state == ACTIVE):
    end()
  else
    fail()

end()
} else if (sourceEvent.actionMasked == MotionEvent.ACTION_UP) {
fail()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,22 @@ 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()

if (isInProgress) {
if (pointerId == pointerIds[0] || pointerId == pointerIds[1]) {
if (pointerId == pointerIds[0]) {
pointerIds[0] = pointerIds[1]
}
pointerIds[1] = MotionEvent.INVALID_POINTER_ID
isInProgress = false
}
} else {
// all key pointers are up
if (pointerId == pointerIds[0]) {
gestureListener?.onRotationEnd(this)
}
coado marked this conversation as resolved.
Show resolved Hide resolved
}
}
MotionEvent.ACTION_UP -> finish()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ class RotationGestureHandler : GestureHandler<RotationGestureHandler>() {
anchorY = point.y
}
if (sourceEvent.actionMasked == MotionEvent.ACTION_UP) {
if (state == STATE_ACTIVE) {
var activePointers = sourceEvent.pointerCount
if (state == STATE_ACTIVE && activePointers == 0) {
coado marked this conversation as resolved.
Show resolved Hide resolved
end()
} else {
fail()
Expand Down
Loading