Android 12 Developer Preview is here! Try it out, and give us your feedback!

SwipeableState

@Stable open class SwipeableState<T>
kotlin.Any
   ↳ androidx.compose.material.SwipeableState

State of the swipeable 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 SwipeableState with the default animation clock, use rememberSwipeableState.

Summary

Public constructors
<init>(initialValue: T, animationSpec: AnimationSpec<Float> = AnimationSpec, confirmStateChange: (newValue: T) -> Boolean = { true })

State of the swipeable modifier.

Public methods
suspend Unit
animateTo(targetValue: T, anim: AnimationSpec<Float> = animationSpec)

Set the state to the target value by starting an animation.

Float

Force swipeable to consume drag delta provided from outside of the regular swipeable gesture flow.

suspend Unit
performFling(velocity: Float)

Perform fling with settling to one of the anchors which is determined by the given velocity.

suspend Unit
snapTo(targetValue: T)

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

Companion functions
Saver<SwipeableState<T>, T>
Saver(animationSpec: AnimationSpec<Float>, confirmStateChange: (T) -> Boolean)

The default Saver implementation for SwipeableState.

Properties
T

The current value of the state.

Float

The direction in which the swipeable is moving, relative to the current currentValue.

Boolean

Whether the state is currently animating.

State<Float>

The current position (in pixels) of the swipeable.

State<Float>

The amount by which the swipeable has been swiped past its bounds.

SwipeProgress<T>

Information about the ongoing swipe or animation, if any.

T

The target value of the state.

Public constructors

<init>