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

[Android] Fix gestures being able to activate despite their parent already being active #3095

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ class GestureHandlerOrchestrator(
private fun hasOtherHandlerToWaitFor(handler: GestureHandler<*>) =
gestureHandlers.any { !isFinished(it.state) && shouldHandlerWaitForOther(handler, it) }

private fun shouldBeCancelledByFinishedHandler(handler: GestureHandler<*>) = gestureHandlers.any { shouldHandlerWaitForOther(handler, it) && it.state == GestureHandler.STATE_END }
private fun shouldBeCancelledByFinishedHandler(handler: GestureHandler<*>) =
gestureHandlers.any { shouldHandlerWaitForOther(handler, it) && it.state == GestureHandler.STATE_END }

private fun handlersWithinHandlerBounds(handler: GestureHandler<*>) =
Copy link
Contributor

Choose a reason for hiding this comment

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

This name is quite misleading. For me it suggests that we compare positions of native views, while in reality we check for common pointers.

What about handlersWithCommonPointers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this function was removed in 6d11f86

gestureHandlers.filter { handler.hasCommonPointers(it) }

private fun shouldBeCancelledByActiveHandler(handler: GestureHandler<*>) =
handlersWithinHandlerBounds(handler).any { it.state == GestureHandler.STATE_ACTIVE && !canRunSimultaneously(handler, it) }

private fun tryActivate(handler: GestureHandler<*>) {
// If we are waiting for a gesture that has successfully finished, we should cancel handler
if (shouldBeCancelledByFinishedHandler(handler)) {
if (shouldBeCancelledByFinishedHandler(handler) || shouldBeCancelledByActiveHandler(handler)) {
handler.cancel()
return
}
Expand Down Expand Up @@ -702,5 +709,8 @@ class GestureHandlerOrchestrator(
state == GestureHandler.STATE_CANCELLED ||
state == GestureHandler.STATE_FAILED ||
state == GestureHandler.STATE_END

private fun isActive(state: Int) =
state == GestureHandler.STATE_ACTIVE
latekvo marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think it is used anywhere 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed ef986a0

}
}
Loading