Compose Modifier

dragAndDropSource

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

DragAndDropSourceWithColoredDragShadowSample

@Sampled
@Composable
fun DragAndDropSourceWithColoredDragShadowSample(color: Color) {
    Box(
        modifier =
            Modifier.size(56.dp).background(color = color).dragAndDropSource(
                drawDragDecoration = { drawRect(color) }
            ) { _ ->
                color.toDragAndDropTransfer()
            }
    )
}

TextDragAndDropSourceSample

@Sampled
@Composable
fun TextDragAndDropSourceSample(modifier: Modifier) {
    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)
    }
}
Jetpack Compose beyond MaterialFree components, screens and templates for apps that don’t look like Google’s. Copy them into your app, or let your coding agent add them.Browse for free

Content updated: