Class

StackState

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

Source set: 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.

Properties

topItem

Source set: Android
public val topItem: Int

The index of the item that's currently at the top of the stack, defaults to 0.

topItemOffsetFraction

Source set: Android
public val topItemOffsetFraction: Float

The offset of the top item as a fraction of the stack item container size. The value indicates how much the item is offset from the snapped position. This value ranges between 0.0 (snapped position) and 1.0 (lower bound of the top item is at the top of the viewport).

interactionSource

Source set: Android
public val interactionSource: InteractionSource

InteractionSource that's used to dispatch drag events when this stack is being dragged. To know whether a fling (or animated scroll) is in progress, use isScrollInProgress.

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

Source set: Android
public val Saver: Saver<StackState, *>

The default Saver implementation for StackState.

Last updated: