Class

SwipeableState

State of the swipeable modifier.

Source set: 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

initialValue The initial value of the state.
animationSpec The default animation that will be used to animate to a new state.
confirmStateChange Optional 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.

Properties

currentValue

Source set: Android
@ExperimentalWearMaterialApi
public var currentValue: T

The current value of the state.

If no swipe or animation is in progress, this corresponds to the anchor at which the swipeable is currently settled. If a swipe or animation is in progress, this corresponds the last anchor at which the swipeable was settled before the swipe or animation started.

isAnimationRunning

Source set: Android
@ExperimentalWearMaterialApi
public var isAnimationRunning: Boolean

Whether the state is currently animating.

offset

Source set: Android
@ExperimentalWearMaterialApi
public val offset: State<Float>

The current position (in pixels) of the swipeable.

You should use this state to offset your content accordingly. The recommended way is to use Modifier.offsetPx. This includes the resistance by default, if resistance is enabled.

overflow

Source set: Android
@ExperimentalWearMaterialApi
public val overflow: State<Float>

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

targetValue

Source set: Android
@ExperimentalWearMaterialApi
public val targetValue: T

The target value of the state.

If a swipe is in progress, this is the value that the swipeable would animate to if the swipe finished. If an animation is running, this is the target value of that animation. Finally, if no swipe or animation is in progress, this is the same as the currentValue.

progress

Source set: Android
@ExperimentalWearMaterialApi
public val progress: SwipeProgress<T>

Information about the ongoing swipe or animation, if any. See SwipeProgress for details.

If no swipe or animation is in progress, this returns SwipeProgress(value, value, 1f).

direction

Source set: Android
@ExperimentalWearMaterialApi
public val direction: Float

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

This will be either 1f if it is is moving from left to right or top to bottom, -1f if it is moving from right to left or bottom to top, or 0f if no swipe or animation is in progress.

Functions

snapTo

@ExperimentalWearMaterialApi
public suspend fun snapTo(targetValue: T)

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

Parameters

targetValue The new target value to set currentValue to.

animateTo

@ExperimentalWearMaterialApi
public suspend fun animateTo(targetValue: T, anim: AnimationSpec<Float> = animationSpec)

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

Parameters

targetValue The new value to animate to.
anim The animation that will be used to animate to the new value.

performFling

@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

velocity velocity to fling and settle with

Returns

the reason fling ended

Companion Object

Methods

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

The default Saver implementation for SwipeableState.

Last updated: