Contents

DragConfiguration

The behavior of the drag, proposed by the dragging source. A value that describes the drag operations a drag source supports.

Declaration

struct DragConfiguration

Overview

Pass a DragConfiguration to the dragConfiguration(_:) modifier to declare which operations — copy, move, or delete — a view supports when it is dragged.

Opting in to move

By default, only copy is allowed. To support drag-to-move, where the source item is removed after a successful drop, initialize with allowMove: true:

.dragConfiguration(DragConfiguration(allowMove: true))

On macOS, users can override the proposed operation during a drag by holding modifier keys:

  • ⌥ (Option) proposes copy.

  • ⌘ (Command) proposes move.

  • ⌥ + ⌘ proposes alias.

Modifier keys only take effect when the source supports the corresponding operation. For example, holding ⌘ has no effect unless allowMove is true.

Responding to the performed operation

DragConfiguration communicates suggested operations to drop destinations, but each destination chooses which operation to perform. To detect which operation was ultimately performed — for example, to remove the source item after a successful move — observe the drag session using onDragSessionUpdated(_:):

.dragConfiguration(DragConfiguration(allowMove: true))
.onDragSessionUpdated { session in
    if session.phase == .ended(.move) {
        removeItem()
    }
}

Topics

Structures

Initializers

Instance Properties

See Also

Configuring drag-and-drop behavior