You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/drag-and-drop/overview.md
+29-1Lines changed: 29 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,8 @@ Compose DND provides a declarative API for adding drag and drop functionality to
4
4
5
5
-`DragAndDropState` -- Holds the state for all drag and drop operations.
6
6
-`DragAndDropContainer` -- A container that wraps all draggable items and drop targets.
7
-
-`DraggableItem` -- Makes a composable draggable.
7
+
-`DraggableItem` composable -- Makes a composable draggable (wrapper approach).
8
+
-`draggableItem` modifier -- Makes a composable draggable (modifier approach, less boilerplate).
8
9
-`dropTarget` modifier -- Marks a composable as a drop target.
9
10
10
11
## Creating DragAndDropState
@@ -91,6 +92,32 @@ Inside `DraggableItem`'s content lambda, you have access to `DraggableItemScope`
91
92
-`key: Any` -- The key of this item.
92
93
-`isDragging: Boolean` -- Whether this item is currently being dragged.
93
94
95
+
## draggableItem Modifier
96
+
97
+
As an alternative to the `DraggableItem` composable wrapper, you can use the `Modifier.draggableItem` modifier directly. This reduces boilerplate by eliminating the wrapper composable.
98
+
99
+
```kotlin
100
+
val isDragging = dragAndDropState.isDragging("item-1")
The `draggableItem` modifier accepts the same parameters as `DraggableItem` (except `content`, which is the composable it's applied to). The `draggableContent` parameter is required — it defines what the drag shadow looks like.
118
+
119
+
Use `DragAndDropState.isDragging(key)` to check if a specific item is being dragged.
120
+
94
121
## Drop Target
95
122
96
123
Use the `Modifier.dropTarget` extension to mark any composable as a drop target.
@@ -127,6 +154,7 @@ Box(
127
154
|`dropAlignment`|`Alignment`|`Alignment.Center`| Alignment of the dropped item within the target for the drop animation. |
128
155
|`dropOffset`|`Offset`|`Offset.Zero`| Additional offset for the drop animation position. |
129
156
|`dropAnimationEnabled`|`Boolean`|`true`| Whether to animate the drop. If `false`, the drop callback fires immediately. |
157
+
|`canDrop`|`Boolean`|`true`| Whether this target accepts drops. When `false`, dragged items cannot hover over or be dropped on this target. Can read `state.draggedItem?.data` to validate dynamically. |
130
158
|`onDrop`|`(DraggedItemState<T>) -> Unit`|`{}`| Called when an item is dropped on this target. |
131
159
|`onDragEnter`|`(DraggedItemState<T>) -> Unit`|`{}`| Called when a dragged item enters this target. |
132
160
|`onDragExit`|`(DraggedItemState<T>) -> Unit`|`{}`| Called when a dragged item exits this target. |
Copy file name to clipboardExpand all lines: docs/drag-and-drop/reorder.md
+45Lines changed: 45 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -204,3 +204,48 @@ private fun ItemCard(
204
204
205
205
!!! tip
206
206
Use `graphicsLayer { alpha = if (isDragging) 0f else 1f }` to hide the original item while it is being dragged, so only the drag shadow is visible.
207
+
208
+
## reorderableItem Modifier
209
+
210
+
As an alternative to the `ReorderableItem` composable wrapper, you can use the `Modifier.reorderableItem` modifier. This combines `draggableItem` and `dropTarget` into a single modifier and reduces boilerplate.
When using the modifier API, use `rememberDragAndDropState` and `DragAndDropContainer` directly instead of `rememberReorderState` and `ReorderContainer`. Use `DragAndDropState.isDragging(key)` to check drag state.
0 commit comments