public open class SwipeableState<T>(
initialValue: T,
internal val animationSpec: AnimationSpec<Float> = AnimationSpec,
internal val confirmStateChange: (newValue: T) -> Boolean = { true },
)
Properties
currentValue
public var currentValue: T by mutableStateOf(initialValue)
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
public var isAnimationRunning: Boolean by mutableStateOf(false)
Whether the state is currently animating.
offset
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
public val overflow: State<Float>
The amount by which the swipeable has been swiped past its bounds.
targetValue
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
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
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
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
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
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 |
Return
the reason fling ended
performDrag
public fun performDrag(delta: Float): Float
Force swipeable to consume drag delta provided from outside of the regular swipeable gesture flow.
Note: This method performs generic drag and it won't settle to any particular anchor, * leaving swipeable in between anchors. When done dragging, performFling must be called as well to ensure swipeable will settle at the anchor.
In general cases, swipeable drags 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 force drag when the child scroll container reaches the bound.
Parameters
| delta | delta in pixels to drag by |
Return
the amount of delta consumed
Members
Companion
public companion object
Functions
Saver
public fun <T : Any> Saver(
animationSpec: AnimationSpec<Float>,
confirmStateChange: (T) -> Boolean,
): Saver<SwipeableState<T>, T>
The default Saver implementation for SwipeableState.