# SwipeableState

Artifact: [androidx.wear.compose:compose-material](https://developer.android.com/jetpack/androidx/releases/wear-compose) [View Source](https://cs.android.com/search?q=file:androidx/wear/compose/material/Swipeable.kt+class:androidx.wear.compose.material.SwipeableState) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)


```
@ExperimentalWearMaterialApi
open class SwipeableState<T : Any?>
```

<br />

*** ** * ** ***

State of the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` 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 `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState` with the default animation clock, use `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/rememberSwipeableState.composable#rememberSwipeableState(kotlin.Any,androidx.compose.animation.core.AnimationSpec,kotlin.Function1)`.

## Summary

| ### Public companion functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState<T>, T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#Saver(androidx.compose.animation.core.AnimationSpec,kotlin.Function1)( animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, confirmStateChange: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` The default `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#Saver(androidx.compose.animation.core.AnimationSpec,kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState`. |

| ### Public constructors |
|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#SwipeableState(kotlin.Any,androidx.compose.animation.core.AnimationSpec,kotlin.Function1)( initialValue: T, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, confirmStateChange: (newValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` |

| ### Public functions |
|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)(targetValue: T, anim: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` Set the state to the target value by starting an animation. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#performFling(kotlin.Float)(velocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Perform fling with settling to one of the anchors which is determined by the given `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#performFling(kotlin.Float)`. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#snapTo(kotlin.Any)(targetValue: T)` Set the state without any animation and suspend until it's set |

| ### Public properties |
|---|---|
| `T` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#currentValue()` The current value of the state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#direction()` The direction in which the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` is moving, relative to the current `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#currentValue()`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#isAnimationRunning()` Whether the state is currently animating. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#offset()` The current position (in pixels) of the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)`. |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/State<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#overflow()` The amount by which the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` has been swiped past its bounds. |
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeProgress<T>` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#progress()` Information about the ongoing swipe or animation, if any. |
| `T` | `@https://developer.android.com/reference/kotlin/androidx/wear/compose/material/ExperimentalWearMaterialApi https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#targetValue()` The target value of the state. |

## Public companion functions

### Saver

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

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

The default `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#Saver(androidx.compose.animation.core.AnimationSpec,kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/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: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = SwipeableDefaults.AnimationSpec` | The default animation that will be used to animate to a new state. |
| `confirmStateChange: (newValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { 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

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@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: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = animationSpec` | The animation that will be used to animate to the new value. |

### performFling

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
suspend fun performFling(velocity: Float): Unit
```

Perform fling with settling to one of the anchors which is determined by the given `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#performFling(kotlin.Float)`. Fling with settling `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` will always consume all the velocity provided since it will settle at the anchor.

In general cases, `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` flings by itself when being swiped. This method is to be used for nested scroll logic that wraps the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)`. In nested scroll developer may want to trigger settling fling when the child scroll container reaches the bound.

| Parameters |
|---|---|
| `velocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | velocity to fling and settle with |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | the reason fling ended |

### snapTo

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@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 `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#currentValue()` to. |

## Public properties

### currentValue

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@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 `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` is currently settled. If a swipe or animation is in progress, this corresponds the last anchor at which the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` was settled before the swipe or animation started.

### direction

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
val direction: Float
```

The direction in which the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` is moving, relative to the current `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#currentValue()`.

This will be either 1f if it 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

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
val isAnimationRunning: Boolean
```

Whether the state is currently animating.

### offset

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
val offset: State<Float>
```

The current position (in pixels) of the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)`.

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

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
val overflow: State<Float>
```

The amount by which the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` has been swiped past its bounds.

### progress

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
val progress: SwipeProgress<T>
```

Information about the ongoing swipe or animation, if any. See `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeProgress` for details.

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

### targetValue

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/wear-compose#1.0.0)

```
@ExperimentalWearMaterialApi
val targetValue: T
```

The target value of the state.

If a swipe is in progress, this is the value that the `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/swipeable.modifier#(androidx.compose.ui.Modifier).swipeable(androidx.wear.compose.material.SwipeableState,kotlin.collections.Map,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,kotlin.Function2,androidx.wear.compose.material.ResistanceConfig,androidx.compose.ui.unit.Dp)` 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 `https://developer.android.com/reference/kotlin/androidx/wear/compose/material/SwipeableState#currentValue()`.