---
title: "SwipeToDismissBoxState"
description: "State of the [SwipeToDismissBox] composable."
type: "class"
---

<div class='type'>Class</div>


<a id='references'></a>

<div class='sourceset sourceset-common'>Common</div>


```kotlin
class SwipeToDismissBoxState
```


State of the `SwipeToDismissBox` composable.


## Secondary Constructors

```kotlin
constructor(
    initialValue: SwipeToDismissBoxValue,
    positionalThreshold: (totalDistance: Float) -> Float,
) {
    this.anchoredDraggableState = AnchoredDraggableState(initialValue)
    this.positionalThreshold = positionalThreshold
}
```


State of the `SwipeToDismissBox` composable.

#### Parameters

| | |
| --- | --- |
| initialValue | The initial value of the state. |
| positionalThreshold | 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. |



```kotlin
constructor(
    initialValue: SwipeToDismissBoxValue,
    density: Density,
    confirmValueChange: (SwipeToDismissBoxValue) -> Boolean = { true },
    positionalThreshold: (totalDistance: Float) -> Float,
) {
    this.anchoredDraggableState =
        AnchoredDraggableState(
            initialValue = initialValue,
            confirmValueChange = confirmValueChange,
            velocityThreshold = { with(density) { DismissVelocityThreshold.toPx() } },
            positionalThreshold = positionalThreshold,
            snapAnimationSpec = AnchoredDraggableDefaults.SnapAnimationSpec,
            decayAnimationSpec = AnchoredDraggableDefaults.DecayAnimationSpec,
        )
}
```


State of the `SwipeToDismissBox` composable.

#### Parameters

| | |
| --- | --- |
| initialValue | The initial value of the state. |
| density | The density that this state can use to convert values to and from dp. |
| confirmValueChange | Optional callback invoked to confirm or veto a pending state change. |
| positionalThreshold | 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. |



## Properties

<div class='sourceset sourceset-common'>Common</div>


```kotlin
val currentValue: SwipeToDismissBoxValue
```


The current state value of the `SwipeToDismissBoxState`.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
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.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
val settledValue: SwipeToDismissBoxValue
```


The value the `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.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
@get:FloatRange(from = 0.0, to = 1.0)

val progress: Float
```


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



<div class='sourceset sourceset-common'>Common</div>


```kotlin
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 `SwipeToDismissBox` if you want different actions on
each side.



## Functions

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


Require the current offset.


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


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

#### Parameters

| | |
| --- | --- |
| targetValue | The new target value |



```kotlin
suspend fun reset() =
        anchoredDraggableState.animateTo(targetValue = SwipeToDismissBoxValue.Settled)
```


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 `CancellationException` if the
animation is interrupted

#### Returns

| | |
| --- | --- |
|  | the reason the reset animation ended |



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


Dismiss the component in the given `direction`, with an animation and suspend. This method
will throw `CancellationException` if the animation is interrupted

#### Parameters

| | |
| --- | --- |
| direction | The dismiss direction. |



## Companion Object

#### Methods

<div class='sourceset sourceset-common'>Common</div>


> **Deprecated** ConfirmValueChangeDeprecated

```kotlin
fun Saver(
            confirmValueChange: (SwipeToDismissBoxValue) -> Boolean,
            positionalThreshold: (totalDistance: Float) -> Float,
            density: Density,
        ) =
            Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue>(
                save = { it.currentValue },
                restore = {
                    SwipeToDismissBoxState(it, density, confirmValueChange, positionalThreshold)
                },
            )
```


`Saver` implementation for `SwipeToDismissBoxState`.



<div class='sourceset sourceset-common'>Common</div>


```kotlin
fun Saver(positionalThreshold: (totalDistance: Float) -> Float) =
            Saver<SwipeToDismissBoxState, SwipeToDismissBoxValue>(
                save = { it.currentValue },
                restore = { SwipeToDismissBoxState(it, positionalThreshold) },
            )
```


The default `Saver` implementation for `SwipeToDismissBoxState`.





