Skip to content

Commit db96d16

Browse files
committed
Fix(gestures): Handle pointer events inside awaitPointerEventScope
The lint tool reported a "ReturnFromAwaitPointerEventScope" warning in KotlinSnippets.kt. Returning a value from this scope can lead to dropped input events due to the way pointer event queues are handled. This commit resolves the warning by moving the animation logic, which depends on the tap position, directly inside the awaitPointerEventScope block. This ensures that the event data is processed immediately within the correct context, preventing potential event loss.
1 parent d1b418e commit db96d16

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

compose/snippets/src/main/java/com/example/compose/snippets/kotlin/KotlinSnippets.kt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -340,15 +340,17 @@ fun MoveBoxWhereTapped() {
340340
// coroutines inside a suspend function
341341
coroutineScope {
342342
while (true) {
343-
// Wait for the user to tap on the screen
344-
val offset = awaitPointerEventScope {
345-
awaitFirstDown().position
346-
}
347-
// Launch a new coroutine to asynchronously animate to
348-
// where the user tapped on the screen
349-
launch {
350-
// Animate to the pressed position
351-
animatedOffset.animateTo(offset)
343+
// Wait for the user to tap on the screen and animate
344+
// in the same block
345+
awaitPointerEventScope {
346+
val offset = awaitFirstDown().position
347+
348+
// Launch a new coroutine to asynchronously animate to
349+
// where the user tapped on the screen
350+
launch {
351+
// Animate to the pressed position
352+
animatedOffset.animateTo(offset)
353+
}
352354
}
353355
}
354356
}

0 commit comments

Comments
 (0)