Skip to content

Commit a4eddf6

Browse files
bug: fixed bug #534 of multiple clicks on the interests screen
1 parent eb6dbaa commit a4eddf6

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

build.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ buildscript {
2626
}
2727

2828
plugins {
29+
java
30+
application
2931
alias(libs.plugins.android.application) apply false
3032
alias(libs.plugins.kotlin.jvm) apply false
3133
alias(libs.plugins.kotlin.serialization) apply false

feature/interests/src/main/java/com/google/samples/apps/nowinandroid/feature/interests/TabContent.kt

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,12 @@ import androidx.compose.foundation.layout.windowInsetsBottomHeight
2525
import androidx.compose.foundation.lazy.LazyColumn
2626
import androidx.compose.runtime.Composable
2727
import androidx.compose.ui.Modifier
28+
import androidx.compose.ui.input.pointer.PointerEventPass
29+
import androidx.compose.ui.input.pointer.pointerInput
2830
import androidx.compose.ui.platform.testTag
2931
import androidx.compose.ui.unit.dp
3032
import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic
33+
import kotlinx.coroutines.coroutineScope
3134

3235
@Composable
3336
fun 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

Comments
 (0)