SwipeableV2State

class SwipeableV2State<T>(initialValue: T, animationSpec: <Error class: unknown class><Float> = SwipeableV2Defaults.AnimationSpec, confirmValueChange: (newValue: T) -> Boolean = { true }, positionalThreshold: <Error class: unknown class>.(totalDistance: Float) -> Float = SwipeableV2Defaults.PositionalThreshold, velocityThreshold: <Error class: unknown class> = SwipeableV2Defaults.VelocityThreshold)

State of the swipeableV2 modifier.

This contains necessary information about any ongoing swipe or animation and provides methods to change the state either immediately or by starting an animation. To create and remember a SwipeableV2State use rememberSwipeableV2State.

Parameters

initialValue

The initial value of the state.

animationSpec

The default animation that will be used to animate to a new state.

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. See the fractionalPositionalThreshold and fixedPositionalThreshold methods.

velocityThreshold

The velocity threshold (in dp per second) that the end velocity has to exceed in order to animate to the next state, even if the positionalThreshold has not been reached.

Constructors

Link copied to clipboard
constructor(initialValue: T, animationSpec: <Error class: unknown class><Float> = SwipeableV2Defaults.AnimationSpec, confirmValueChange: (newValue: T) -> Boolean = { true }, positionalThreshold: <Error class: unknown class>.(totalDistance: Float) -> Float = SwipeableV2Defaults.PositionalThreshold, velocityThreshold: <Error class: unknown class> = SwipeableV2Defaults.VelocityThreshold)

Types

Link copied to clipboard
object Companion

Properties

Link copied to clipboard

The current value of the SwipeableV2State.

Link copied to clipboard

Whether an animation is currently in progress.

Link copied to clipboard

The velocity of the last known animation. Gets reset to 0f when an animation completes successfully, but does not get reset when an animation gets interrupted. You can use this value to provide smooth reconciliation behavior when re-targeting an animation.

Link copied to clipboard
val maxOffset: <Error class: unknown class>

The maximum offset this state can reach. This will be the biggest anchor, or Float.POSITIVE_INFINITY if the anchors are not initialized yet.

Link copied to clipboard
val minOffset: <Error class: unknown class>

The minimum offset this state can reach. This will be the smallest anchor, or Float.NEGATIVE_INFINITY if the anchors are not initialized yet.

Link copied to clipboard

The current offset, or null if it has not been initialized yet.

Link copied to clipboard

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

Link copied to clipboard

The target value. This is the closest value to the current offset (taking into account positional thresholds). If no interactions like animations or drags are in progress, this will be the current value.

Functions

Link copied to clipboard
suspend fun animateTo(targetValue: T, velocity: Float = lastVelocity)

Animate to a targetValue. If the targetValue is not in the set of anchors, the currentValue will be updated to the targetValue without updating the offset.

Link copied to clipboard

Swipe by the delta, coerce it in the bounds and dispatch it to the draggableState.

Link copied to clipboard

Whether the value has an anchor associated with it.

Link copied to clipboard

Require the current offset.

Link copied to clipboard
suspend fun settle(velocity: Float)

Find the closest anchor taking into account the velocity and settle at it with an animation.

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

Snap to a targetValue without any animation. If the targetValue is not in the set of anchors, the currentValue will be updated to the targetValue without updating the offset.