BottomSheetState

Class

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

State of the persistent bottom sheet in BottomSheetScaffold.

Parameters

initialValueThe initial value of the state.
densityThe density that this state can use to convert values to and from dp.
animationSpecThe default animation that will be used to animate to a new state.
confirmValueChangeOptional callback invoked to confirm or veto a pending state change.

Properties

Common
val currentValue: BottomSheetValue

The current value of the BottomSheetState.

Common
val targetValue: BottomSheetValue

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

Common
val isExpanded: Boolean

Whether the bottom sheet is expanded.

Common
val isCollapsed: Boolean

Whether the bottom sheet is collapsed.

Common

Deprecated Please use the progress function to query progress explicitly between targets.

@get:FloatRange(from = 0.0, to = 1.0)
@ExperimentalMaterialApi
val progress: Float

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

Functions

@FloatRange(from = 0.0, to = 1.0)
    fun progress(from: BottomSheetValue, to: BottomSheetValue): 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

fromThe starting value used to calculate the distance
toThe end value used to calculate the distance
suspend fun expand()

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.

suspend fun collapse() = anchoredDraggableState.animateTo(Collapsed)

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.

fun requireOffset() = anchoredDraggableState.requireOffset()

Require the current offset.

Companion Object

Methods

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

The default Saver implementation for BottomSheetState.