File tree Expand file tree Collapse file tree 2 files changed +22
-2
lines changed
android/src/main/java/com/swmansion/gesturehandler/core Expand file tree Collapse file tree 2 files changed +22
-2
lines changed Original file line number Diff line number Diff line change @@ -684,6 +684,22 @@ open class GestureHandler<ConcreteGestureHandlerT : GestureHandler<ConcreteGestu
684684 }
685685 }
686686
687+ /*
688+ * Returns true if the view this handler is attached to is a descendant of the view the other handler
689+ * is attached to and false otherwise.
690+ */
691+ fun isDescendantOf (of : GestureHandler <* >): Boolean {
692+ var view = this .view?.parent as ? View
693+ while (view != null ) {
694+ if (view == of.view) {
695+ return true
696+ }
697+
698+ view = view.parent as ? View
699+ }
700+ return false
701+ }
702+
687703 // responsible for resetting the state of handler upon activation (may be called more than once
688704 // if the handler is waiting for failure of other one)
689705 open fun resetProgress () {}
Original file line number Diff line number Diff line change @@ -85,11 +85,15 @@ class GestureHandlerOrchestrator(
8585 private fun hasOtherHandlerToWaitFor (handler : GestureHandler <* >) =
8686 gestureHandlers.any { ! isFinished(it.state) && shouldHandlerWaitForOther(handler, it) }
8787
88- private fun shouldBeCancelledByFinishedHandler (handler : GestureHandler <* >) = gestureHandlers.any { shouldHandlerWaitForOther(handler, it) && it.state == GestureHandler .STATE_END }
88+ private fun shouldBeCancelledByFinishedHandler (handler : GestureHandler <* >) =
89+ gestureHandlers.any { shouldHandlerWaitForOther(handler, it) && it.state == GestureHandler .STATE_END }
90+
91+ private fun shouldBeCancelledByActiveHandler (handler : GestureHandler <* >) =
92+ gestureHandlers.any { handler.hasCommonPointers(it) && it.state == GestureHandler .STATE_ACTIVE && ! canRunSimultaneously(handler, it) && handler.isDescendantOf(it) }
8993
9094 private fun tryActivate (handler : GestureHandler <* >) {
9195 // If we are waiting for a gesture that has successfully finished, we should cancel handler
92- if (shouldBeCancelledByFinishedHandler(handler)) {
96+ if (shouldBeCancelledByFinishedHandler(handler) || shouldBeCancelledByActiveHandler(handler) ) {
9397 handler.cancel()
9498 return
9599 }
You can’t perform that action at this time.
0 commit comments