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.

Summary

Public companion properties

Saver<StackStateInt>

The default Saver implementation for StackState.

Public constructors

StackState(initialTopItem: @IntRange(from = 0) Int)

Public functions

suspend Unit
animateScrollToItem(item: Int, animationSpec: AnimationSpec<Float>)

Scroll animate to a given item's closest snap position.

open Float
open suspend Unit
scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit)
suspend Unit

Scroll (jump immediately) to a given item index.

Public properties

open Boolean
open Boolean
InteractionSource

InteractionSource that's used to dispatch drag events when this stack is being dragged.

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.

Public companion properties

Saver

Added in 1.0.0-alpha01
val SaverSaver<StackStateInt>

The default Saver implementation for StackState.

Public constructors

StackState

Added in 1.0.0-alpha01
StackState(initialTopItem: @IntRange(from = 0) Int = 0)
Parameters
initialTopItem: @IntRange(from = 0) Int = 0

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

Public functions

animateScrollToItem

Added in 1.0.0-alpha01
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 AnimationSpec to move between items

dispatchRawDelta

Added in 1.0.0-alpha01
open fun dispatchRawDelta(delta: Float): Float

scroll

Added in 1.0.0-alpha01
open suspend fun scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit): Unit

scrollToItem

Added in 1.0.0-alpha01
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

canScrollBackward

open val canScrollBackwardBoolean

canScrollForward

open val canScrollForwardBoolean

interactionSource

Added in 1.0.0-alpha01
val interactionSourceInteractionSource

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

Added in 1.0.0-alpha01
open val isScrollInProgressBoolean

lastScrolledBackward

open val lastScrolledBackwardBoolean

lastScrolledForward

open val lastScrolledForwardBoolean

topItem

Added in 1.0.0-alpha01
val topItemInt

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

topItemOffsetFraction

Added in 1.0.0-alpha01
val topItemOffsetFractionFloat

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).