@@ -25,9 +25,12 @@ import androidx.compose.foundation.layout.windowInsetsBottomHeight
2525import androidx.compose.foundation.lazy.LazyColumn
2626import androidx.compose.runtime.Composable
2727import androidx.compose.ui.Modifier
28+ import androidx.compose.ui.input.pointer.PointerEventPass
29+ import androidx.compose.ui.input.pointer.pointerInput
2830import androidx.compose.ui.platform.testTag
2931import androidx.compose.ui.unit.dp
3032import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic
33+ import kotlinx.coroutines.coroutineScope
3134
3235@Composable
3336fun TopicsTabContent (
@@ -39,7 +42,8 @@ fun TopicsTabContent(
3942 LazyColumn (
4043 modifier = modifier
4144 .padding(horizontal = 16 .dp)
42- .testTag(" interests:topics" ),
45+ .testTag(" interests:topics" )
46+ .disableSplitMotionEvents(),
4347 contentPadding = PaddingValues (top = 8 .dp)
4448 ) {
4549 topics.forEach { followableTopic ->
@@ -61,3 +65,22 @@ fun TopicsTabContent(
6165 }
6266 }
6367}
68+
69+ fun Modifier.disableSplitMotionEvents () =
70+ pointerInput(Unit ) {
71+ coroutineScope {
72+ var currentId: Long = - 1L
73+ awaitPointerEventScope {
74+ while (true ) {
75+ awaitPointerEvent(PointerEventPass .Initial ).changes.forEach { pointerInfo ->
76+ when {
77+ pointerInfo.pressed && currentId == - 1L -> currentId = pointerInfo.id.value
78+ pointerInfo.pressed.not () && currentId == pointerInfo.id.value -> currentId = - 1
79+ pointerInfo.id.value != currentId && currentId != - 1L -> pointerInfo.consume()
80+ else -> Unit
81+ }
82+ }
83+ }
84+ }
85+ }
86+ }
0 commit comments