From db96d16bf9d827e70a41944d92a34d5cb2ac57b8 Mon Sep 17 00:00:00 2001 From: cartland Date: Fri, 15 Aug 2025 13:16:29 -0700 Subject: [PATCH] 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. --- .../compose/snippets/kotlin/KotlinSnippets.kt | 20 ++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/compose/snippets/src/main/java/com/example/compose/snippets/kotlin/KotlinSnippets.kt b/compose/snippets/src/main/java/com/example/compose/snippets/kotlin/KotlinSnippets.kt index 12c5618b4..447b37031 100644 --- a/compose/snippets/src/main/java/com/example/compose/snippets/kotlin/KotlinSnippets.kt +++ b/compose/snippets/src/main/java/com/example/compose/snippets/kotlin/KotlinSnippets.kt @@ -340,15 +340,17 @@ fun MoveBoxWhereTapped() { // coroutines inside a suspend function coroutineScope { while (true) { - // Wait for the user to tap on the screen - val offset = awaitPointerEventScope { - awaitFirstDown().position - } - // Launch a new coroutine to asynchronously animate to - // where the user tapped on the screen - launch { - // Animate to the pressed position - animatedOffset.animateTo(offset) + // Wait for the user to tap on the screen and animate + // in the same block + awaitPointerEventScope { + val offset = awaitFirstDown().position + + // Launch a new coroutine to asynchronously animate to + // where the user tapped on the screen + launch { + // Animate to the pressed position + animatedOffset.animateTo(offset) + } } } }