Is it possible to opt a `LazyColumn` out of a nest...
# compose
j
Is it possible to opt a
LazyColumn
out of a nested scroll chain? The docs only explain how to opt in/configure the existing chain: https://developer.android.com/jetpack/compose/gestures#auto-nested-scrolling
m
Can you please share a use case where you would want this? We explicitly made a decision to include nested scroll by default with no opt-out capabilities, so the contract is always consistent when you don't know your children / parent.
j
Sure, our UI requires that we have scrollable pickers inside a list of items. The entire page is also a full-screen bottom sheet. Scrolling the pickers causes the whole list to shuffle around, and also scrolls the whole bottom sheet. I’ve attached videos of compose vs our production app. Scrolling the pickers in production does not cause anything else to scroll:
(First video is compose, second video is existing functionality)
I think it’s good UX that scrolling can chain up to parent containers, but I don’t know if it should always happen in the same gesture. For example, take a look at how the Shazam iOS app handles this: scrolling the content inside the list does not close the bottom sheet once we reach the top. A second scroll gesture if the list is already scrolled to the top will close it Until we’re able to do something like that I think we probably need some opt-out capability
m
So you'r picker is also a LazyColumn?
If so, you can pass a
Modifier.nestedScroll
and pass an ``object: NestedScrollConnection` with overriden
onPostScroll
and
onPostFling
that should eat all delta/velocity, so the bottom sheet that is higher in the nested scroll hierarchy gets nothing
j
@matvei Yeah the picker is also a LazyColumn. Overriding those methods didn’t work unfortunately:
Copy code
.nestedScroll(object : NestedScrollConnection {
    override fun onPostScroll(
        consumed: Offset,
        available: Offset,
        source: NestedScrollSource
    ): Offset {
        return Offset.Zero
    }

    override suspend fun onPostFling(
        consumed: Velocity,
        available: Velocity
    ): Velocity {
        return Velocity.Zero
    }
})
m
According to the nestedScroll modifier documentation, please try to: 1. Remember the NEstedScrollConnection object. 2. return
available
in both cases and not
Velocity.Zero
since you want to consume everything available to stop the propagation up
j
That worked, thanks!
👍 1