# StackState

Artifact: [androidx.xr.glimmer:glimmer](https://developer.android.com/jetpack/androidx/releases/xr-glimmer) [View Source](https://cs.android.com/search?q=file:androidx/xr/glimmer/stack/StackState.kt+class:androidx.xr.glimmer.stack.StackState) Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)


```
class StackState : ScrollableState
```

<br />

*** ** * ** ***

The `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` state that allows programmatic control and observation of the stack's state.

A `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` object can be created and remembered using `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/rememberStackState.composable#rememberStackState(kotlin.Int)`.

Note: Properties of the state will only be correctly populated after the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` it is associated with has been composed for the first time.

Warning: A single `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState` instance must not be shared across multiple `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` composables.

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/rememberStackState.composable#rememberStackState(kotlin.Int)` |   |
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/VerticalStack.composable#VerticalStack(androidx.compose.ui.Modifier,androidx.xr.glimmer.stack.StackState,kotlin.Function1)` |   |

## Summary

| ### Public companion properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState, *>` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#Saver()` The default `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState`. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#StackState(kotlin.Int)(initialTopItem: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` |

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.AnimationSpec)(item: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` Scroll animate to a given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.AnimationSpec)`'s closest snap position. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#dispatchRawDelta(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` |
| `open suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#scroll(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction1)(scrollPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#scrollToItem(kotlin.Int)(item: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Scroll (jump immediately) to a given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#scrollToItem(kotlin.Int)` index. |

| ### Public properties |
|---|---|
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#canScrollBackward()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#canScrollForward()` |
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#interactionSource()` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/InteractionSource` that's used to dispatch drag events when this stack is being dragged. |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#isScrollInProgress()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#lastScrolledBackward()` |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#lastScrolledForward()` |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#topItem()` The index of the item that's currently at the top of the stack, defaults to 0. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#topItemOffsetFraction()` The offset of the top item as a fraction of the stack item container size. |

### Inherited properties

From [androidx.compose.foundation.gestures.ScrollableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState) `open https://developer.android.com/reference/kotlin/androidx/compose/foundation/ScrollIndicatorState?` `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/ScrollableState#scrollIndicatorState()`

## Public companion properties

### Saver

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val Saver: Saver<StackState, *>
```

The default `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState`.

## Public constructors

### StackState

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

| Parameters |
|---|---|
| `initialTopItem: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = 0) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html = 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-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
suspend fun animateScrollToItem(
    item: Int,
    animationSpec: AnimationSpec<Float> = spring()
): Unit
```

Scroll animate to a given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.AnimationSpec)`'s closest snap position. If the `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.AnimationSpec)` is too far away from `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#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 `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#animateScrollToItem(kotlin.Int,androidx.compose.animation.core.AnimationSpec)`.

| Parameters |
|---|---|
| `item: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the destination item |
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = spring()` | An `https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec` to move between items |

### dispatchRawDelta

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
open fun dispatchRawDelta(delta: Float): Float
```

### scroll

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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

### scrollToItem

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
suspend fun scrollToItem(item: Int): Unit
```

Scroll (jump immediately) to a given `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#scrollToItem(kotlin.Int)` index.

| Parameters |
|---|---|
| `item: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The index of the destination item |

## Public properties

### canScrollBackward

```
open val canScrollBackward: Boolean
```

### canScrollForward

```
open val canScrollForward: Boolean
```

### interactionSource

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val interactionSource: InteractionSource
```

`https://developer.android.com/reference/kotlin/androidx/compose/foundation/interaction/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 `https://developer.android.com/reference/kotlin/androidx/xr/glimmer/stack/StackState#isScrollInProgress()`.

### isScrollInProgress

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
open val isScrollInProgress: Boolean
```

### lastScrolledBackward

```
open val lastScrolledBackward: Boolean
```

### lastScrolledForward

```
open val lastScrolledForward: Boolean
```

### topItem

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

```
val topItem: Int
```

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

### topItemOffsetFraction

Added in [1.0.0-alpha22](https://developer.android.com/jetpack/androidx/releases/xr-glimmer#1.0.0-alpha22)

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