Class

BottomDrawerState

State of the BottomDrawer composable.

Source set: Common
class BottomDrawerState(
    initialValue: BottomDrawerValue,
    density: Density,
    confirmStateChange: (BottomDrawerValue) -> Boolean = { true },
    animationSpec: AnimationSpec<Float> = DrawerDefaults.AnimationSpec,
)

State of the BottomDrawer composable.

Parameters

initialValue The initial value of the state.
density The density that this state can use to convert values to and from dp.
confirmStateChange Optional callback invoked to confirm or veto a pending state change.
animationSpec The animation spec to be used for open/close animations, as well as settling when a user lets go.

Properties

targetValue

Source set: Common
val targetValue: BottomDrawerValue

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

offset

Source set: Common
val offset: Float

The current offset in pixels, or Float.NaN if it has not been initialized yet.

currentValue

Source set: Common
val currentValue: BottomDrawerValue

The current value of the BottomDrawerState.

isOpen

Source set: Common
val isOpen: Boolean

Whether the drawer is open, either in opened or expanded state.

isClosed

Source set: Common
val isClosed: Boolean

Whether the drawer is closed.

isExpanded

Source set: Common
val isExpanded: Boolean

Whether the drawer is expanded.

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.

Functions

progress

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

open

suspend fun open()

Open the drawer with animation and suspend until it if fully opened or animation has been cancelled. If the content height is less than BottomDrawerOpenFraction, the drawer state will move to BottomDrawerValue.Expanded instead.

close

suspend fun close() = anchoredDraggableState.animateTo(Closed)

Close the drawer with animation and suspend until it if fully closed or animation has been cancelled.

expand

suspend fun expand() = anchoredDraggableState.animateTo(Expanded)

Expand the drawer with animation and suspend until it if fully expanded or animation has been cancelled.

Companion Object

Methods

Source set: Common
fun Saver(
            density: Density,
            confirmStateChange: (BottomDrawerValue) -> Boolean,
            animationSpec: AnimationSpec<Float>,
        ) =
            Saver<BottomDrawerState, BottomDrawerValue>(
                save = { it.anchoredDraggableState.currentValue },
                restore = { BottomDrawerState(it, density, confirmStateChange, animationSpec) },
            )

The default Saver implementation for BottomDrawerState.

Last updated: