# dragAndDropSource

Common/AllAndroid/JVM

## Functions summary

|---|---|---|
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.[dragAndDropSource](https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.coroutines.SuspendFunction1))(block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)` **This function is deprecated.** Replaced by overload with a callback for obtain a transfer data,start detection is performed by Compose itself | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1)( transferData: (https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset) -> https://developer.android.com/reference/kotlin/androidx/compose/ui/draganddrop/DragAndDropTransferData? )` A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` that allows an element it is applied to be treated like a source for drag and drop operations. | Cmn |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `@https://developer.android.com/reference/kotlin/androidx/compose/foundation/ExperimentalFoundationApi https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.[dragAndDropSource](https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1,kotlin.coroutines.SuspendFunction1))( drawDragDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html )` **This function is deprecated.** Replaced by overload with a callback for obtain a transfer data,start detection is performed by Compose itself | android |
| `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` | `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier.https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1,kotlin.Function1)( drawDragDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html, transferData: (https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset) -> https://developer.android.com/reference/kotlin/androidx/compose/ui/draganddrop/DragAndDropTransferData? )` A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` that allows an element it is applied to be treated like a source for drag and drop operations. | Cmn |

## Functions

### Modifier.dragAndDropSource

android 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/draganddrop/LegacyDragAndDropSourceWithDefaultPainter.android.kt+function:dragAndDropSource) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
@ExperimentalFoundationApi
fun Modifier.[dragAndDropSource](https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.coroutines.SuspendFunction1))(block: suspend DragAndDropSourceScope.() -> Unit): Modifier
```

> [!CAUTION]
> **This function is deprecated.**   
> Replaced by overload with a callback for obtain a transfer data,start detection is performed by Compose itself, use this instead:
>
> ```kotlin
> Modifier.dragAndDropSource(transferData)
> ```

A Modifier that allows an element it is applied to to be treated like a source for drag and drop operations. It displays the element dragged as a drag shadow.

Learn how to use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1,kotlin.coroutines.SuspendFunction1)`:

```kotlin
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.draganddrop.dragAndDropSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draganddrop.DragAndDropTransferData
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

val label = remember { "Drag me" }
Box(
    modifier =
        modifier
            .dragAndDropSource { _ ->
                DragAndDropTransferData(
                    clipData = ClipData.newPlainText(label, label),
                    flags = View.DRAG_FLAG_GLOBAL,
                )
            }
            .border(
                border =
                    BorderStroke(
                        width = 4.dp,
                        brush = Brush.linearGradient(listOf(Color.Magenta, Color.Magenta)),
                    ),
                shape = RoundedCornerShape(16.dp),
            )
            .padding(24.dp)
) {
    Text(modifier = Modifier.align(Alignment.Center), text = label)
}
```

| Parameters |
|---|---|
| `block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A lambda with a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope` as a receiver which provides a `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope` to detect the drag gesture, after which a drag and drop gesture can be started with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope#startTransfer(androidx.compose.ui.draganddrop.DragAndDropTransferData)`. |

### Modifier.dragAndDropSource

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/draganddrop/DragAndDropSource.kt+function:dragAndDropSource) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun Modifier.dragAndDropSource(
    transferData: (Offset) -> DragAndDropTransferData?
): Modifier
```

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` that allows an element it is applied to be treated like a source for drag and drop operations. It displays the element dragged as a drag shadow.

Learn how to use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1)`:

```kotlin
import androidx.compose.foundation.BorderStroke
import androidx.compose.foundation.border
import androidx.compose.foundation.draganddrop.dragAndDropSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.Text
import androidx.compose.runtime.remember
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.draganddrop.DragAndDropTransferData
import androidx.compose.ui.graphics.Brush
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.unit.dp

val label = remember { "Drag me" }
Box(
    modifier =
        modifier
            .dragAndDropSource { _ ->
                DragAndDropTransferData(
                    clipData = ClipData.newPlainText(label, label),
                    flags = View.DRAG_FLAG_GLOBAL,
                )
            }
            .border(
                border =
                    BorderStroke(
                        width = 4.dp,
                        brush = Brush.linearGradient(listOf(Color.Magenta, Color.Magenta)),
                    ),
                shape = RoundedCornerShape(16.dp),
            )
            .padding(24.dp)
) {
    Text(modifier = Modifier.align(Alignment.Center), text = label)
}
```

| Parameters |
|---|---|
| `transferData: (https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset) -> https://developer.android.com/reference/kotlin/androidx/compose/ui/draganddrop/DragAndDropTransferData?` | A function that receives the current offset of the drag operation and returns the `https://developer.android.com/reference/kotlin/androidx/compose/ui/draganddrop/DragAndDropTransferData` to be transferred. If null is returned, the drag and drop transfer won't be started. |

### Modifier.dragAndDropSource

android 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/draganddrop/LegacyDragAndDropSource.android.kt+function:dragAndDropSource) Added in [1.6.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.6.0) Deprecated in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
@ExperimentalFoundationApi
fun Modifier.[dragAndDropSource](https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1,kotlin.coroutines.SuspendFunction1))(
    drawDragDecoration: DrawScope.() -> Unit,
    block: suspend DragAndDropSourceScope.() -> Unit
): Modifier
```

> [!CAUTION]
> **This function is deprecated.**   
> Replaced by overload with a callback for obtain a transfer data,start detection is performed by Compose itself, use this instead:
>
> ```kotlin
> Modifier.dragAndDropSource(transferData)
> ```

A Modifier that allows an element it is applied to to be treated like a source for drag and drop operations.

Learn how to use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1,kotlin.coroutines.SuspendFunction1)` while providing a custom drag shadow:

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.draganddrop.dragAndDropSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

Box(
    modifier =
        Modifier.size(56.dp).background(color = color).dragAndDropSource(
            drawDragDecoration = { drawRect(color) }
        ) { _ ->
            color.toDragAndDropTransfer()
        }
)
```

| Parameters |
|---|---|
| `drawDragDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | provides the visual representation of the item dragged during the drag and drop gesture. |
| `block: suspend https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | A lambda with a `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope` as a receiver which provides a `https://developer.android.com/reference/kotlin/androidx/compose/ui/input/pointer/PointerInputScope` to detect the drag gesture, after which a drag and drop gesture can be started with `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/DragAndDropSourceScope#startTransfer(androidx.compose.ui.draganddrop.DragAndDropTransferData)`. |

### Modifier.dragAndDropSource

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/draganddrop/DragAndDropSource.kt+function:dragAndDropSource) Added in [1.8.0](https://developer.android.com/jetpack/androidx/releases/compose-foundation#1.8.0)

```
fun Modifier.dragAndDropSource(
    drawDragDecoration: DrawScope.() -> Unit,
    transferData: (Offset) -> DragAndDropTransferData?
): Modifier
```

A `https://developer.android.com/reference/kotlin/androidx/compose/ui/Modifier` that allows an element it is applied to be treated like a source for drag and drop operations.

Learn how to use `https://developer.android.com/reference/kotlin/androidx/compose/foundation/draganddrop/dragAndDropSource.modifier#(androidx.compose.ui.Modifier).dragAndDropSource(kotlin.Function1)` while providing a custom drag shadow:

```kotlin
import androidx.compose.foundation.background
import androidx.compose.foundation.draganddrop.dragAndDropSource
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.size
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

Box(
    modifier =
        Modifier.size(56.dp).background(color = color).dragAndDropSource(
            drawDragDecoration = { drawRect(color) }
        ) { _ ->
            color.toDragAndDropTransfer()
        }
)
```

| Parameters |
|---|---|
| `drawDragDecoration: https://developer.android.com/reference/kotlin/androidx/compose/ui/graphics/drawscope/DrawScope.() -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | provides the visual representation of the item dragged during the drag and drop gesture. |
| `transferData: (https://developer.android.com/reference/kotlin/androidx/compose/ui/geometry/Offset) -> https://developer.android.com/reference/kotlin/androidx/compose/ui/draganddrop/DragAndDropTransferData?` | A function that receives the current offset of the drag operation and returns the `https://developer.android.com/reference/kotlin/androidx/compose/ui/draganddrop/DragAndDropTransferData` to be transferred. If null is returned, the drag and drop transfer won't be started. |