Start native apps faster with the Composables CLI ->
Class

ScrollFieldState

A state object that can be hoisted to observe and control the scrolling behavior of a ScrollField.

Source set: Common
class ScrollFieldState(internal val pagerState: PagerState, val itemCount: Int)

A state object that can be hoisted to observe and control the scrolling behavior of a ScrollField.

In most cases, this state should be created via rememberScrollFieldState.

Parameters

pagerState the underlying PagerState used to handle the scroll logic.
itemCount the total number of unique items available in the scroll field.

Properties

selectedOption

Source set: Common
var selectedOption: Int

The index of the currently selected option.

This value is always clamped between 0 and 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

Source set: Common
val targetOption: Int

The option the pager will settle on once any in-progress scroll finishes. Equal to selectedOption when the pager is at rest.

isScrollInProgress

Source set: Common
val isScrollInProgress: Boolean

Whether this ScrollField is currently scrolling, either by user gesture or by animation.

Functions

scrollToOption

suspend fun scrollToOption(option: Int)

Instantly scrolls to the specified option.

Parameters

option the index of the item to scroll to.

animateScrollToOption

suspend fun animateScrollToOption(option: Int)

Animates the scroll to the specified option.

Parameters

option the index of the item to animate to.

Last updated: