Skip to content
Merged
Show file tree
Hide file tree
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 @@ -609,10 +609,14 @@ open class GestureHandler {
}

// if there are tracked pointers and the gesture is about to end, send event cancelling all pointers
if (trackedPointersCount > 0 &&
(newState == STATE_END || newState == STATE_CANCELLED || newState == STATE_FAILED)
) {
if (trackedPointersCount > 0 && isFinished(newState)) {
cancelPointers()

// `cancelPointers` dispatches the event synchronously and its callback may change the state
// (e.g. via `GestureStateManager.fail`), in which case the transition is already complete.
if (isFinished(state)) {
return
}
}

val oldState = state
Expand Down Expand Up @@ -998,6 +1002,8 @@ open class GestureHandler {
}

companion object {
fun isFinished(state: Int) = state == STATE_CANCELLED || state == STATE_FAILED || state == STATE_END
Comment thread
j-piasecki marked this conversation as resolved.
Resolved

private const val DEFAULT_NEEDS_POINTER_DATA = false
private const val DEFAULT_MANUAL_ACTIVATION = false
private const val DEFAULT_SHOULD_CANCEL_WHEN_OUTSIDE = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ class GestureHandlerOrchestrator(

private fun cleanupFinishedHandlers() {
for (handler in gestureHandlers.asReversed()) {
if (isFinished(handler.state) && !handler.isAwaiting) {
if (GestureHandler.isFinished(handler.state) && !handler.isAwaiting) {
handler.reset()
handler.apply {
isActive = false
Expand All @@ -111,13 +111,13 @@ class GestureHandlerOrchestrator(
}
}

gestureHandlers.removeAll { isFinished(it.state) && !it.isAwaiting }
gestureHandlers.removeAll { GestureHandler.isFinished(it.state) && !it.isAwaiting }

finishedHandlersCleanupScheduled = false
}

private fun hasOtherHandlerToWaitFor(handler: GestureHandler) =
gestureHandlers.any { !isFinished(it.state) && shouldHandlerWaitForOther(handler, it) }
gestureHandlers.any { !GestureHandler.isFinished(it.state) && shouldHandlerWaitForOther(handler, it) }

private fun shouldBeCancelledByFinishedHandler(handler: GestureHandler) =
gestureHandlers.any { shouldHandlerWaitForOther(handler, it) && it.state == GestureHandler.STATE_END }
Expand Down Expand Up @@ -167,7 +167,7 @@ class GestureHandlerOrchestrator(
handler.isAwaiting = false
}

if (isFinished(newState)) {
if (GestureHandler.isFinished(newState)) {
// We have to loop through copy in order to avoid modifying collection
// while iterating over its elements
val currentlyAwaitingHandlers = awaitingHandlers.toList()
Expand Down Expand Up @@ -1027,9 +1027,5 @@ class GestureHandlerOrchestrator(
true
}
}

private fun isFinished(state: Int) = state == GestureHandler.STATE_CANCELLED ||
state == GestureHandler.STATE_FAILED ||
state == GestureHandler.STATE_END
}
}
Loading