DismissState
@ExperimentalMaterialApi
class DismissState(
initialValue: DismissValue,
confirmStateChange: (DismissValue) -> Boolean = { true },
) : SwipeableState<DismissValue>(initialValue, confirmStateChange = confirmStateChange)
State of the SwipeToDismiss
composable.
Parameters
initialValue | The initial value of the state. |
confirmStateChange | Optional callback invoked to confirm or veto a pending state change. |
Properties
val dismissDirection: DismissDirection?
The direction (if any) in which the composable has been or is being dismissed.
If the composable is settled at the default state, then this will be null. Use this to change
the background of the SwipeToDismiss
if you want different actions on each side.
Functions
fun isDismissed(direction: DismissDirection): Boolean
Whether the component has been dismissed in the given direction
.
Parameters
direction | The dismiss direction. |
suspend fun reset() = animateTo(targetValue = Default)
Reset the component to the default position with animation and suspend until it if fully
reset or animation has been cancelled. This method will throw CancellationException
if the
animation is interrupted
Returns
the reason the reset animation ended |
suspend fun dismiss(direction: DismissDirection)
Dismiss the component in the given direction
, with an animation and suspend. This method
will throw CancellationException
if the animation is interrupted
Parameters
direction | The dismiss direction. |
Companion Object
Methods
fun Saver(confirmStateChange: (DismissValue) -> Boolean) =
Saver<DismissState, DismissValue>(
save = { it.currentValue },
restore = { DismissState(it, confirmStateChange) },
)
The default Saver
implementation for DismissState
.