SwipeableState

Class

Android
@ExperimentalWearMaterialApi
public open class SwipeableState<T>(
    internal val initialValue: T,
    internal val animationSpec: AnimationSpec<Float> = SwipeableDefaults.AnimationSpec,
    internal val confirmStateChange: (newValue: T) -> Boolean = { true },
)

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.

Parameters

initialValueThe initial value of the state.
animationSpecThe default animation that will be used to animate to a new state.
confirmStateChangeOptional callback invoked to confirm or veto a pending state change. If the state change is accepted, the offset is optionally be reset to the initial value. and offset is reset.

Functions

@ExperimentalWearMaterialApi
    public suspend fun snapTo(targetValue: T)

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

Parameters

targetValueThe new target value to set currentValue to.
@ExperimentalWearMaterialApi
    public suspend fun animateTo(targetValue: T, anim: AnimationSpec<Float> = animationSpec)

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

Parameters

targetValueThe new value to animate to.
animThe animation that will be used to animate to the new value.
@ExperimentalWearMaterialApi
    public suspend fun performFling(velocity: Float)

Perform fling with settling to one of the anchors which is determined by the given velocity. Fling with settling swipeable will always consume all the velocity provided since it will settle at the anchor.

In general cases, swipeable flings by itself when being swiped. This method is to be used for nested scroll logic that wraps the swipeable. In nested scroll developer may want to trigger settling fling when the child scroll container reaches the bound.

Parameters

velocityvelocity to fling and settle with

Returns

the reason fling ended

Companion Object

Methods

Android
public fun <T : Any> Saver(
            animationSpec: AnimationSpec<Float>,
            confirmStateChange: (T) -> Boolean,
        ): Saver<SwipeableState<T>, T>

The default Saver implementation for SwipeableState.