BottomSheetState
class BottomSheetState(
initialValue: BottomSheetValue,
density: Density,
animationSpec: AnimationSpec<Float> = BottomSheetScaffoldDefaults.AnimationSpec,
confirmValueChange: (BottomSheetValue) -> Boolean = { true },
)
State of the persistent bottom sheet in BottomSheetScaffold
.
Parameters
initialValue | The initial value of the state. |
density | The density that this state can use to convert values to and from dp. |
animationSpec | The default animation that will be used to animate to a new state. |
confirmValueChange | Optional callback invoked to confirm or veto a pending state change. |
Properties
val currentValue: BottomSheetValue
The current value of the BottomSheetState
.
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.
val isExpanded: Boolean
Whether the bottom sheet is expanded.
val isCollapsed: Boolean
Whether the bottom sheet is collapsed.
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
from | The starting value used to calculate the distance |
to | The 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
fun Saver(
animationSpec: AnimationSpec<Float>,
confirmStateChange: (BottomSheetValue) -> Boolean,
density: Density,
): Saver<BottomSheetState, *>
The default Saver
implementation for BottomSheetState
.