# DraggableAnchors

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

  ```
  interface DraggableAnchors<T : Any?>
  ```

*** ** * ** ***

Structure that represents the anchors of a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/AnchoredDraggableState`.

See the DraggableAnchors factory method to construct drag anchors using a default implementation. This structure does not make any guarantees about ordering of the anchors.

## Summary

| ### Public functions |
|---|---|---|
| `T?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#anchorAt(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Get the anchor key at the specified index, or null if the index is out of bounds. | Cmn |
| `T?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#closestAnchor(kotlin.Float)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Find the closest anchor value to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#closestAnchor(kotlin.Float)`. | Cmn |
| `T?` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#closestAnchor(kotlin.Float,kotlin.Boolean)(position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html, searchUpwards: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)` Find the closest anchor value to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#closestAnchor(kotlin.Float,kotlin.Boolean)`, in the specified direction. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#hasPositionFor(kotlin.Any)(anchor: T)` Whether there is an anchor position associated with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#hasPositionFor(kotlin.Any)` | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#maxPosition()()` The biggest anchor position, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the anchors are empty. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#minPosition()()` The smallest anchor position, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the anchors are empty. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#positionAt(kotlin.Int)(index: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Get the anchor position at the specified index, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the index is out of bounds. | Cmn |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#positionOf(kotlin.Any)(anchor: T)` Get the anchor position for an associated `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#positionOf(kotlin.Any)` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#size()` The number of anchors | Cmn |

| ### Extension functions |
|---|---|---|
| `inline 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/DraggableAnchors<T>.https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#(androidx.compose.foundation.gestures.DraggableAnchors).forEach(kotlin.Function2)(block: (key, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` Iterate over all the anchors. | Cmn |

## Public functions

### anchorAt

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

```
fun anchorAt(index: Int): T?
```

Get the anchor key at the specified index, or null if the index is out of bounds.

### closestAnchor

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

```
fun closestAnchor(position: Float): T?
```

Find the closest anchor value to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#closestAnchor(kotlin.Float)`. If there are multiple anchors at the same offset, it is up to the implementation which will be returned. When using the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors` factory function, this will be the last anchor of the candidates at this offset.

| Parameters |
|---|---|
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The position to start searching from |

| Returns |
|---|---|
| `T?` | The closest anchor or null if the anchors are empty. |

### closestAnchor

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

```
fun closestAnchor(position: Float, searchUpwards: Boolean): T?
```

Find the closest anchor value to the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#closestAnchor(kotlin.Float,kotlin.Boolean)`, in the specified direction.

| Parameters |
|---|---|
| `position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The position to start searching from |
| `searchUpwards: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | Whether to search upwards from the current position or downwards |

| Returns |
|---|---|
| `T?` | The closest anchor or null if the anchors are empty |

### hasPositionFor

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

```
fun hasPositionFor(anchor: T): Boolean
```

Whether there is an anchor position associated with the `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#hasPositionFor(kotlin.Any)`

| Parameters |
|---|---|
| `anchor: T` | The value to look up |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | true if there is an anchor for this value, false if there is no anchor for this value |

### maxPosition

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

```
fun maxPosition(): Float
```

The biggest anchor position, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the anchors are empty.

### minPosition

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

```
fun minPosition(): Float
```

The smallest anchor position, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the anchors are empty.

### positionAt

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

```
fun positionAt(index: Int): Float
```

Get the anchor position at the specified index, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the index is out of bounds.

### positionOf

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

```
fun positionOf(anchor: T): Float
```

Get the anchor position for an associated `https://developer.android.com/reference/kotlin/androidx/compose/foundation/gestures/DraggableAnchors#positionOf(kotlin.Any)`

| Parameters |
|---|---|
| `anchor: T` | The value to look up |

| Returns |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html` | The position of the anchor, or `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/-companion/-na-n.html` if the anchor does not exist |

## Public properties

### size

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

```
val size: Int
```

The number of anchors

## Extension functions

### DraggableAnchors.forEach

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:forEach)

```
inline fun <T : Any?> DraggableAnchors<T>.forEach(block: (key, position: Float) -> Unit): Unit
```

Iterate over all the anchors.

| Parameters |
|---|---|
| `block: (key, position: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | The action to invoke with the key and position |