SwipeButtonState

class SwipeButtonState(val confirmThreshold: Float = 0.9f, onComplete: () -> Unit = {}, onReset: () -> Unit = {}, onProgressChanged: (Float) -> Unit = {})

In accordance with the Compose state management pattern, this class encapsulates the physical interaction logic (dragging, progress, and thresholds) while remaining agnostic of the visual styling.

Parameters

confirmThreshold

The normalized value (0.0 to 1.0) that the user must drag beyond to trigger the completion state. Defaults to 0.9 (90%).

onComplete

Callback invoked when the button successfully reaches the completed state.

onReset

Callback invoked when the button is reset from completed to idle.

onProgressChanged

Callback providing real-time updates of the drag progress (0.0 to 1.0).

Constructors

Link copied to clipboard
constructor(confirmThreshold: Float = 0.9f, onComplete: () -> Unit = {}, onReset: () -> Unit = {}, onProgressChanged: (Float) -> Unit = {})

Properties

Link copied to clipboard
Link copied to clipboard

Whether the swipe action has been successfully completed. When true, the button typically transforms into a loading or success indicator.

Link copied to clipboard

Indicates whether the user is currently interacting with the slider.

Link copied to clipboard

The internal animatable progress of the swipe (0f = start, 1f = end).

Functions

Link copied to clipboard
suspend fun animateToRest(animationSpec: AnimationSpec<Float> = spring(stiffness = Spring.StiffnessLow))

Animates the slider back to the start position. Usually called when the user releases the drag before reaching the confirmThreshold.

Link copied to clipboard
suspend fun complete(animationSpec: AnimationSpec<Float> = tween(300))

Transitions the state to completed and animates the progress to 100%.

Link copied to clipboard
suspend fun forceComplete()

Immediately sets the state to completed without playing an animation.

Link copied to clipboard
suspend fun forceReset()

Immediately resets the state to idle without playing an animation.

Link copied to clipboard
suspend fun reset(animationSpec: AnimationSpec<Float> = tween(300))

Resets the button to its initial idle state with an animation.

Link copied to clipboard
suspend fun updateProgress(value: Float)

Updates the current swipe progress instantly.