---
title: "anchoredDrag"
description: "Call this function to take control of drag logic and perform anchored drag with the latest anchors."
type: "function"
---
## API Reference

### anchoredDrag

> Source set: Common

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

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

All actions that change the [offset](/jetpack-compose/androidx.compose.foundation/foundation/properties/offset/api) of this [AnchoredDraggableState](/jetpack-compose/androidx.compose.foundation/foundation/functions/AnchoredDraggableState/api) must be performed
within an [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) block (even if they don't call any other methods on this object) in
order to guarantee that mutual exclusion is enforced.

If [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) is called from elsewhere with the `dragPriority` higher or equal to ongoing
drag, the ongoing drag will be cancelled.

<b>If the [anchors](/jetpack-compose/androidx.compose.foundation/foundation/properties/anchors/api) change while the `block` is being executed, it will be cancelled and
re-executed with the latest anchors and target.</b> This allows you to target the correct
state.

#### Parameters

| | |
| --- | --- |
| dragPriority | of the drag operation |
| block | perform anchored drag given the current anchor provided |

### anchoredDrag

> Source set: Common

```kotlin
public suspend fun anchoredDrag(
        targetValue: T,
        dragPriority: MutatePriority = MutatePriority.Default,
        block: suspend AnchoredDragScope.(anchor: DraggableAnchors<T>, targetValue: T) -> 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 [offset](/jetpack-compose/androidx.compose.foundation/foundation/properties/offset/api) of this [AnchoredDraggableState](/jetpack-compose/androidx.compose.foundation/foundation/functions/AnchoredDraggableState/api) must be performed
within an [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) 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 [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) is intended
to arrive to. This will set `AnchoredDraggableState.targetValue` to provided value so
consumers can reflect it in their UIs.

<b>If the [anchors](/jetpack-compose/androidx.compose.foundation/foundation/properties/anchors/api) or `AnchoredDraggableState.targetValue` change while the `block` is being
executed, it will be cancelled and re-executed with the latest anchors and target.</b> This
allows you to target the correct state.

If [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag/api) is called from elsewhere with the `dragPriority` higher or equal to ongoing
drag, the ongoing drag will be cancelled.

#### Parameters

| | |
| --- | --- |
| targetValue | hint the target value that this [anchoredDrag](/jetpack-compose/androidx.compose.foundation/foundation/functions/anchoredDrag) is intended to arrive to |
| dragPriority | of the drag operation |
| block | perform anchored drag given the current anchor provided |
