# SwipeToDismissBoxState

Artifact: [androidx.compose.material3:material3](https://developer.android.com/jetpack/androidx/releases/compose-material3) [View Source](https://cs.android.com/search?q=file:androidx/compose/material3/SwipeToDismissBox.kt+class:androidx.compose.material3.SwipeToDismissBoxState) Common/AllAndroid/JVM
- Cmn

  ```
  class SwipeToDismissBoxState
  ```

*** ** * ** ***

State of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBox.composable#SwipeToDismissBox(androidx.compose.material3.SwipeToDismissBoxState,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function1)` composable.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState, https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue>` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#Saver(kotlin.Function1)(positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` The default `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#Saver(kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState, https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue>` | `[Saver](https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#Saver(kotlin.Function1,kotlin.Function1,androidx.compose.ui.unit.Density))( confirmValueChange: (https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density )` **This function is deprecated.** confirmValueChange is deprecated without replacement. | Cmn |

| ### Public constructors |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#SwipeToDismissBoxState(androidx.compose.material3.SwipeToDismissBoxValue,kotlin.Function1)( initialValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue, positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` State of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBox.composable#SwipeToDismissBox(androidx.compose.material3.SwipeToDismissBoxState,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function1)` composable. | Cmn |
| `[SwipeToDismissBoxState](https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#SwipeToDismissBoxState(androidx.compose.material3.SwipeToDismissBoxValue,androidx.compose.ui.unit.Density,kotlin.Function1,kotlin.Function1))( initialValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue, density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density, confirmValueChange: (https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html )` **This function is deprecated.** confirmValueChange is deprecated without replacement. | Cmn |

| ### Public functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#dismiss(androidx.compose.material3.SwipeToDismissBoxValue)(direction: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue)` Dismiss the component in the given `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#dismiss(androidx.compose.material3.SwipeToDismissBoxValue)`, with an animation and suspend. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#requireOffset()()` Require the current offset. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#reset()()` Reset the component to the default position with animation and suspend until it if fully reset or animation has been cancelled. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#snapTo(androidx.compose.material3.SwipeToDismissBoxValue)(targetValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue)` Set the state without any animation and suspend until it's set | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#currentValue()` The current state value of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#dismissDirection()` The direction (if any) in which the composable has been or is being dismissed. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#progress()` The fraction of the progress going from currentValue to targetValue, within 0f..1f bounds. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#settledValue()` The value the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState` is currently settled at. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#targetValue()` The target state. | Cmn |

## Public companion functions

### Saver

Cmn

```
fun Saver(positionalThreshold: (totalDistance: Float) -> Float): Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue>
```

The default `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#Saver(kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState`.

### Saver

Cmn

```
fun [Saver](https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#Saver(kotlin.Function1,kotlin.Function1,androidx.compose.ui.unit.Density))(
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean,
    positionalThreshold: (totalDistance: Float) -> Float,
    density: Density
): Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue>
```

> [!CAUTION]
> **This function is deprecated.**   
> confirmValueChange is deprecated without replacement. Rather than relying on a callback to veto state changes, the anchor set should not include disallowed anchors. See androidx.compose.foundation.samples.AnchoredDraggableDynamicAnchorsSample for an example of using dynamic anchors over confirmValueChange, use this instead:
>
> ```kotlin
> Saver(positionalThreshold, density)
> ```

`https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#Saver(kotlin.Function1,kotlin.Function1,androidx.compose.ui.unit.Density)` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState`.

## Public constructors

### SwipeToDismissBoxState

Cmn

```
SwipeToDismissBoxState(
    initialValue: SwipeToDismissBoxValue,
    positionalThreshold: (totalDistance: Float) -> Float
)
```

State of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBox.composable#SwipeToDismissBox(androidx.compose.material3.SwipeToDismissBoxState,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function1)` composable.

| Parameters |
|---|---|
| `initialValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | The initial value of the state. |
| `positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The positional threshold to be used when calculating the target state while a swipe is in progress and when settling after the swipe ends. This is the distance from the start of a transition. It will be, depending on the direction of the interaction, added or subtracted from/to the origin offset. It should always be a positive value. |

### SwipeToDismissBoxState

Cmn

```
[SwipeToDismissBoxState](https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#SwipeToDismissBoxState(androidx.compose.material3.SwipeToDismissBoxValue,androidx.compose.ui.unit.Density,kotlin.Function1,kotlin.Function1))(
    initialValue: SwipeToDismissBoxValue,
    density: Density,
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true },
    positionalThreshold: (totalDistance: Float) -> Float
)
```

> [!CAUTION]
> **This function is deprecated.**   
> confirmValueChange is deprecated without replacement. Rather than relying on a callback to veto state changes, the anchor set should not include disallowed anchors. See androidx.compose.foundation.samples.AnchoredDraggableDynamicAnchorsSample for an example of using dynamic anchors over confirmValueChange, use this instead:
>
> ```kotlin
> SwipeToDismissBoxState(initialValue, density, positionalThreshold)
> ```

State of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBox.composable#SwipeToDismissBox(androidx.compose.material3.SwipeToDismissBoxState,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function1)` composable.

| Parameters |
|---|---|
| `initialValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | The initial value of the state. |
| `density: https://developer.android.com/reference/kotlin/androidx/compose/ui/unit/Density` | The density that this state can use to convert values to and from dp. |
| `confirmValueChange: (https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { true }` | Optional callback invoked to confirm or veto a pending state change. |
| `positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The positional threshold to be used when calculating the target state while a swipe is in progress and when settling after the swipe ends. This is the distance from the start of a transition. It will be, depending on the direction of the interaction, added or subtracted from/to the origin offset. It should always be a positive value. |

## Public functions

### dismiss

Cmn

```
suspend fun dismiss(direction: SwipeToDismissBoxValue): Unit
```

Dismiss the component in the given `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState#dismiss(androidx.compose.material3.SwipeToDismissBoxValue)`, with an animation and suspend. This method will throw `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` if the animation is interrupted

| Parameters |
|---|---|
| `direction: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | The dismiss direction. |

### requireOffset

Cmn

```
fun requireOffset(): Float
```

Require the current offset.

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

### reset

Cmn

```
suspend fun reset(): Unit
```

Reset the component to the default position with animation and suspend until it if fully reset or animation has been cancelled. This method will throw `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` if the animation is interrupted

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

### snapTo

Cmn

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

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

| Parameters |
|---|---|
| `targetValue: https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxValue` | The new target value |

## Public properties

### currentValue

Cmn

```
val currentValue: SwipeToDismissBoxValue
```

The current state value of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState`.

### dismissDirection

Cmn

```
val dismissDirection: SwipeToDismissBoxValue
```

The direction (if any) in which the composable has been or is being dismissed.

Use this to change the background of the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBox.composable#SwipeToDismissBox(androidx.compose.material3.SwipeToDismissBoxState,kotlin.Function1,androidx.compose.ui.Modifier,kotlin.Boolean,kotlin.Boolean,kotlin.Boolean,kotlin.Function1,kotlin.Function1)` if you want different actions on each side.

### progress

Cmn

```
val progress: Float
```

The fraction of the progress going from currentValue to targetValue, within 0f..1f bounds.

### settledValue

Cmn

```
val settledValue: SwipeToDismissBoxValue
```

The value the `https://developer.android.com/reference/kotlin/androidx/compose/material3/SwipeToDismissBoxState` is currently settled at. When progressing through multiple anchors, e.g. A -\> B -\> C, settledValue will stay the same until settled at an anchor, while currentValue will update to the closest anchor.

### targetValue

Cmn

```
val targetValue: SwipeToDismissBoxValue
```

The target state. This is the closest state to the current offset (taking into account positional thresholds). If no interactions like animations or drags are in progress, this will be the current state.