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) + } } } }