# AnchoredDraggableState

Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/AnchoredDraggable.kt+class:androidx.compose.foundation.gestures.AnchoredDraggableState) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0) Common/AllAndroid/JVM
- Cmn

  ```
  class AnchoredDraggableState<T : Any?>
  ```

*** ** * ** ***

State of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/anchoredDraggable.modifier#(androidx.compose.ui.Modifier).anchoredDraggable(androidx.compose.foundation.gestures.AnchoredDraggableState,kotlin.Boolean,androidx.compose.foundation.gestures.Orientation,kotlin.Boolean,androidx.compose.foundation.interaction.MutableInteractionSource,androidx.compose.foundation.OverscrollEffect,androidx.compose.foundation.gestures.FlingBehavior)` modifier. Use the constructor overload with anchors if the anchors are defined in composition, or update the anchors using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)`.

This contains necessary information about any ongoing drag or animation and provides methods to change the state either immediately or by starting an animation.

## Summary

| ### Public companion functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>, T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver()()` The default `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>, T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> [Saver](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver(kotlin.Function1))(confirmValueChange: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` **This function is deprecated.** confirmValueChange is deprecated without replacement. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/runtime/saveable/Saver<https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>, T>` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> [Saver](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver(androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec,kotlin.Function1,kotlin.Function0,kotlin.Function1))( snapAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, decayAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, positionalThreshold: (distance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, velocityThreshold: () -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, confirmValueChange: (T) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` **This function is deprecated.** This constructor of AnchoredDraggableState has been deprecated. | Cmn |

| ### Public constructors |
|---|---|
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#AnchoredDraggableState(kotlin.Any)(initialValue: T)` | Cmn |
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#AnchoredDraggableState(kotlin.Any,androidx.compose.foundation.gestures.DraggableAnchors)( initialValue: T, anchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T> )` Construct an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` instance with anchors. | Cmn |
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> [AnchoredDraggableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#AnchoredDraggableState(kotlin.Any,kotlin.Function1))( initialValue: T, confirmValueChange: (newValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` **This function is deprecated.** confirmValueChange is deprecated without replacement. | Cmn |
| `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> [AnchoredDraggableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#AnchoredDraggableState(kotlin.Any,androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Function1))( initialValue: T, anchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>, confirmValueChange: (newValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/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/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)( dragPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDragScope.(anchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Call this function to take control of drag logic and perform anchored drag with the latest anchors. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)( targetValue: T, dragPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDragScope.(anchor: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>, targetValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` Call this function to take control of drag logic and perform anchored drag with the latest anchors and target. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#dispatchRawDelta(kotlin.Float)(delta: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Drag by the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#dispatchRawDelta(kotlin.Float)`, coerce it in the bounds and dispatch it to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/FloatRange(from = 0.0, to = 1.0) 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/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)(from: T, to: T)` The fraction of the offset between `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)`, as a fraction between 0f..1f, or 1f if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)` is equal to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)`. | Cmn |
| `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/compose/foundation/gestures/AnchoredDraggableState#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/foundation/gestures/AnchoredDraggableState#settle(androidx.compose.animation.core.AnimationSpec)(animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>)` Find the closest anchor and settle at it with the given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(androidx.compose.animation.core.AnimationSpec)`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `[settle](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(kotlin.Float))(velocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` **This function is deprecated.** settle does not accept a velocity anymore. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)(newAnchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>, newTarget: T)` Update the anchors. | Cmn |

| ### Public properties |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchors()` | Cmn |
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#currentValue()` The current value of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`. | Cmn |
| `lateinit https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#decayAnimationSpec()` **This property is deprecated.** This constructor of AnchoredDraggableState has been deprecated. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#isAnimationRunning()` Whether an animation is currently in progress. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#lastVelocity()` The velocity of the last known animation. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#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. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress()` **This property is deprecated.** Use the progress function to query the progress between two specified anchors. | Cmn |
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settledValue()` The value the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` is currently settled at. | Cmn |
| `lateinit https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#snapAnimationSpec()` **This property is deprecated.** This constructor of AnchoredDraggableState has been deprecated. | Cmn |
| `T` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#targetValue()` The target value. | Cmn |

| ### Extension functions |
|---|---|---|
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)( targetValue: T, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Animate to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)( targetValue: T, velocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, snapAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>, decayAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Attempt to animate using decay Animation to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)`. | Cmn |
| `suspend https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `<T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)(targetValue: T)` Snap to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` without any animation. | Cmn |

## Public companion functions

### Saver

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun <T : Any> Saver(): Saver<AnchoredDraggableState<T>, T>
```

The default `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver()` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`.

### Saver

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun <T : Any> [Saver](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver(kotlin.Function1))(confirmValueChange: (T) -> Boolean = { true }): Saver<AnchoredDraggableState<T>, T>
```

> [!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.

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

### Saver

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun <T : Any> [Saver](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver(androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec,kotlin.Function1,kotlin.Function0,kotlin.Function1))(
    snapAnimationSpec: AnimationSpec<Float>,
    decayAnimationSpec: DecayAnimationSpec<Float>,
    positionalThreshold: (distance: Float) -> Float,
    velocityThreshold: () -> Float,
    confirmValueChange: (T) -> Boolean = { true }
): Saver<AnchoredDraggableState<T>, T>
```

> [!CAUTION]
> **This function is deprecated.**   
> This constructor of AnchoredDraggableState has been deprecated. Please pass thresholds and animation specs to AnchoredDraggableDefaults.flingBehavior(..) instead, which can be passed to Modifier.anchoredDraggable.

The default `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#Saver(androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec,kotlin.Function1,kotlin.Function0,kotlin.Function1)` implementation for `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`.

## Public constructors

### AnchoredDraggableState

Cmn

```
<T : Any?> AnchoredDraggableState(initialValue: T)
```

| Parameters |
|---|---|
| `initialValue: T` | The initial value of the state. |

### AnchoredDraggableState

Cmn

```
<T : Any?> AnchoredDraggableState(
    initialValue: T,
    anchors: DraggableAnchors<T>
)
```

Construct an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` instance with anchors.

| Parameters |
|---|---|
| `initialValue: T` | The initial value of the state. |
| `anchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>` | The anchors of the state. Use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)` to update the anchors later. |

### AnchoredDraggableState

Cmn

```
<T : Any?> [AnchoredDraggableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#AnchoredDraggableState(kotlin.Any,kotlin.Function1))(
    initialValue: T,
    confirmValueChange: (newValue) -> Boolean
)
```

> [!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.

Construct an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` instance with anchors.

```kotlin
import androidx.compose.foundation.gestures.AnchoredDraggableState
import androidx.compose.foundation.gestures.DraggableAnchors
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.anchoredDraggable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset

val open = "Open"
val closed = "Closed"

@Composable
fun DrawerLayout(
    state: AnchoredDraggableState<String>,
    activePositions: List<String> = listOf(open, closed),
    modifier: Modifier = Modifier,
    drawerContent: @Composable () -> Unit,
    content: @Composable () -> Unit,
) {
    Box(modifier) {
        Box(Modifier.anchoredDraggable(state, Orientation.Horizontal)) { content() }
        Box(
            Modifier.onSizeChanged { measuredSize ->
                    state.updateAnchors(
                        DraggableAnchors {
                            if (closed in activePositions) {
                                closed at -measuredSize.width.toFloat()
                            }
                            if (open in activePositions) {
                                open at 0f
                            }
                        }
                    )
                }
                .offset { IntOffset(x = state.requireOffset().roundToInt(), y = 0) }
        ) {
            drawerContent()
        }
    }
}

val state =
    rememberSaveable(saver = AnchoredDraggableState.Saver()) {
        AnchoredDraggableState(initialValue = closed)
    }
val activePositions = remember { mutableStateListOf(open, closed) }
DrawerLayout(
    state,
    activePositions,
    drawerContent = {
        Button(
            onClick = {
                if (closed in activePositions) {
                    activePositions.remove(closed)
                } else {
                    activePositions.add(closed)
                }
            }
        ) {
            val text =
                if (closed in activePositions) {
                    "Click to disallow closing drawer"
                } else {
                    "Click to allow closing"
                }
            Text(text)
        }
    },
) {
    Text("Swipe to expand Drawer")
}
```
For an example of using dynamic anchors to replace confirmValueChange.

| Parameters |
|---|---|
| `initialValue: T` | The initial value of the state. |
| `confirmValueChange: (newValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Optional callback invoked to confirm or veto a pending state change. |

### AnchoredDraggableState

Cmn

```
<T : Any?> [AnchoredDraggableState](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#AnchoredDraggableState(kotlin.Any,androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Function1))(
    initialValue: T,
    anchors: DraggableAnchors<T>,
    confirmValueChange: (newValue) -> Boolean = { true }
)
```

> [!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.

Construct an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` instance with anchors.

```kotlin
import androidx.compose.foundation.gestures.AnchoredDraggableState
import androidx.compose.foundation.gestures.DraggableAnchors
import androidx.compose.foundation.gestures.Orientation
import androidx.compose.foundation.gestures.anchoredDraggable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.offset
import androidx.compose.foundation.layout.width
import androidx.compose.material3.Button
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.layout.onSizeChanged
import androidx.compose.ui.unit.IntOffset

val open = "Open"
val closed = "Closed"

@Composable
fun DrawerLayout(
    state: AnchoredDraggableState<String>,
    activePositions: List<String> = listOf(open, closed),
    modifier: Modifier = Modifier,
    drawerContent: @Composable () -> Unit,
    content: @Composable () -> Unit,
) {
    Box(modifier) {
        Box(Modifier.anchoredDraggable(state, Orientation.Horizontal)) { content() }
        Box(
            Modifier.onSizeChanged { measuredSize ->
                    state.updateAnchors(
                        DraggableAnchors {
                            if (closed in activePositions) {
                                closed at -measuredSize.width.toFloat()
                            }
                            if (open in activePositions) {
                                open at 0f
                            }
                        }
                    )
                }
                .offset { IntOffset(x = state.requireOffset().roundToInt(), y = 0) }
        ) {
            drawerContent()
        }
    }
}

val state =
    rememberSaveable(saver = AnchoredDraggableState.Saver()) {
        AnchoredDraggableState(initialValue = closed)
    }
val activePositions = remember { mutableStateListOf(open, closed) }
DrawerLayout(
    state,
    activePositions,
    drawerContent = {
        Button(
            onClick = {
                if (closed in activePositions) {
                    activePositions.remove(closed)
                } else {
                    activePositions.add(closed)
                }
            }
        ) {
            val text =
                if (closed in activePositions) {
                    "Click to disallow closing drawer"
                } else {
                    "Click to allow closing"
                }
            Text(text)
        }
    },
) {
    Text("Swipe to expand Drawer")
}
```
For an example of using dynamic anchors to replace confirmValueChange.

| Parameters |
|---|---|
| `initialValue: T` | The initial value of the state. |
| `anchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>` | The anchors of the state. Use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)` to update the anchors later. |
| `confirmValueChange: (newValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html = { true }` | Optional callback invoked to confirm or veto a pending state change. |

## Public functions

### anchoredDrag

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
suspend fun anchoredDrag(
    dragPriority: MutatePriority = MutatePriority.Default,
    block: suspend AnchoredDragScope.(anchors: DraggableAnchors<T>) -> Unit
): Unit
```

Call this function to take control of drag logic and perform anchored drag with the latest anchors.

All actions that change the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#offset()` of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` must be performed within an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)` block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)` is called from elsewhere with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)` higher or equal to ongoing drag, the ongoing drag will be cancelled.

**If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchors()` change while the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)` is being executed, it will be cancelled and re-executed with the latest anchors and target.** This allows you to target the correct state.

| Parameters |
|---|---|
| `dragPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority = MutatePriority.Default` | of the drag operation |
| `block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDragScope.(anchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | perform anchored drag given the current anchor provided |

### anchoredDrag

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
suspend fun anchoredDrag(
    targetValue: T,
    dragPriority: MutatePriority = MutatePriority.Default,
    block: suspend AnchoredDragScope.(anchor: DraggableAnchors<T>, targetValue) -> Unit
): Unit
```

Call this function to take control of drag logic and perform anchored drag with the latest anchors and target.

All actions that change the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#offset()` of this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` must be performed within an `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)` block (even if they don't call any other methods on this object) in order to guarantee that mutual exclusion is enforced.

This overload allows the caller to hint the target value that this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)` is intended to arrive to. This will set `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#targetValue()` to provided value so consumers can reflect it in their UIs.

**If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchors()` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#targetValue()` change while the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)` is being executed, it will be cancelled and re-executed with the latest anchors and target.** This allows you to target the correct state.

If `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)` is called from elsewhere with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)` higher or equal to ongoing drag, the ongoing drag will be cancelled.

| Parameters |
|---|---|
| `targetValue: T` | hint the target value that this `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(kotlin.Any,androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction3)` is intended to arrive to |
| `dragPriority: https://developer.android.com/reference/kotlin/androidx/compose/foundation/MutatePriority = MutatePriority.Default` | of the drag operation |
| `block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDragScope.(anchor: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>, targetValue) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | perform anchored drag given the current anchor provided |

### dispatchRawDelta

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
fun dispatchRawDelta(delta: Float): Float
```

Drag by the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#dispatchRawDelta(kotlin.Float)`, coerce it in the bounds and dispatch it to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The delta the consumed by the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` |

### progress

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
@FrequentlyChangingValue
fun progress(from: T, to: T): @FloatRange(from = 0.0, to = 1.0) Float
```

The fraction of the offset between `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)` and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)`, as a fraction between 0f..1f, or 1f if `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)` is equal to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#progress(kotlin.Any,kotlin.Any)`.

| Parameters |
|---|---|
| `from: T` | The starting value used to calculate the distance |
| `to: T` | The end value used to calculate the distance |

### requireOffset

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
@FrequentlyChangingValue
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 |

| See also |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#offset()` |   |

### settle

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
suspend fun settle(animationSpec: AnimationSpec<Float>): Unit
```

Find the closest anchor and settle at it with the given `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(androidx.compose.animation.core.AnimationSpec)`.

| Parameters |
|---|---|
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>` | The animation spec that will be used to animate to the closest anchor. |

### settle

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
suspend fun [settle](https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(kotlin.Float))(velocity: Float): Float
```

> [!CAUTION]
> **This function is deprecated.**   
> settle does not accept a velocity anymore. Please use FlingBehavior#performFling instead. See AnchoredDraggableSample.kt for example usages.

Find the closest anchor, taking into account the velocityThreshold and positionalThreshold, and settle at it with an animation.

If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(kotlin.Float)` is lower than the velocityThreshold, the closest anchor by distance and positionalThreshold will be the target. If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(kotlin.Float)` is higher than the velocityThreshold, the positionalThreshold will **not** be considered and the next anchor in the direction indicated by the sign of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(kotlin.Float)` will be the target.

Based on the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settle(kotlin.Float)`, either snapAnimationSpec or decayAnimationSpec will be used to animate towards the target.

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The velocity consumed in the animation |

### updateAnchors

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
fun updateAnchors(
    newAnchors: DraggableAnchors<T>,
    newTarget: T = if (!offset.isNaN()) {
                newAnchors.closestAnchor(offset) ?: targetValue
            } else targetValue
): Unit
```

Update the anchors. If there is no ongoing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)` operation, snap to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)`, otherwise restart the ongoing `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#anchoredDrag(androidx.compose.foundation.MutatePriority,kotlin.coroutines.SuspendFunction2)` operation (e.g. an animation) with the new anchors.

**If your anchors depend on the size of the layout, updateAnchors should be called in the layout (placement) phase, e.g. through Modifier.onSizeChanged.** This ensures that the state is set up within the same frame. For static anchors, or anchors with different data dependencies, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)` is safe to be called from side effects or layout.

| Parameters |
|---|---|
| `newAnchors: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors<T>` | The new anchors. |
| `newTarget: T = if (!offset.isNaN()) { newAnchors.closestAnchor(offset) ?: targetValue } else targetValue` | The new target, by default the closest anchor or the current target if there are no anchors. |

## Public properties

### anchors

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
val anchors: DraggableAnchors<T>
```

### currentValue

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
val currentValue: T
```

The current value of the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`.

That is the closest anchor point that the state has passed through.

### decayAnimationSpec

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
lateinit val decayAnimationSpec: DecayAnimationSpec<Float>
```

> [!CAUTION]
> **This property is deprecated.**   
> This constructor of AnchoredDraggableState has been deprecated. Please pass thresholds and animation specs to AnchoredDraggableDefaults.flingBehavior(..) instead, which can be passed to Modifier.anchoredDraggable.

### isAnimationRunning

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
val isAnimationRunning: Boolean
```

Whether an animation is currently in progress.

### lastVelocity

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
val lastVelocity: Float
```

The velocity of the last known animation. Gets reset to 0f when an animation completes successfully, but does not get reset when an animation gets interrupted. You can use this value to provide smooth reconciliation behavior when re-targeting an animation.

### offset

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.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.

The offset will be initialized when the anchors are first set through `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#updateAnchors(androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any)`.

Strongly consider using `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#requireOffset()` which will throw if the offset is read before it is initialized. This helps catch issues early in your workflow.

### progress

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0) Deprecated in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
val progress: Float
```

> [!CAUTION]
> **This property is deprecated.**   
> Use the progress function to query the progress between two specified anchors, use this instead:
>
> ```kotlin
> progress(state.settledValue, state.targetValue)
> ```

The fraction of the progress going from `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settledValue()` to `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#targetValue()`, within 0f..1f bounds, or 1f if the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` is in a settled state.

### settledValue

Cmn Added in [1.7.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.7.0)

```
val settledValue: T
```

The value the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` is currently settled at.

When progressing through multiple anchors, e.g. `A -> B -> C`, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#settledValue()` will stay the same until settled at an anchor, while `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#currentValue()` will update to the closest anchor.

### snapAnimationSpec

Cmn Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
lateinit val snapAnimationSpec: AnimationSpec<Float>
```

> [!CAUTION]
> **This property is deprecated.**   
> This constructor of AnchoredDraggableState has been deprecated. Please pass thresholds and animation specs to AnchoredDraggableDefaults.flingBehavior(..) instead, which can be passed to Modifier.anchoredDraggable.

### targetValue

Cmn Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0)

```
val targetValue: T
```

The target value. This is the closest value to the current offset. If no interactions like animations or drags are in progress, this will be the current value.

## Extension functions

### AnchoredDraggableState.animateTo

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/AnchoredDraggable.kt+function:animateTo)

```
suspend fun <T : Any?> AnchoredDraggableState<T>.animateTo(
    targetValue: T,
    animationSpec: AnimationSpec<Float> = if (usePreModifierChangeBehavior) {
            @Suppress("DEPRECATION") this.snapAnimationSpec
        } else AnchoredDraggableDefaults.SnapAnimationSpec
): Unit
```

Animate to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)`. If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)` is not in the set of anchors, the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#currentValue()` will be updated to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)` without updating the offset.

| Parameters |
|---|---|
| `targetValue: T` | The target value of the animation |
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = if (usePreModifierChangeBehavior) { @Suppress("DEPRECATION") this.snapAnimationSpec } else AnchoredDraggableDefaults.SnapAnimationSpec` | The animation spec used to perform the animation |

| Throws |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` | if the interaction interrupted by another interaction like a gesture interaction or another programmatic interaction like a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Any,androidx.compose.animation.core.AnimationSpec)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` call. |

### AnchoredDraggableState.animateToWithDecay

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/AnchoredDraggable.kt+function:animateToWithDecay)

```
suspend fun <T : Any?> AnchoredDraggableState<T>.animateToWithDecay(
    targetValue: T,
    velocity: Float,
    snapAnimationSpec: AnimationSpec<Float> = if (usePreModifierChangeBehavior) {
            @Suppress("DEPRECATION") this.snapAnimationSpec
        } else AnchoredDraggableDefaults.SnapAnimationSpec,
    decayAnimationSpec: DecayAnimationSpec<Float> = if (usePreModifierChangeBehavior) {
            @Suppress("DEPRECATION") this.decayAnimationSpec
        } else AnchoredDraggableDefaults.DecayAnimationSpec
): Float
```

Attempt to animate using decay Animation to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)`. If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` is high enough to get to the target offset, we'll use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` to get to that offset and return the consumed velocity. If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` is not high enough, we'll use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` to reach the target offset.

If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` is not in the set of anchors, `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#currentValue()` will be updated ro the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` without updating the offset.

| Parameters |
|---|---|
| `targetValue: T` | The target value of the animation |
| `velocity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The velocity the animation should start with, in px/s |
| `snapAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = if (usePreModifierChangeBehavior) { @Suppress("DEPRECATION") this.snapAnimationSpec } else AnchoredDraggableDefaults.SnapAnimationSpec` | The animation spec used if the velocity is not high enough to perform a decay to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` using the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` |
| `decayAnimationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/DecayAnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = if (usePreModifierChangeBehavior) { @Suppress("DEPRECATION") this.decayAnimationSpec } else AnchoredDraggableDefaults.DecayAnimationSpec` | The animation spec used if the velocity is high enough to perform a decay to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateToWithDecay(kotlin.Any,kotlin.Float,androidx.compose.animation.core.AnimationSpec,androidx.compose.animation.core.DecayAnimationSpec)` |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The velocity consumed in the animation |

| Throws |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` | if the interaction interrupted bt another interaction like a gesture interaction or another programmatic interaction like `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Float,androidx.compose.foundation.gestures.AnchoredDragScope,androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any,androidx.compose.animation.core.AnimationSpec)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` call. |

### AnchoredDraggableState.snapTo

Cmn Artifact: [androidx.compose.foundation:foundation](https://developer.android.com/jetpack/androidx/releases/compose-foundation) [View Source](https://cs.android.com/search?q=file:androidx/compose/foundation/gestures/AnchoredDraggable.kt+function:snapTo)

```
suspend fun <T : Any?> AnchoredDraggableState<T>.snapTo(targetValue: T): Unit
```

Snap to a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` without any animation. If the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` is not in the set of anchors, the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState#currentValue()` will be updated to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` without updating the offset.

| Parameters |
|---|---|
| `targetValue: T` | The target value of the animation |

| Throws |
|---|---|
| `https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-cancellation-exception/index.html` | if the interaction interrupted by another interaction like a gesture interaction or another programmatic interaction like a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).animateTo(kotlin.Float,androidx.compose.foundation.gestures.AnchoredDragScope,androidx.compose.foundation.gestures.DraggableAnchors,kotlin.Any,androidx.compose.animation.core.AnimationSpec)` or `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#(androidx.compose.foundation.gestures.AnchoredDraggableState).snapTo(kotlin.Any)` call. |