BottomDrawerState
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
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.
val offset: Float
The current offset in pixels, or Float.NaN if it has not been initialized yet.
val currentValue: BottomDrawerValue
The current value of the BottomDrawerState.
val isOpen: Boolean
Whether the drawer is open, either in opened or expanded state.
val isClosed: Boolean
Whether the drawer is closed.
val isExpanded: Boolean
Whether the drawer is expanded.
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
| from | The starting value used to calculate the distance |
| to | The 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
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.
