SwipeToDismissBoxState


State of the SwipeToDismissBox composable.

Summary

Public companion functions

Saver<SwipeToDismissBoxStateSwipeToDismissBoxValue>
Saver(
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean,
    positionalThreshold: (totalDistance: Float) -> Float,
    density: Density
)

The default Saver implementation for SwipeToDismissBoxState.

Cmn

Public constructors

SwipeToDismissBoxState(
    initialValue: SwipeToDismissBoxValue,
    density: Density,
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean,
    positionalThreshold: (totalDistance: Float) -> Float
)
Cmn

Public functions

suspend Unit

Dismiss the component in the given direction, with an animation and suspend.

Cmn
Float

Require the current offset.

Cmn
suspend Unit

Reset the component to the default position with animation and suspend until it if fully reset or animation has been cancelled.

Cmn
suspend Unit

Set the state without any animation and suspend until it's set

Cmn

Public properties

SwipeToDismissBoxValue

The current state value of the SwipeToDismissBoxState.

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 target state.

Cmn

Public companion functions

Saver

fun Saver(
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean,
    positionalThreshold: (totalDistance: Float) -> Float,
    density: Density
): Saver<SwipeToDismissBoxStateSwipeToDismissBoxValue>

The default Saver implementation for SwipeToDismissBoxState.

Public constructors

SwipeToDismissBoxState

SwipeToDismissBoxState(
    initialValue: SwipeToDismissBoxValue,
    density: Density,
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true },
    positionalThreshold: (totalDistance: Float) -> Float
)
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 currentValueSwipeToDismissBoxValue

The current state value of the SwipeToDismissBoxState.

dismissDirection

val dismissDirectionSwipeToDismissBoxValue

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 progressFloat

The fraction of the progress going from currentValue to targetValue, within 0f..1f bounds.

targetValue

val targetValueSwipeToDismissBoxValue

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.