ButtonGroupState

sealed interface ButtonGroupState : ScrollableState


A state object that allows querying and controlling the state of a ButtonGroup component.

Summary

Public companion properties

Saver<ButtonGroupStateInt>

The default Saver implementation for ButtonGroupState.

Public functions

suspend Unit
animateScrollToItem(
    index: Int,
    animationSpec: FiniteAnimationSpec<Float>
)

Scroll to the item at index with the given animationSpec.

suspend Unit
scrollToItem(index: Int)

Jump instantly to the item at index.

Public properties

Int

Index of the current child.

Int

The number of items currently within the ButtonGroup.

Inherited functions

From androidx.compose.foundation.gestures.ScrollableState
Float
suspend Unit
scroll(scrollPriority: MutatePriority, block: suspend ScrollScope.() -> Unit)

Public companion properties

Saver

Added in 1.0.0-alpha16
val SaverSaver<ButtonGroupStateInt>

The default Saver implementation for ButtonGroupState.

Public functions

animateScrollToItem

Added in 1.0.0-alpha16
suspend fun animateScrollToItem(
    index: Int,
    animationSpec: FiniteAnimationSpec<Float> = ButtonGroupDefaults.AnimateScrollToItemAnimationSpec
): Unit

Scroll to the item at index with the given animationSpec.

If the ButtonGroup has focus, focus will be requested for the child at this index.

Throws
IllegalArgumentException

if index is not in [0, itemCount)

scrollToItem

Added in 1.0.0-alpha16
suspend fun scrollToItem(index: Int): Unit

Jump instantly to the item at index.

If the ButtonGroup has focus, focus will be requested for the child at this index.

Throws
IllegalArgumentException

if index is not in [0, itemCount)

Public properties

currentItemIndex

Added in 1.0.0-alpha16
val currentItemIndexInt

Index of the current child.

The index updates continuously as the user scrolls. To get updates only when the index is "settled", use the current item index when isScrollInProgress is false.

Returns -1 if the ButtonGroup is empty, or if the layout has not been initialized yet.

itemCount

Added in 1.0.0-alpha16
val itemCountInt

The number of items currently within the ButtonGroup.