Hi folks, I’m trying to use `PinnedScrollBehavior`...
# compose
j
Hi folks, I’m trying to use
PinnedScrollBehavior
for
TopBar
, the thing is that my
LazyColumn
has
reverseLayout
set to
true
. Because of that TopBar only changes color when I scroll to the top and then start scrolling to the bottom again, which is not the desired behaviour. Has anyone dealt with the same case?
I’ve come up with something like:
Copy code
class ReversedPinnedScrollBehaviour(
    override val state: TopAppBarState,
    val canScroll: () -> Boolean = { true }
) : TopAppBarScrollBehavior {
    override val isPinned: Boolean = true
    override val flingAnimationSpec: DecayAnimationSpec<Float>? = null
    override val snapAnimationSpec: AnimationSpec<Float>? = null
    override val nestedScrollConnection: NestedScrollConnection =
        object : NestedScrollConnection {
            override fun onPostScroll(
                consumed: Offset,
                available: Offset,
                source: NestedScrollSource
            ): Offset {
                if (!canScroll()) return Offset.Zero
                if (consumed.y == 0f && available.y < 0f) {
                    // Reset the total content offset to zero when scrolling all the way down.
                    // This will eliminate some float precision inaccuracies.
                    state.contentOffset = 0f
                } else {
                    state.contentOffset -= consumed.y
                }
                return Offset.Zero
            }
        }
}
But I wonder if there is out of the box solution for that 🤔 ?
If anyone’s interested I’ve added it to issue tracker https://issuetracker.google.com/issues/262234750