# AnchoredDraggableDefaults

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.AnchoredDraggableDefaults) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0) Common/AllAndroid/JVM
- Cmn

  ```
  object AnchoredDraggableDefaults
  ```

*** ** * ** ***

Contains useful defaults for use with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState` and `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)`

## Summary

| ### Public functions |
|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior` | `@https://developer.android.com/reference/kotlin/androidx/compose/runtime/Composable <T : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html?> https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableDefaults#flingBehavior(androidx.compose.foundation.gestures.AnchoredDraggableState,kotlin.Function1,androidx.compose.animation.core.AnimationSpec)( state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>, positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> )` Create and remember a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior` for use with `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)` that will find the target based on the velocity and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableDefaults#flingBehavior(androidx.compose.foundation.gestures.AnchoredDraggableState,kotlin.Function1,androidx.compose.animation.core.AnimationSpec)` when performing a fling, and settle to that target. | Cmn |

| ### Public properties |
|---|---|---|
| `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/AnchoredDraggableDefaults#DecayAnimationSpec()` The default spec for decaying, an exponential decay | Cmn |
| `(https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableDefaults#PositionalThreshold()` The default positional threshold, 50% of the distance | Cmn |
| `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/AnchoredDraggableDefaults#SnapAnimationSpec()` The default spec for snapping, a tween spec | Cmn |

## Public functions

### flingBehavior

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

```
@Composable
fun <T : Any?> flingBehavior(
    state: AnchoredDraggableState<T>,
    positionalThreshold: (totalDistance: Float) -> Float = PositionalThreshold,
    animationSpec: AnimationSpec<Float> = SnapAnimationSpec
): TargetedFlingBehavior
```

Create and remember a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/TargetedFlingBehavior` for use with `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)` that will find the target based on the velocity and `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableDefaults#flingBehavior(androidx.compose.foundation.gestures.AnchoredDraggableState,kotlin.Function1,androidx.compose.animation.core.AnimationSpec)` when performing a fling, and settle to that target.

There are two paths: a) If the velocity is bigger than `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#AnchoredDraggableMinFlingVelocity()` (125 dp/s), the fling behavior will move to the next closest anchor in the fling direction, determined by the sign of the fling velocity. b) If the velocity is smaller than `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/package-summary#AnchoredDraggableMinFlingVelocity()` (125 dp/s), the fling behavior will consider the positional thresholds, by default `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableDefaults#PositionalThreshold()`. If the offset has crossed the threshold when performing the fling, the fling behavior will move to the next anchor in the fling direction. Otherwise, it will move back to the previous anchor.

| Parameters |
|---|---|
| `state: https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState<T>` | The state the fling will be performed on |
| `positionalThreshold: (totalDistance: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html = PositionalThreshold` | The positional threshold, in px, to be used when calculating the target state while a drag is in progress and when settling after the drag 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. |
| `animationSpec: https://developer.android.com/reference/kotlin/androidx/compose/animation/core/AnimationSpec<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html> = SnapAnimationSpec` | The animation spec used to perform the settling |

## Public properties

### DecayAnimationSpec

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

```
val DecayAnimationSpec: DecayAnimationSpec<Float>
```

The default spec for decaying, an exponential decay

### PositionalThreshold

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

```
val PositionalThreshold: (Float) -> Float
```

The default positional threshold, 50% of the distance

### SnapAnimationSpec

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

```
val SnapAnimationSpec: AnimationSpec<Float>
```

The default spec for snapping, a tween spec