scroll

suspend fun scroll(block: suspend ScrollScope.() -> Unit)

Runs block with this state's position to itself, for a caller that moves the pane over time - a step per frame - rather than in one write.

val scope = rememberCoroutineScope()
scope.launch { state.scroll { scrollTo(0, state.maxY) } }

The block moves the pane through ScrollScope.scrollTo and holds the position until it returns. Whatever else moves the position ends it - the user scrolling the pane, a write to x or y, a revealRect, a layout pass correcting a position that no longer shows content - and so does a later scroll, which takes the position, ends the block holding it and waits for that block to unwind before running its own. Last caller wins. A block ended either way is cancelled, so CancellationException reaches this call and the statements after it in the caller's coroutine do not run.

Runs on the Event Dispatch Thread, like every other write to this state: launch it from rememberCoroutineScope(), or from a scope dispatched there.

Parameters

block

the moves to make, run with a ScrollScope that writes this state's position.

Throws

if called off the Event Dispatch Thread, from inside a scroll block of this same state, or if waiting for a predecessor would form a circular scroll handover.