SwipeToDismissBoxState

class SwipeToDismissBoxState(initialValue: SwipeToDismissBoxValue, density: Density, confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true }, positionalThreshold: (totalDistance: Float) -> Float)

State of the SwipeToDismissBox composable.

Parameters

initialValue

The initial value of the state.

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.

positionalThreshold

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.

Constructors

Link copied to clipboard
constructor(initialValue: SwipeToDismissBoxValue, density: Density, confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true }, positionalThreshold: (totalDistance: Float) -> Float)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The current state value of the SwipeToDismissBoxState.

Link copied to clipboard

The direction (if any) in which the composable has been or is being dismissed.

Link copied to clipboard
@get:FloatRange(from = 0.0, to = 1.0)
val progress: Float

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

Link copied to clipboard

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.

Functions

Link copied to clipboard
suspend fun dismiss(direction: SwipeToDismissBoxValue)

Dismiss the component in the given direction, with an animation and suspend. This method will throw CancellationException if the animation is interrupted

Link copied to clipboard

Require the current offset.

Link copied to clipboard
suspend fun reset()

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

Link copied to clipboard
suspend fun snapTo(targetValue: SwipeToDismissBoxValue)

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