BottomDrawerState

Class

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

State of the BottomDrawer composable.

Parameters

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

Properties

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.

Common
val offset: Float

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

Common
val currentValue: BottomDrawerValue

The current value of the BottomDrawerState.

Common
val isOpen: Boolean

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

Common
val isClosed: Boolean

Whether the drawer is closed.

Common
val isExpanded: Boolean

Whether the drawer is expanded.

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: 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

fromThe starting value used to calculate the distance
toThe end value used to calculate the distance
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.

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

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

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

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.