StickToBottomState

"Stick to bottom" for a chat list (the idea behind AI Elements' use-stick-to-bottom), for a normal top-to-bottom LazyListState:

  • While following, every layout change that leaves content below the viewport — a streamed token, a Markdown block finishing parsing, a Mermaid or KaTeX WebView reporting its height, an image decoding, the keyboard opening — pins the list back to the bottom, instantly (no animation to fall behind the stream).

  • The moment the user drags toward older content, following stops. Growth happens below the viewport, so what they are reading never moves.

  • Scrolling back to the very bottom, or jumpToLatest, resumes following.

Anything that moves the list away from the bottom that we didn't do ourselves — a drag or fling, but also accessibility scroll actions, keyboard paging or app code calling scrollToItem — stops following, so pinning never fights whoever is scrolling.

Properties

Link copied to clipboard
val connection: NestedScrollConnection

Install on the list (or a parent) with Modifier.nestedScroll(connection).

Link copied to clipboard

True while the list is pinned to the newest content.

Link copied to clipboard

Show a "scroll to latest" affordance.

Functions

Link copied to clipboard
suspend fun jumpToLatest(animated: Boolean = false)

Pin to the bottom and follow again (e.g. the user sent a message).