Add new gesture detector method for looping over gestures
Fixes: 251260206
Relnote: "A new method, awaitEachGesture(), for gesture detectors
was added. It operates similar to forEachGesture(), but the loop
over gestures operates entirely within the AwaitPointerEventScope
so events can't be lost between iterations.
forEachGesture() has been deprecated in favor of awaitEachGesture()
because it allows events to be lost between gestures."
Test: new tests
Change-Id: Iffc3fb8cf53d0e5eb9b529c023b3e2d29003e86f
diff --git a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
index 7538250..87053fb 100644
--- a/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
+++ b/compose/foundation/foundation/src/commonMain/kotlin/androidx/compose/foundation/text/selection/SelectionManager.kt
@@ -20,7 +20,7 @@
import androidx.compose.foundation.fastFold
import androidx.compose.foundation.focusable
-import androidx.compose.foundation.gestures.forEachGesture
+import androidx.compose.foundation.gestures.awaitEachGesture
import androidx.compose.foundation.gestures.waitForUpOrCancellation
import androidx.compose.foundation.text.Handle
import androidx.compose.foundation.text.TextDragObserver
@@ -54,7 +54,6 @@
import kotlin.math.absoluteValue
import kotlin.math.max
import kotlin.math.min
-import kotlinx.coroutines.coroutineScope
/**
* A bridge class between user interaction to the text composables for text selection.
@@ -615,13 +614,9 @@
* Detect tap without consuming the up event.
*/
private suspend fun PointerInputScope.detectNonConsumingTap(onTap: (Offset) -> Unit) {
- forEachGesture {
- coroutineScope {
- awaitPointerEventScope {
- waitForUpOrCancellation()?.let {
- onTap(it.position)
- }
- }
+ awaitEachGesture {
+ waitForUpOrCancellation()?.let {
+ onTap(it.position)
}
}
}