Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix tracking for multitouch gestures #1827

Merged
merged 2 commits into from
Feb 11, 2025
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 @@ -182,6 +182,98 @@ class SyntheticEventSenderTest {
)
}

@Test
fun `touch, should generate one press at a time on simultaneous touches press`() {
eventsSentBy(
event(
Press,
1 to touch(1f, 3f, pressed = true)
),
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = true)
),
) positionAndDownShouldEqual listOf(
event(
Press,
1 to touch(1f, 3f, pressed = true)
),
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = false),
),
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = true)
)
)
}

@Test
fun `touch, should generate one release at a time on simultaneous touches release`() {
eventsSentBy(
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = true),
),
event(
Release,
1 to touch(1f, 3f, pressed = false),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = true),
),
event(
Release,
2 to touch(10f, 20f, pressed = false),
3 to touch(100f, 200f, pressed = false),
),
) positionAndDownShouldEqual listOf(
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = false),
3 to touch(100f, 200f, pressed = false),
),
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = false),
),
event(
Press,
1 to touch(1f, 3f, pressed = true),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = true),
),
event(
Release,
1 to touch(1f, 3f, pressed = false),
2 to touch(10f, 20f, pressed = true),
3 to touch(100f, 200f, pressed = true),
),
event(
Release,
1 to touch(1f, 3f, pressed = false),
2 to touch(10f, 20f, pressed = false),
3 to touch(100f, 200f, pressed = true),
),
event(
Release,
2 to touch(10f, 20f, pressed = false),
3 to touch(100f, 200f, pressed = false),
)
)
}

@Test
fun `should consume move event when synthetic events added`() {
val sender = SyntheticEventSender { event ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,10 +146,7 @@ internal class SyntheticEventSender(
type = PointerEventType.Release,
copyPointer = {
it.copySynthetic(
// TODO is this a typo and it should be `it.id in newReleased`, as in sendMissingPresses?
// or maybe we can even write `down = !sendingAsUp.contains(it.id)` and `down = sendingAsDown.contains(it.id)`
// The test pass in both cases
down = !sendingAsUp.contains(it.id)
down = it.down && !sendingAsUp.contains(it.id)
)
}
)
Expand All @@ -161,9 +158,9 @@ internal class SyntheticEventSender(
}

private fun sendMissingPresses(currentEvent: PointerInputEvent): PointerEventResult {
val previousPressed = previousEvent?.pressedIds().orEmpty()
val previousPressed = previousEvent?.pressedIds().orEmpty().toSet()
val currentPressed = currentEvent.pressedIds()
val newPressed = (currentPressed - previousPressed.toSet()).toList()
val newPressed = (currentPressed - previousPressed).toList()
val sendingAsDown = HashSet<PointerId>(newPressed.size)

var result = PointerEventResult(anyMovementConsumed = false)
Expand All @@ -178,7 +175,7 @@ internal class SyntheticEventSender(
type = PointerEventType.Press,
copyPointer = {
it.copySynthetic(
down = sendingAsDown.contains(it.id)
down = previousPressed.contains(it.id) || sendingAsDown.contains(it.id)
)
}
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,11 @@ internal class UserInputGestureRecognizer(
super.touchesEnded(touches, withEvent)

fun endTouchesEvent() {
setState(UIGestureRecognizerStateEnded)
onTouchesEvent(trackedTouches.keys, withEvent, TouchesEventKind.ENDED)
stopTrackingTouches(touches)
if (trackedTouches.isEmpty()) {
setState(UIGestureRecognizerStateEnded)
}
}

if (state.isOngoing) {
Expand Down