SwipeToDismissBoxState
-
Cmn
class SwipeToDismissBoxState
State of the SwipeToDismissBox composable.
Summary
Public companion functions |
||
|---|---|---|
Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue> |
The default |
Cmn
|
Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue> |
This function is deprecated. confirmValueChange is deprecated without replacement. |
Cmn
|
Public constructors |
|
|---|---|
SwipeToDismissBoxState(State of the |
Cmn
|
This function is deprecated. confirmValueChange is deprecated without replacement. |
Cmn
|
Public functions |
||
|---|---|---|
suspend Unit |
dismiss(direction: SwipeToDismissBoxValue)Dismiss the component in the given |
Cmn
|
Float |
Require the current offset. |
Cmn
|
suspend Unit |
reset()Reset the component to the default position with animation and suspend until it if fully reset or animation has been cancelled. |
Cmn
|
suspend Unit |
snapTo(targetValue: SwipeToDismissBoxValue)Set the state without any animation and suspend until it's set |
Cmn
|
Public properties |
||
|---|---|---|
SwipeToDismissBoxValue |
The current state value of the |
Cmn
|
SwipeToDismissBoxValue |
The direction (if any) in which the composable has been or is being dismissed. |
Cmn
|
Float |
The fraction of the progress going from currentValue to targetValue, within 0f..1f bounds. |
Cmn
|
SwipeToDismissBoxValue |
The value the |
Cmn
|
SwipeToDismissBoxValue |
The target state. |
Cmn
|
Public companion functions
Saver
fun Saver(positionalThreshold: (totalDistance: Float) -> Float): Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue>
The default Saver implementation for SwipeToDismissBoxState.
Saver
funSaver(
confirmValueChange: (SwipeToDismissBoxValue) -> Boolean,
positionalThreshold: (totalDistance: Float) -> Float,
density: Density
): Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue>
Saver implementation for SwipeToDismissBoxState.
Public constructors
SwipeToDismissBoxState
SwipeToDismissBoxState(
initialValue: SwipeToDismissBoxValue,
positionalThreshold: (totalDistance: Float) -> Float
)
State of the SwipeToDismissBox composable.
| Parameters | |
|---|---|
initialValue: SwipeToDismissBoxValue |
The initial value of the state. |
positionalThreshold: (totalDistance: Float) -> Float |
The positional threshold to be used when calculating the target state while a swipe is in progress and when settling after the swipe ends. This is the distance from the start of a transition. It will be, depending on the direction of the interaction, added or subtracted from/to the origin offset. It should always be a positive value. |
SwipeToDismissBoxState
SwipeToDismissBoxState(
initialValue: SwipeToDismissBoxValue,
density: Density,
confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true },
positionalThreshold: (totalDistance: Float) -> Float
)
State of the SwipeToDismissBox composable.
| Parameters | |
|---|---|
initialValue: SwipeToDismissBoxValue |
The initial value of the state. |
density: Density |
The density that this state can use to convert values to and from dp. |
confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true } |
Optional callback invoked to confirm or veto a pending state change. |
positionalThreshold: (totalDistance: Float) -> Float |
The positional threshold to be used when calculating the target state while a swipe is in progress and when settling after the swipe ends. This is the distance from the start of a transition. It will be, depending on the direction of the interaction, added or subtracted from/to the origin offset. It should always be a positive value. |
Public functions
dismiss
suspend fun dismiss(direction: SwipeToDismissBoxValue): Unit
Dismiss the component in the given direction, with an animation and suspend. This method will throw CancellationException if the animation is interrupted
| Parameters | |
|---|---|
direction: SwipeToDismissBoxValue |
The dismiss direction. |
requireOffset
fun requireOffset(): Float
Require the current offset.
| Throws | |
|---|---|
kotlin.IllegalStateException |
If the offset has not been initialized yet |
reset
suspend fun reset(): Unit
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 | |
|---|---|
Unit |
the reason the reset animation ended |
snapTo
suspend fun snapTo(targetValue: SwipeToDismissBoxValue): Unit
Set the state without any animation and suspend until it's set
| Parameters | |
|---|---|
targetValue: SwipeToDismissBoxValue |
The new target value |
Public properties
currentValue
val currentValue: SwipeToDismissBoxValue
The current state value of the SwipeToDismissBoxState.
dismissDirection
val dismissDirection: SwipeToDismissBoxValue
The direction (if any) in which the composable has been or is being dismissed.
Use this to change the background of the SwipeToDismissBox if you want different actions on each side.
progress
val progress: Float
The fraction of the progress going from currentValue to targetValue, within 0f..1f bounds.
settledValue
val settledValue: SwipeToDismissBoxValue
The value the SwipeToDismissBoxState is currently settled at. When progressing through multiple anchors, e.g. A -> B -> C, settledValue will stay the same until settled at an anchor, while currentValue will update to the closest anchor.
targetValue
val targetValue: SwipeToDismissBoxValue
The target state. This is the closest state to the current offset (taking into account positional thresholds). If no interactions like animations or drags are in progress, this will be the current state.