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
public val topItem: Int
The index of the item that's currently at the top of the stack, defaults to 0.
topItemOffsetFraction
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
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.
isScrollInProgress
override val isScrollInProgress: Boolean
canScrollForward
override val canScrollForward: Boolean
canScrollBackward
override val canScrollBackward: Boolean
lastScrolledForward
override val lastScrolledForward: Boolean
lastScrolledBackward
override val lastScrolledBackward: Boolean
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 |
scroll
override suspend fun scroll(
scrollPriority: MutatePriority,
block: suspend ScrollScope.() -> Unit,
)
dispatchRawDelta
override fun dispatchRawDelta(delta: Float): Float
Members
Companion
public companion object
Properties
Saver
public val Saver: Saver<StackState, *> =
Saver(save = { it.topItem }, restore = { StackState(it) })
The default Saver implementation for StackState.