SwipeableState
@ExperimentalWearMaterialApi
open class SwipeableState<T : Any?>
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 companion functions |
|
|---|---|
Saver<SwipeableState<T>, T> |
<T : Any> Saver(The default |
Public constructors |
|---|
<T : Any?> SwipeableState( |
Public functions |
|
|---|---|
suspend Unit |
@ExperimentalWearMaterialApiSet the state to the target value by starting an animation. |
suspend Unit |
@ExperimentalWearMaterialApiPerform fling with settling to one of the anchors which is determined by the given |
suspend Unit |
@ExperimentalWearMaterialApiSet the state without any animation and suspend until it's set |
Public properties |
|
|---|---|
T |
The current value of the state. |
Float |
The direction in which the |
Boolean |
Whether the state is currently animating. |
State<Float> |
The current position (in pixels) of the |
State<Float> |
The amount by which the |
SwipeProgress<T> |
Information about the ongoing swipe or animation, if any. |
T |
The target value of the state. |
Public companion functions
Saver
fun <T : Any> Saver(
animationSpec: AnimationSpec<Float>,
confirmStateChange: (T) -> Boolean
): Saver<SwipeableState<T>, T>
The default Saver implementation for SwipeableState.
Public constructors
SwipeableState
<T : Any?> SwipeableState(
initialValue: T,
animationSpec: AnimationSpec<Float> = SwipeableDefaults.AnimationSpec,
confirmStateChange: (newValue) -> Boolean = { true }
)
| Parameters | |
|---|---|
initialValue: T |
The initial value of the state. |
animationSpec: AnimationSpec<Float> = SwipeableDefaults.AnimationSpec |
The default animation that will be used to animate to a new state. |
confirmStateChange: (newValue) -> Boolean = { true } |
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. |
Public functions
animateTo
@ExperimentalWearMaterialApi
suspend fun animateTo(targetValue: T, anim: AnimationSpec<Float> = animationSpec): Unit
Set the state to the target value by starting an animation.
| Parameters | |
|---|---|
targetValue: T |
The new value to animate to. |
anim: AnimationSpec<Float> = animationSpec |
The animation that will be used to animate to the new value. |
performFling
@ExperimentalWearMaterialApi
suspend fun performFling(velocity: Float): Unit
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: Float |
velocity to fling and settle with |
| Returns | |
|---|---|
Unit |
the reason fling ended |
snapTo
@ExperimentalWearMaterialApi
suspend fun snapTo(targetValue: T): Unit
Set the state without any animation and suspend until it's set
| Parameters | |
|---|---|
targetValue: T |
The new target value to set |
Public properties
currentValue
@ExperimentalWearMaterialApi
val 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.
direction
@ExperimentalWearMaterialApi
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.
isAnimationRunning
@ExperimentalWearMaterialApi
val isAnimationRunning: Boolean
Whether the state is currently animating.
offset
@ExperimentalWearMaterialApi
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
@ExperimentalWearMaterialApi
val overflow: State<Float>
The amount by which the swipeable has been swiped past its bounds.
progress
@ExperimentalWearMaterialApi
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).
targetValue
@ExperimentalWearMaterialApi
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.