Jakub Ledwon
12/13/2022, 11:48 AMPinnedScrollBehavior
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?Jakub Ledwon
12/13/2022, 12:02 PMclass 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 🤔 ?Jakub Ledwon
12/14/2022, 11:13 AM