ModalBottomSheetState
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
val currentValue: ModalBottomSheetValue
The current value of the ModalBottomSheetState
.
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.
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.
val isVisible: Boolean
Whether the bottom sheet is visible.
Functions
@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 |
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.
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
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.