Is it possible to decrease swipe sensitivity for `...
# compose
m
Is it possible to decrease swipe sensitivity for
Pager
? In my case,
Pager
item contains
LazyColumn
so there is horizontal Pager swipe and vertical LazyColumn scroll conflict. This is common problem which is easy to fix in View system by overriding
touch slop
property in
ViewPager
. Is same possible in Compose?
a
You can provide your own
LocalViewConfiguration
with
touchSlop
overridden.
m
I tried something like this but still not working as expected (there is still conflict between horizontal/vertical scroll):
Copy code
val viewConfiguration = LocalViewConfiguration.current
val updatedViewConfiguration = remember(viewConfiguration) {
  object : ViewConfiguration by viewConfiguration {
    override val touchSlop: Float
      get() = viewConfiguration.touchSlop * 3
  }
}

Box(modifier = Modifier.fillMaxSize()) {
  CompositionLocalProvider(
    LocalViewConfiguration provides updatedViewConfiguration,
  ) {
    Pager(...)
    }
  }
And then override it again inside page where
LazyColumn
is defined:
Copy code
val viewConfiguration = LocalViewConfiguration.current
val updatedViewConfiguration = remember(viewConfiguration) {
    object : ViewConfiguration by viewConfiguration {
      override val touchSlop: Float
        get() = 5f // decrease for higher sensitivity
    }
  }

HorizontalPager(
    state = pagerState,
    key = ...,
) { index ->
    CompositionLocalProvider(
      LocalViewConfiguration provides updatedViewConfiguration,
    ) {
         LazyColumn(...)
    }
  }
a
1. You should use the original value inside the pager instead of a fixed value. 2. What do you mean by “conflict”? If you still feel the sensitivity is too high, just increase the value for the pager. This works in the same way as overriding touch slop of ViewPager.
m
By "conflict" I mean that often vertical scroll triggers
Pager
and not
LazyColumn
scroll. That is a reason why I want to decrease
Pager
sensitivity. But with this approach (using
CompositionLocalProvider
), when I decrease
Pager
sensitivity, I also change sensitivity for
LazyColumn
since
LazyColumn
is a child of a
Pager
item. Do you have any suggestion to fix that?
a
As I suggested you should set the touch slop to the original value inside the pager.
u
@Matija Sokol Were you able to get a solution for this?
m
@लातों वाला भूत I didn't resolve this.