How can I disable `HorizontalPager` scroll (via `u...
# compose
s
How can I disable
HorizontalPager
scroll (via
userScrollEnabled
) when the user started a
LazyColumn
scroll (and vice versa)? Do I need to write a complex
NestedScrollConnection
?
c
Are you using the accompanist
HorizontalPager
?
s
Yes
c
For a consistent user experience, I would disable horizontal scrolling altogether. Having two directions of scrolls in the same page is not a good ux
s
Material design guidelines don't say so (https:/material.io/components/tabs#behavior), and many users already asked for this feature. Many apps (made with the traditional Android `View`s) have the desired behavior - and I could achieve it as well using my own
Pager
... Of course, the UX I showed is terrible.
c
Copy code
val listState = rememberLazyListState()
https://developer.android.com/reference/kotlin/androidx/compose/foundation/lazy/LazyListState#isScrollInProgress() This should tell you whether someone is scrolling around vertically, you can simple change the value for
userScrollEnabled
based on it
s
@chatterInDaSkull I did that already but it's not enough. The very first drag will still dispatch X changes to the
HorizontalPager
and Y changes to the
LazyColumn
I think it's due to how
HorizontalPager
detect drags: it uses
scrollable
instead of
draggable
(my
Pager
that doesn't have this problem uses
detectHorizontalDragGestures
)
PS: I can't really use my
Pager
because it's not lazy. I started re-implementing it using a
LazyLayout
yesterday
c
Might be worth writing a bug report or a feature request for accompanist itself
s
I implemented my own pager and got an acceptable result:
c
you should share your snippet so people can use it in the future
634 Views