Как заставить Jetpack Compose HorizontalPager проводить только вперед (отключить пролистывание назад)?Android

Форум для тех, кто программирует под Android
Ответить Пред. темаСлед. тема
Anonymous
 Как заставить Jetpack Compose HorizontalPager проводить только вперед (отключить пролистывание назад)?

Сообщение Anonymous »

На Android с использованием Jetpack Compose я хочу, чтобы HorizontalPager прокручивался только в одном направлении, то есть только вперед. Я не могу заставить pointerInput или pointerInteropFilter правильно обрабатывать обнаружение жестов.
Я попробовал следующий код, но ни один из вариантов не работает

Код: Выделить всё

 // if you use detectDragGesture on the box, then the message is printed, however the event does not bubble up and the horizontalPager will not swipe
// if you put the pointerInput onto the HorizontalPager, then the gesture is not detected and no message is printed
HorizontalPager(state = pagerState) { page ->
// Display each page with a different background color
Box(
modifier = Modifier
.fillMaxSize()
.background(colors[page])
.pointerInput(Unit) {
detectDragGestures { _, _ ->
println("In Here")
}
}
) {
}
}

// the other option is to use pointerInteropFilter
// the problem with this is that when used with the horizontalPager it does not detect the ACTION_MOVE for horizontal scroll
HorizontalPager(state = pagerState) { page ->
Box(
modifier = Modifier
.fillMaxSize()
.background(colors[page])
.pointerInteropFilter { motionEvent ->
when (motionEvent.action)
MotionEvent.ACTION_MOVE -> {
// This is not detected for horizontal scroll
println("ACTION_MOVE")
}                    }
true
}
) {
Text("Hello")
}
}
Если я смогу правильно определить пролистывание назад, я смогу установить userScrollEnabled на пейджере, чтобы отключить пролистывание назад.
Любой другой подход к отключению пролистывания назад тоже подойдет.


Подробнее здесь: https://stackoverflow.com/questions/788 ... ble-backwa
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение

Вернуться в «Android»