StackState
class StackState : 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.
| See also | |
|---|---|
rememberStackState |
|
VerticalStack |
Summary
Public companion properties |
|
|---|---|
Saver<StackState, Int> |
The default |
Public constructors |
|---|
StackState(initialTopItem: @IntRange(from = 0) Int) |
Public functions |
|
|---|---|
suspend Unit |
animateScrollToItem(item: Int, animationSpec: AnimationSpec<Float>)Scroll animate to a given |
open Float |
dispatchRawDelta(delta: Float) |
open suspend Unit |
scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit) |
suspend Unit |
scrollToItem(item: Int)Scroll (jump immediately) to a given |
Public properties |
|
|---|---|
open Boolean |
|
open Boolean |
|
InteractionSource |
|
open Boolean |
|
open Boolean |
|
open Boolean |
|
Int |
The index of the item that's currently at the top of the stack, defaults to 0. |
Float |
The offset of the top item as a fraction of the stack item container size. |
Inherited properties |
|---|
Public companion properties
Saver
val Saver: Saver<StackState, Int>
The default Saver implementation for StackState.
Public constructors
Public functions
animateScrollToItem
suspend fun animateScrollToItem(
item: Int,
animationSpec: AnimationSpec<Float> = spring()
): Unit
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: Int |
The index of the destination item |
animationSpec: AnimationSpec<Float> = spring() |
An |
scroll
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit
scrollToItem
suspend fun scrollToItem(item: Int): Unit
Scroll (jump immediately) to a given item index.
| Parameters | |
|---|---|
item: Int |
The index of the destination item |
Public properties
interactionSource
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.
topItem
val topItem: Int
The index of the item that's currently at the top of the stack, defaults to 0.
topItemOffsetFraction
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).