Overloads
2 ways to call compose().onDrag(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().onDrag(data: string)nonisolated func onDrag(
_ data: @escaping () -> NSItemProvider
) -> some ViewParameters
data*stringA closure that returns a single
Return value
A view that activates this view as the source of a drag and drop operation, beginning with user gesture input.
Discussion
Applying the onDrag(_:) modifier adds the appropriate gestures for
drag and drop to this view. When a drag operation begins, a rendering of
this view is generated and used as the preview image.
To customize the default preview, apply a
View.contentShape(_:_:eoFill:) with a
ContentShapeKinds.dragPreview kind. For example, you can change the
preview's corner radius or use a nested view as the preview.
If you want to show a different preview, you can use
View.onDrag(_:preview:).
To use Transferable types directly and access a richer feature
set — including multi-item drag via
View.dragContainer(for:in:_:) — use View.draggable(_:)
instead.
doc://com.apple.documentation/documentation/Foundation/NSItemProvider that represents the draggable data from this view.
See also
More in Events and lifecycle.
- onAppearAdds an action to perform before this view appears.
- onChangeAdds a modifier for this view that fires an action when a specific value changes.
- onContinueUserActivityRegisters a handler to invoke in response to a user activity that your app receives.
- onContinuousHoverAdds an action to perform when the pointer enters, moves within, and exits the view's bounds.
- onDisappearAdds an action to perform after this view disappears.
- onDragSessionUpdatedSpecifies an action to perform on each update of an ongoing dragging operation activated by draggable(:) or anther drag modifiers.
- onDropDefines the destination of a drag and drop operation that handles the dropped content with a closure that you specify.
- onDropSessionUpdatedSpecifies an action to perform on each update of an ongoing drop operation activated by dropDestination(:) or other drop modifiers.
- onGeometryChangeAdds an action to be performed when a value, created from a geometry proxy, changes.
- onHingeChangeAdds an action to perform when the hinge context of the view hierarchy changes.
- onHoverAdds an action to perform when the user moves the pointer over or away from the view's frame.
- onInteractiveResizeChangeAdds an action to perform when the enclosing window is being interactively resized.