Google is committed to advancing racial equity for Black communities. See how.

LazyListState

@Stable class LazyListState : Scrollable
kotlin.Any
   ↳ androidx.compose.foundation.lazy.LazyListState

A state object that can be hoisted to control and observe scrolling

In most cases, this will be created via rememberLazyListState.

Summary

Public constructors
<init>(firstVisibleItemIndex: Int = 0, firstVisibleItemScrollOffset: Int = 0, interactionState: InteractionState? = null, flingConfig: FlingConfig, animationClock: AnimationClockObservable)

A state object that can be hoisted to control and observe scrolling

Public methods
suspend Unit
scroll(block: suspend ScrollScope.() -> Unit)

Call this function to take control of scrolling and gain the ability to send scroll events via ScrollScope.scrollBy.

suspend Unit
snapToItemIndex(@IntRange(0) index: Int, @IntRange(0) scrollOffset: Int = 0)

Instantly brings the item at index to the top of the viewport, offset by scrollOffset pixels.

Companion functions
Saver<LazyListState, *>
Saver(flingConfig: FlingConfig, animationClock: AnimationClockObservable, interactionState: InteractionState?)

The default Saver implementation for LazyListState.

Inherited extension functions
From androidx.compose.foundation.animation
suspend Float
Scrollable.smoothScrollBy(value: Float, spec: AnimationSpec<Float> = spring())

Smooth scroll by value pixels.

Properties
Int

The index of the first item that is visible

Int

The scroll offset of the first visible item.

Boolean

Whether this LazyListState is currently scrolling via scroll or via an animation/fling.

LazyListLayoutInfo

The object of LazyListLayoutInfo calculated during the last layout pass.

Public constructors

<init>

LazyListState(
    firstVisibleItemIndex: Int = 0,
    firstVisibleItemScrollOffset: Int = 0,
    interactionState: InteractionState? = null,
    flingConfig: FlingConfig,
    animationClock: AnimationClockObservable)

A state object that can be hoisted to control and observe scrolling

In most cases, this will be created via rememberLazyListState.

Parameters
firstVisibleItemIndex: Int = 0 the initial value for LazyListState.firstVisibleItemIndex
firstVisibleItemScrollOffset: Int = 0 the initial value for
interactionState: InteractionState? = null InteractionState that will be updated when the element with this state is being scrolled by dragging, using Interaction.Dragged. If you want to know whether the fling (or smooth scroll) is in progress, use LazyListState.isAnimationRunning.
flingConfig: FlingConfig fling configuration to use for flinging
animationClock: AnimationClockObservable animation clock to run flinging and smooth scrolling on

Public methods

scroll

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

Call this function to take control of scrolling and gain the ability to send scroll events via ScrollScope.scrollBy. All actions that change the logical scroll position must be performed within a scroll block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

Cancels the currently running scroll, if any, and suspends until the cancellation is complete.

If scroll is called from elsewhere, this will be canceled.

snapToItemIndex

suspend fun snapToItemIndex(
    @IntRange(0) index: Int,
    @IntRange(0) scrollOffset: Int = 0
): Unit

Instantly brings the item at index to the top of the viewport, offset by scrollOffset pixels.

Cancels the currently running scroll, if any, and suspends until the cancellation is complete.

Parameters
index: Int the data index to snap to
scrollOffset: Int = 0 the number of pixels past the start of the item to snap to

Properties

firstVisibleItemIndex

val firstVisibleItemIndex: Int

The index of the first item that is visible

firstVisibleItemScrollOffset

val firstVisibleItemScrollOffset: Int

The scroll offset of the first visible item. Scrolling forward is positive - i.e., the amount that the item is offset backwards

isAnimationRunning

val isAnimationRunning: Boolean

Whether this LazyListState is currently scrolling via scroll or via an animation/fling.

Note: all scrolls initiated via scroll are considered to be animations, regardless of whether they are actually performing an animation.

layoutInfo

val layoutInfo: LazyListLayoutInfo

The object of LazyListLayoutInfo calculated during the last layout pass. For example, you can use it to calculate what items are currently visible.

Companion functions

Saver

fun Saver(
    flingConfig: FlingConfig,
    animationClock: AnimationClockObservable,
    interactionState: InteractionState?
): Saver<LazyListState, *>

The default Saver implementation for LazyListState.