ObserveScrollDirection

fun LazyListState.ObserveScrollDirection(onScrollForward: () -> Unit, onScrollBackward: () -> Unit)

Observes this LazyListState's scroll position and calls onScrollForward/onScrollBackward every time the scroll direction actually changes (not on every scroll delta) — the real mechanism behind LazyColumn/LazyRow's OnScrolled trigger (ScrollDirection.Bottom/End maps to onScrollForward, ScrollDirection.Top/Start to onScrollBackward).

Direction is derived by comparing the current firstVisibleItemIndex/firstVisibleItemScrollOffset pair against the previous one on every emission of snapshotFlow; a frame where neither changes calls neither callback.

Parameters

onScrollForward

called when the list's first visible item moves later (scrolling toward the end of the list).

onScrollBackward

called when it moves earlier (scrolling toward the start).


fun ScrollState.ObserveScrollDirection(onScrollForward: () -> Unit, onScrollBackward: () -> Unit)

Same as the LazyListState overload above, for a plain (non-lazy) ScrollState — the mechanism behind Column/Row's own OnScrolled trigger when scrollable = true. Direction is derived by comparing the current scroll offset (ScrollState.value) against the previous one.

Parameters

onScrollForward

called when the scroll offset increases.

onScrollBackward

called when it decreases.