DragConfiguration

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

StructureiOS 26.0+macOS 26.0+visionOS 26.0+DragConfiguration in SwiftUI

Declaration

React
type DragConfiguration = { allowMove: boolean; } | { operationsWithinApp?: DragConfigurationOperationsWithinApp; operationsOutsideApp?: DragConfigurationOperationsOutsideApp; };
Swift
struct DragConfiguration

Type methods

Overview

Pass a DragConfiguration to the View.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 View.onDragSessionUpdated(_:):

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

From Apple’s SwiftUI documentation. Code samples there are Swift.

Used by

See also

More in Gestures and input.