# ScrollFieldState

Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/ScrollField.kt+class:androidx.compose.material3.ScrollFieldState) Common/AllAndroid/JVM
- Cmn

  ```
  class ScrollFieldState
  ```

*** ** * ** ***

A state object that can be hoisted to observe and control the scrolling behavior of a `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollField.composable#ScrollField(androidx.compose.material3.ScrollFieldState,kotlin.String,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.ScrollFieldColors,kotlin.Function1,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function3)`.

In most cases, this state should be created via `https://developer.android.com/reference/kotlin/androidx/compose/material3/rememberScrollFieldState.composable#rememberScrollFieldState(kotlin.Int,kotlin.Int)`.

## Summary

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#ScrollFieldState(androidx.compose.foundation.pager.PagerState,kotlin.Int)(pagerState: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState, itemCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` | Cmn |

| ### Public functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#animateScrollToOption(kotlin.Int)(option: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Animates the scroll to the specified `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#animateScrollToOption(kotlin.Int)`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#scrollToOption(kotlin.Int)(option: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Instantly scrolls to the specified `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#scrollToOption(kotlin.Int)`. | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#isScrollInProgress()` Whether this `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollField.composable#ScrollField(androidx.compose.material3.ScrollFieldState,kotlin.String,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.ScrollFieldColors,kotlin.Function1,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function3)` is currently scrolling, either by user gesture or by animation. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#itemCount()` the total number of unique items available in the scroll field. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#selectedOption()` The index of the currently selected option. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#targetOption()` The option the pager will settle on once any in-progress scroll finishes. | Cmn |

## Public constructors

### ScrollFieldState

Cmn

```
ScrollFieldState(pagerState: PagerState, itemCount: Int)
```

| Parameters |
|---|---|
| `pagerState: https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` | the underlying `https://developer.android.com/reference/kotlin/androidx/compose/foundation/pager/PagerState` used to handle the scroll logic. |
| `itemCount: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | the total number of unique items available in the scroll field. |

## Public functions

### animateScrollToOption

Cmn

```
suspend fun animateScrollToOption(option: Int): Unit
```

Animates the scroll to the specified `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#animateScrollToOption(kotlin.Int)`.

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#scrollToOption(kotlin.Int)` | for an instant scroll. |

### scrollToOption

Cmn

```
suspend fun scrollToOption(option: Int): Unit
```

Instantly scrolls to the specified `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#scrollToOption(kotlin.Int)`.

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

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#animateScrollToOption(kotlin.Int)` | for a smooth transition. |

## Public properties

### isScrollInProgress

Cmn

```
val isScrollInProgress: Boolean
```

Whether this `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollField.composable#ScrollField(androidx.compose.material3.ScrollFieldState,kotlin.String,androidx.compose.ui.Modifier,kotlin.Boolean,androidx.compose.material3.ScrollFieldColors,kotlin.Function1,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function3)` is currently scrolling, either by user gesture or by animation.

### itemCount

Cmn

```
val itemCount: Int
```

the total number of unique items available in the scroll field.

### selectedOption

Cmn

```
var selectedOption: Int
```

The index of the currently selected option.

This value is always clamped between 0 and `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#itemCount()` - 1. When the internal pager is scrolled, this value updates to reflect the item closest to the snap position.

Setting this value will instantly scroll to the specified option.

### targetOption

Cmn

```
val targetOption: Int
```

The option the pager will settle on once any in-progress scroll finishes. Equal to `https://developer.android.com/reference/kotlin/androidx/compose/material3/ScrollFieldState#selectedOption()` when the pager is at rest.