Lukas K-G
05/20/2021, 4:24 AMZach Klippenstein (he/him) [MOD]
05/20/2021, 2:54 PMLukas K-G
05/21/2021, 5:01 AMPiotr Prus
06/10/2021, 9:38 AMpointerInput
on the scrollable list, but awaitPointedEvents is throwing an error: java.lang.IllegalStateException: cannot access currentEvent outside of input dispatch
And detectVerticalDragGestures
is blocking my scroll 😞Lukas K-G
06/10/2021, 9:40 AMPiotr Prus
06/10/2021, 9:52 AMZach Klippenstein (he/him) [MOD]
06/10/2021, 2:35 PMPiotr Prus
06/10/2021, 4:16 PM@Composable
fun TestColumn() {
val listState = rememberScrollState()
Column(modifier = Modifier
.fillMaxWidth()
.verticalScroll(listState)
.pointerInput(Unit) {
detectVerticalDragGestures { change, dragAmount ->
Log.d("AAAA", "change: $change")
}
}) {
for (index in 1..20) {
Surface(color = Color.Red) {
Text(
modifier = Modifier.padding(12.dp),
text = "Next number: $index",
style = MaterialTheme.typography.h5
)
}
}
}
}
The log is displayed, the drag gesture is consumed and not passed.Zach Klippenstein (he/him) [MOD]
06/10/2021, 4:22 PMPiotr Prus
06/10/2021, 4:40 PM@Composable
fun TestColumn2() {
val listState = rememberScrollState()
Column(modifier = Modifier
.fillMaxWidth()
.verticalScroll(listState)
.pointerInput(Unit) {
awaitPointerEventScope {
Log.d("AAAA", "pointer event: ${this.currentEvent}")
}
}) {
for (index in 1..20) {
Surface(color = Color.Red) {
Text(
modifier = Modifier.padding(12.dp),
text = "Next number: $index",
style = MaterialTheme.typography.h5
)
}
}
}
}
The error:
java.lang.IllegalStateException: cannot access currentEvent outside of input dispatch
at androidx.compose.ui.input.pointer.SuspendingPointerInputFilter$PointerEventHandlerCoroutine.getCurrentEvent(SuspendingPointerInputFilter.kt:419)
Piotr Prus
06/10/2021, 5:46 PMawaitPointerEventScope
needs to be in coroutine scope. I thought the lambda exp of pinterInput is already a coroutineScope 🙂 .
The solution:
.pointerInput(Unit) {
coroutineScope {
forEachGesture {
awaitPointerEventScope {
val event = awaitPointerEvent()
event.changes.forEach { inputChange ->
val drag = awaitVerticalDragOrCancellation(inputChange.id)
Log.d("AAAA", "drag or cancel change: ${drag?.positionChange()}")
}
}
}
}
}
Zach Klippenstein (he/him) [MOD]
06/10/2021, 6:02 PMZach Klippenstein (he/him) [MOD]
06/10/2021, 6:03 PM