Skip to content
Open
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 @@ -258,7 +258,7 @@ open class GestureHandler {
trackedPointersIDsCount--
}

private fun isTrackingPointer(pointerId: Int) = trackedPointerIDs[pointerId] != -1
fun isTrackingPointer(pointerId: Int) = trackedPointerIDs[pointerId] != -1

private fun needAdapt(event: MotionEvent): Boolean {
if (event.pointerCount != trackedPointersIDsCount) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ class GestureHandlerOrchestrator(
}
}

fun recordHandlerIfNotPresent(handler: GestureHandler, view: View?) {
fun recordHandlerIfNotPresent(handler: GestureHandler, view: View?, pointerId: Int = -1) {
if (gestureHandlers.contains(handler)) {
return
}
Expand All @@ -543,7 +543,9 @@ class GestureHandlerOrchestrator(
handler.activationIndex = Int.MAX_VALUE
handler.prepare(view, this)

if (!handler.shouldBeginWithRecordedHandlers(gestureHandlers)) {
// Only handlers extracted for the same pointer (they already track it) may block this one
val recorded = if (pointerId >= 0) gestureHandlers.filter { it.isTrackingPointer(pointerId) } else emptyList()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It may make sense to move this check into shouldBeginWithRecordedHandlers so each handler can decide on its own whether to filter or not - buttons may want to do it differently depending on exclusive, but I didn't think that much about it, so it may be a bad idea. WDYT?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

To be honest I don't have a strong opinion.

I have a feeling that orchestrator is a better place for deciding which handlers should be checked by given handler, also recorded was documented as "handlers already recorded for the current touch". Moving it to shouldBeginWithRecordedHandlers might give more flexibility, but I'm not sure we need that.

if (!handler.shouldBeginWithRecordedHandlers(recorded)) {
handler.cancel()
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

Expand Down Expand Up @@ -589,7 +591,7 @@ class GestureHandlerOrchestrator(

if (handler.isEnabled && handler.isWithinBounds(view, coords[0], coords[1])) {
found = true
recordHandlerIfNotPresent(handler, parentViewGroup)
recordHandlerIfNotPresent(handler, parentViewGroup, pointerId)
handler.startTrackingPointer(pointerId)
}
}
Expand Down Expand Up @@ -654,7 +656,7 @@ class GestureHandlerOrchestrator(
continue
}

recordHandlerIfNotPresent(handler, view)
recordHandlerIfNotPresent(handler, view, pointerId)
handler.startTrackingPointer(pointerId)
found = true
}
Expand Down Expand Up @@ -691,7 +693,7 @@ class GestureHandlerOrchestrator(
continue
}

recordHandlerIfNotPresent(handler, view)
recordHandlerIfNotPresent(handler, view, pointerId)
handler.startTrackingPointer(pointerId)
found = true
}
Expand Down
Loading