Class

ListState

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

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Android
public class ListState(firstVisibleItemIndex: Int = 0, firstVisibleItemScrollOffset: Int = 0) :
    ScrollableState

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

In most cases, this will be created via rememberListState.

Parameters

firstVisibleItemIndex the initial value for ListState.firstVisibleItemIndex
firstVisibleItemScrollOffset the initial value for ListState.firstVisibleItemScrollOffset

Functions

scrollToItem

public suspend fun scrollToItem(@IntRange(from = 0) index: Int, scrollOffset: Int = 0)

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

Parameters

index the index to which to scroll. Must be non-negative.
scrollOffset the offset that the item should end up after the scroll. Note that positive offset refers to forward scroll, so in a top-to-bottom list, positive offset will scroll the item further upward (taking it partly offscreen).

animateScrollToItem

public suspend fun animateScrollToItem(@IntRange(from = 0) index: Int, scrollOffset: Int = 0)

Animate (smooth scroll) to the given item.

Parameters

index the index to which to scroll. Must be non-negative.
scrollOffset the offset that the item should end up after the scroll. Note that positive offset refers to forward scroll, so in a top-to-bottom list, positive offset will scroll the item further upward (taking it partly offscreen).

Companion Object

Properties

Android
public val Saver: Saver<ListState, Any>

The default Saver implementation for ListState.