Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accompanist Nested HorizontalPager disable swipes in parent

I have a nested HorizontalPager like

HorizontalPager(
   count = list.size
) {
   HorizontalPager(
    count = list2.size
   ) {
     //items
   }
 }

is there any way to disable horizontal scrolling in parents pager, but enable in childrens.

This solution disables scroll in all childs views and it isn't what i need

private val HorizontalScrollConsumer = object : NestedScrollConnection {
    override fun onPreScroll(available: Offset, source: NestedScrollSource) = available.copy(y = 0f)
    override suspend fun onPreFling(available: Velocity) = available.copy(y = 0f)
}

fun Modifier.disabledHorizontalPointerInputScroll(disabled: Boolean = true) =
    if (disabled) this.nestedScroll(HorizontalScrollConsumer) else this
like image 732
dbuzin Avatar asked Jan 25 '26 14:01

dbuzin


1 Answers

Pass this argument in HorizontalPager

userScrollEnabled = false

HorizontalPager(
    ...
    userScrollEnabled = false
    ...
) {
  // Your Code...
}

Note: By default userScrollEnabled is true, if we need to disable it, just pass this argument with false in HorizontalPager

like image 134
Tippu Fisal Sheriff Avatar answered Jan 28 '26 06:01

Tippu Fisal Sheriff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!