androidx.compose.foundation.lazy

LazyListState

Class · from org.jetbrains.compose.foundation:foundation:1.12.2

No hand-written docs yet.

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

class LazyListState(
    firstVisibleItemIndex: Int = 0,
    firstVisibleItemScrollOffset: Int = 0,
    prefetchStrategy: LazyListPrefetchStrategy = LazyListPrefetchStrategy(),
) : ScrollableState

Is a

How to get one

Create it

Ready-made values and functions that return it

Used by

Parameters that take a LazyListState.

Properties

firstVisibleItemIndex

val firstVisibleItemIndex: Int

The index of the first item that is visible within the scrollable viewport area not including items in the content padding region. For the first visible item that includes items in the content padding please use LazyListLayoutInfo.visibleItemsInfo.

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.

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.

interactionSource

val interactionSource: InteractionSource

InteractionSource that will be used to dispatch drag events when this list is being dragged. If you want to know whether the fling (or animated scroll) is in progress, use isScrollInProgress.

Saver

val Saver: Saver<LazyListState, *>

The default Saver implementation for LazyListState.

Functions

scrollToItem

fun scrollToItem(
    index: Int,
    scrollOffset: Int = 0,
)

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

requestScrollToItem

fun requestScrollToItem(
    index: Int,
    scrollOffset: Int = 0,
)

Requests the item at index to be at the start of the viewport during the next remeasure, offset by scrollOffset, and schedules a remeasure.

animateScrollToItem

fun animateScrollToItem(
    index: Int,
    scrollOffset: Int = 0,
)

Animate (smooth scroll) to the given item.

Library docs

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

In most cases, this will be created via rememberLazyListState.