bug: fixed bug #534 of multiple clicks on the interests screen

pull/568/head
vishesh 2 years ago
parent eb6dbaac0b
commit a4eddf6fa3

@ -26,6 +26,8 @@ buildscript {
}
plugins {
java
application
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false

@ -25,9 +25,12 @@ import androidx.compose.foundation.layout.windowInsetsBottomHeight
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.input.pointer.PointerEventPass
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.unit.dp
import com.google.samples.apps.nowinandroid.core.domain.model.FollowableTopic
import kotlinx.coroutines.coroutineScope
@Composable
fun TopicsTabContent(
@ -39,7 +42,8 @@ fun TopicsTabContent(
LazyColumn(
modifier = modifier
.padding(horizontal = 16.dp)
.testTag("interests:topics"),
.testTag("interests:topics")
.disableSplitMotionEvents(),
contentPadding = PaddingValues(top = 8.dp)
) {
topics.forEach { followableTopic ->
@ -61,3 +65,22 @@ fun TopicsTabContent(
}
}
}
fun Modifier.disableSplitMotionEvents() =
pointerInput(Unit) {
coroutineScope {
var currentId: Long = -1L
awaitPointerEventScope {
while (true) {
awaitPointerEvent(PointerEventPass.Initial).changes.forEach { pointerInfo ->
when {
pointerInfo.pressed && currentId == -1L -> currentId = pointerInfo.id.value
pointerInfo.pressed.not() && currentId == pointerInfo.id.value -> currentId = -1
pointerInfo.id.value != currentId && currentId != -1L -> pointerInfo.consume()
else -> Unit
}
}
}
}
}
}

Loading…
Cancel
Save