# SwipeToDismissBoxState

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


```
class SwipeToDismissBoxState
```

<br />

*** ** * ** ***

State for `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/BasicSwipeToDismissBox.composable#BasicSwipeToDismissBox(androidx.wear.compose.foundation.SwipeToDismissBoxState,androidx.compose.ui.Modifier,kotlin.Any,kotlin.Any,kotlin.Boolean,kotlin.Function2)`.

## Summary

| ### Public constructors |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/RememberInComposition https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#SwipeToDismissBoxState(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: (https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/annotation/FrequentlyChangingValue https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#requireOffset()()` Require the current offset. |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#snapTo(androidx.wear.compose.foundation.SwipeToDismissValue)(targetValue: https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue)` Set the state without any animation and suspend until it's set |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#currentValue()` The current value of the state. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#isAnimationRunning()` Whether the state is currently animating. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#offset()` The current offset, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if it has not been initialized yet. |
| `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue` | `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#targetValue()` The target value of the state. |

## Public constructors

### SwipeToDismissBoxState

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

```
@RememberInComposition
SwipeToDismissBoxState(
    animationSpec: AnimationSpec<Float> = SwipeToDismissBoxDefaults.AnimationSpec,
    confirmStateChange: (SwipeToDismissValue) -> Boolean = { true }
)
```

| Parameters |
|---|---|
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = SwipeToDismissBoxDefaults.AnimationSpec` | The default animation that will be used to animate to a new state. |
| `confirmStateChange: (https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { true }` | callback invoked to confirm or veto a pending state change. |

## Public functions

### requireOffset

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

```
@FrequentlyChangingValue
fun requireOffset(): Float
```

Require the current offset. This method should always be used instead of using the `offset` field, unless the access to the uninitialised value is required.

The offset shows how far the foreground content was swiped from its original position.

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If the offset has not been initialized yet |

### snapTo

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

```
suspend fun snapTo(targetValue: SwipeToDismissValue): Unit
```

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

| Parameters |
|---|---|
| `targetValue: https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue` | The new target value to set `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissBoxState#currentValue()` to. |

## Public properties

### currentValue

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

```
val currentValue: SwipeToDismissValue
```

The current value of the state.

Before and during a swipe, corresponds to `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue#Default`, then switches to `https://developer.android.com/reference/kotlin/androidx/wear/compose/foundation/SwipeToDismissValue#Dismissed` if the swipe has been completed.

### isAnimationRunning

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

```
val isAnimationRunning: Boolean
```

Whether the state is currently animating.

### offset

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

```
val offset: Float
```

The current offset, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if it has not been initialized yet. Consider using `requireOffset()` method instead - this field should only be used when the access to the uninitialised value is required.

The offset shows how far the foreground content was swiped from its original position.

### targetValue

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

```
val targetValue: SwipeToDismissValue
```

The target value of the state.

If a swipe is in progress, this is the value that the state 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/foundation/SwipeToDismissBoxState#currentValue()`.