BottomSheetState


State of the persistent bottom sheet in BottomSheetScaffold.

Summary

Public companion functions

Saver<BottomSheetState, *>
Saver(
    animationSpec: AnimationSpec<Float>,
    confirmStateChange: (BottomSheetValue) -> Boolean,
    density: Density
)

The default Saver implementation for BottomSheetState.

Cmn

Public constructors

BottomSheetState(
    initialValue: BottomSheetValue,
    density: Density,
    animationSpec: AnimationSpec<Float>,
    confirmValueChange: (BottomSheetValue) -> Boolean
)
Cmn

Public functions

suspend Unit

Collapse the bottom sheet with animation and suspend until it if fully collapsed or animation has been cancelled.

Cmn
suspend Unit

Expand the bottom sheet with an animation and suspend until the animation finishes or is cancelled.

Cmn
@FloatRange(from = 0.0, to = 1.0) Float

The fraction of the offset between from and to, as a fraction between 0f..1f, or 1f if from is equal to to.

Cmn
Float

Require the current offset.

Cmn

Public properties

BottomSheetValue

The current value of the BottomSheetState.

Cmn
Boolean

Whether the bottom sheet is collapsed.

Cmn
Boolean

Whether the bottom sheet is expanded.

Cmn
Float

This property is deprecated. Please use the progress function to query progress explicitly between targets.

Cmn
BottomSheetValue

The target value the state will settle at once the current interaction ends, or the currentValue if there is no interaction in progress.

Cmn

Public companion functions

Saver

fun Saver(
    animationSpec: AnimationSpec<Float>,
    confirmStateChange: (BottomSheetValue) -> Boolean,
    density: Density
): Saver<BottomSheetState, *>

The default Saver implementation for BottomSheetState.

Public constructors

BottomSheetState

BottomSheetState(
    initialValue: BottomSheetValue,
    density: Density,
    animationSpec: AnimationSpec<Float> = BottomSheetScaffoldDefaults.AnimationSpec,
    confirmValueChange: (BottomSheetValue) -> Boolean = { true }
)
Parameters
initialValue: BottomSheetValue

The initial value of the state.

density: Density

The density that this state can use to convert values to and from dp.

animationSpec: AnimationSpec<Float> = BottomSheetScaffoldDefaults.AnimationSpec

The default animation that will be used to animate to a new state.

confirmValueChange: (BottomSheetValue) -> Boolean = { true }

Optional callback invoked to confirm or veto a pending state change.

Public functions

collapse

suspend fun collapse(): Unit

Collapse the bottom sheet with animation and suspend until it if fully collapsed or animation has been cancelled. This method will throw CancellationException if the animation is interrupted.

expand

suspend fun expand(): Unit

Expand the bottom sheet with an animation and suspend until the animation finishes or is cancelled. Note: If the peek height is equal to the sheet height, this method will animate to the Collapsed state.

This method will throw CancellationException if the animation is interrupted.

progress

fun progress(from: BottomSheetValue, to: BottomSheetValue): @FloatRange(from = 0.0, to = 1.0) Float

The fraction of the offset between from and to, as a fraction between 0f..1f, or 1f if from is equal to to.

Parameters
from: BottomSheetValue

The starting value used to calculate the distance

to: BottomSheetValue

The end value used to calculate the distance

requireOffset

fun requireOffset(): Float

Require the current offset.

Throws
kotlin.IllegalStateException

If the offset has not been initialized yet

Public properties

currentValue

val currentValueBottomSheetValue

The current value of the BottomSheetState.

isCollapsed

val isCollapsedBoolean

Whether the bottom sheet is collapsed.

isExpanded

val isExpandedBoolean

Whether the bottom sheet is expanded.

progress

@ExperimentalMaterialApi
val progressFloat

The fraction of the progress, within 0f..1f bounds, or 1f if the AnchoredDraggableState is in a settled state.

targetValue

val targetValueBottomSheetValue

The target value the state will settle at once the current interaction ends, or the currentValue if there is no interaction in progress.