I am trying to restrict user from swiping in a Horizontal pager and make it scroll only by a button click. I tried many ways and failed. I tried to disable the gesture by using this modifier extension function code.But this blocks clicks also which is not intended. So How to detect the swipe and block the swipe gesture alone?
fun Modifier.gesturesDisabled(disabled: Boolean = true) =
if (disabled) {
pointerInput(Unit) {
awaitPointerEventScope {
// we should wait for all new pointer events
while (true) {
awaitPointerEvent(pass = PointerEventPass.Initial)
.changes
.forEach(PointerInputChange::consumeAllChanges)
}
}
}
} else {
Modifier
}
i am using Horizontal Pager from accompanist
implementation "com.google.accompanist:accompanist-pager:0.24.4-alpha"
implementation "com.google.accompanist:accompanist-pager-indicators:0.21.2-beta"
and use it like
HorizontalPager(
count = 10,
state = pagerState,
modifier = Modifier.fillMaxSize()
) { tabIndex ->
Text(tabIndex.toString())
}