Skip to content

fix: android - Pinch gesture handler when one finger is lifted #1799

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

Closed
Changes from all 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 @@ -59,12 +59,12 @@ class PinchGestureHandler : GestureHandler<PinchGestureHandler>() {
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){
Copy link
Author

@intergalacticspacehighway intergalacticspacehighway Jan 2, 2022

Choose a reason for hiding this comment

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

This surely appears weird, but I am not sure If there's a better way to achieve this. This is done due to the below scenario.

User has 2 fingers and performing pinch -> One finger is lifted -> ACTION_POINTER_UP is fired -> event.pointerCount is still 2 -> scale detector sets the focal values to single finger -> the event received has new focus but the pointer count is still 2.

However, this again makes it consistent with iOS. iOS Pinch handler doesn't send events in case of a finger is lifted. Only when a single pointer is moved, it starts sending the event. (practically tested, it would be great if someone can find it documented somewhere)

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()
Expand Down