Class

ModalBottomSheetState

State of the ModalBottomSheetLayout composable.

Source set: Common
class ModalBottomSheetState(
initialValue: ModalBottomSheetValue,
density: Density,
confirmValueChange: (ModalBottomSheetValue) -> Boolean = { true },
internal val animationSpec: AnimationSpec<Float> = ModalBottomSheetDefaults.AnimationSpec,
internal val isSkipHalfExpanded: Boolean = false,
)

State of the ModalBottomSheetLayout composable.

Parameters

initialValue The initial value of the state. Must not be set to ModalBottomSheetValue.HalfExpanded if isSkipHalfExpanded is set to true.
density The density that this state can use to convert values to and from dp.
confirmValueChange Optional callback invoked to confirm or veto a pending state change.
animationSpec The default animation that will be used to animate to a new state.
isSkipHalfExpanded Whether the half expanded state, if the sheet is tall enough, should be skipped. If true, the sheet will always expand to the Expanded state and move to the Hidden state when hiding the sheet, either programmatically or by user interaction. Must not be set to true if the initialValue is ModalBottomSheetValue.HalfExpanded. If supplied with ModalBottomSheetValue.HalfExpanded for the initialValue, an IllegalArgumentException will be thrown.

Properties

currentValue

Source set: Common
val currentValue: ModalBottomSheetValue

The current value of the ModalBottomSheetState.

targetValue

Source set: Common
val targetValue: ModalBottomSheetValue

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

progress

Deprecated

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

Source set: Common
@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.

isVisible

Source set: Common
val isVisible: Boolean

Whether the bottom sheet is visible.

Functions

progress

@FloatRange(from = 0.0, to = 1.0)
    fun progress(from: ModalBottomSheetValue, to: ModalBottomSheetValue): 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 The starting value used to calculate the distance
to The end value used to calculate the distance

show

suspend fun show()

Show the bottom sheet with animation and suspend until it's shown. If the sheet is taller than 50% of the parent's height, the bottom sheet will be half expanded. Otherwise it will be fully expanded.

hide

suspend fun hide() = animateTo(Hidden)

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

Companion Object

Methods

Source set: Common
fun Saver(
            animationSpec: AnimationSpec<Float>,
            confirmValueChange: (ModalBottomSheetValue) -> Boolean,
            skipHalfExpanded: Boolean,
            density: Density,
        ): Saver<ModalBottomSheetState, *>

The default Saver implementation for ModalBottomSheetState. Saves the currentValue and recreates a ModalBottomSheetState with the saved value as initial value.

Last updated: