DragConfiguration
The behavior of the drag, proposed by the dragging source. A value that describes the drag operations a drag source supports.
Declaration
type DragConfiguration = { allowMove: boolean; } | { operationsWithinApp?: DragConfigurationOperationsWithinApp; operationsOutsideApp?: DragConfigurationOperationsOutsideApp; };struct DragConfigurationType 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.
- AutomaticHoverEffectThe default hover effect based on the surrounding context.
- CustomHoverEffectA type that represents how a view should change when a pointer hovers over a view, or when someone looks at the view.
- DragConfigurationOperationsOutsideAppDescribes the suggested drag operations to other applications.
- DragConfigurationOperationsWithinAppDescribes the drag operations suggested to destinations within the app.
- DragGestureA dragging motion that invokes an action as the drag-event sequence changes.
- DragGestureValueThe attributes of a drag gesture.
- DragSessionDescribes the ongoing dragging session.
- DragSessionIDThe identifier of a drag session.
- DragSessionPhaseThe phase of the current drag session
- GestureAn instance that matches a sequence of events to a gesture, and returns a stream of values for each of its states.
- GestureChainGesture with chained calls: SwiftUI.Gesture.exclusively(...).
- GestureInputKindsAn option set that specifies which input kinds a gesture should recognize.