StackState


public final class StackState implements 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

Nested types

public static class StackState.Companion

Public constructors

StackState(@IntRange(from = 0) int initialTopItem)

Public methods

final void
animateScrollToItem(
    int item,
    @NonNull AnimationSpec<@NonNull Float> animationSpec
)

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

float
dispatchRawDelta(float delta)
boolean
boolean
final @NonNull InteractionSource

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

boolean
boolean
final int

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

final float

The offset of the top item as a fraction of the stack item container size.

boolean
void
scroll(
    @NonNull MutatePriority scrollPriority,
    @NonNull SuspendFunction1<@NonNull ScrollScopeUnit> block
)
final void
scrollToItem(int item)

Scroll (jump immediately) to a given item index.

Public constructors

StackState

Added in 1.0.0-alpha01
public StackState(@IntRange(from = 0) int initialTopItem)
Parameters
@IntRange(from = 0) int initialTopItem

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

Public methods

animateScrollToItem

Added in 1.0.0-alpha01
public final void animateScrollToItem(
    int item,
    @NonNull AnimationSpec<@NonNull Float> animationSpec
)

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
int item

The index of the destination item

@NonNull AnimationSpec<@NonNull Float> animationSpec

An AnimationSpec to move between items

dispatchRawDelta

Added in 1.0.0-alpha01
public float dispatchRawDelta(float delta)

getCanScrollBackward

public boolean getCanScrollBackward()

getCanScrollForward

public boolean getCanScrollForward()

getInteractionSource

Added in 1.0.0-alpha01
public final @NonNull InteractionSource getInteractionSource()

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.

getLastScrolledBackward

public boolean getLastScrolledBackward()

getLastScrolledForward

public boolean getLastScrolledForward()

getTopItem

Added in 1.0.0-alpha01
public final int getTopItem()

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

getTopItemOffsetFraction

Added in 1.0.0-alpha01
@FrequentlyChangingValue
public final float getTopItemOffsetFraction()

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

isScrollInProgress

Added in 1.0.0-alpha01
public boolean isScrollInProgress()

scroll

Added in 1.0.0-alpha01
public void scroll(
    @NonNull MutatePriority scrollPriority,
    @NonNull SuspendFunction1<@NonNull ScrollScopeUnit> block
)

scrollToItem

Added in 1.0.0-alpha01
public final void scrollToItem(int item)

Scroll (jump immediately) to a given item index.

Parameters
int item

The index of the destination item