Class

StackState

The VerticalStack state that allows programmatic control and observation of the stack's state.

RevenueCat

RevenueCat

Add subscriptions to your apps in minutes

Ad Get started for free
Android
public class StackState(@IntRange(from = 0) initialTopItem: Int = 0) : ScrollableState

The VerticalStack state that allows programmatic control and observation of the stack's state.

A StackState object can be created and remembered using rememberStackState.

Note: Properties of the state will only be correctly populated after the VerticalStack it is associated with has been composed for the first time.

Warning: A single StackState instance must not be shared across multiple VerticalStack composables.

Parameters

initialTopItem The index of the item to show at the top of the stack initially. Must be non-negative. Defaults to 0.

Functions

scrollToItem

public suspend fun scrollToItem(item: Int)

Scroll (jump immediately) to a given item index.

Parameters

item The index of the destination item

animateScrollToItem

public suspend fun animateScrollToItem(
        item: Int,
        animationSpec: AnimationSpec<Float> = spring(),
    )

Scroll animate to a given item's closest snap position. If the item is too far away from topItem, not all the items in the range will be composed. Instead, the stack will jump to a nearer item, then compose and animate the rest of the items until the destination item.

Parameters

item The index of the destination item
animationSpec An AnimationSpec to move between items

Companion Object

Properties

Android
public val Saver: Saver<StackState, *>

The default Saver implementation for StackState.