diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt index 547e18c2d6..a9082c2f49 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandler.kt @@ -684,6 +684,22 @@ open class GestureHandler): Boolean { + var view = this.view?.parent as? View + while (view != null) { + if (view == of.view) { + return true + } + + view = view.parent as? View + } + return false + } + // responsible for resetting the state of handler upon activation (may be called more than once // if the handler is waiting for failure of other one) open fun resetProgress() {} diff --git a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt index 3c5e5ea29a..4d76e8ff2e 100644 --- a/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt +++ b/android/src/main/java/com/swmansion/gesturehandler/core/GestureHandlerOrchestrator.kt @@ -85,11 +85,15 @@ 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 shouldBeCancelledByActiveHandler(handler: GestureHandler<*>) = + gestureHandlers.any { handler.hasCommonPointers(it) && it.state == GestureHandler.STATE_ACTIVE && !canRunSimultaneously(handler, it) && handler.isDescendantOf(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 }