onDrop
Defines the destination of a drag and drop operation that handles the dropped content with a closure that you specify.
Overloads
2 ways to call compose().onDrop(). Each is one SwiftUI overload, picked by the arguments you pass.
compose().onDrop({
of: string[],
isTargeted: Binding<boolean> | null,
perform: { returns: boolean; perform?: (providers: string[], location: CGPoint) => void; },
})nonisolated func onDrop(
of supportedContentTypes: [UTType],
isTargeted: Binding<Bool>?,
perform action: @escaping ([NSItemProvider], CGPoint) -> Bool
) -> some ViewParameters
options.of*string[]options.isTargeted*Binding<boolean> | nullA binding that updates when a drag and drop operation enters or exits the drop target area. The binding's value is
truewhen the cursor is inside the area, andfalsewhen the cursor is outside.options.perform*{ returns: boolean; perform?: (providers: string[], location: CGPoint) => void; }
Return value
A view that provides a drop destination for a drag operation of the specified types.
Discussion
The drop destination is the same size and position as this view.
Make sure to start loading the contents of NSItemProvider instances
within the scope of the action closure. Do not perform loading asynchronously
on a different actor. Loading the contents may finish later, but it must start here.
For security reasons, the drop receiver can access the dropped payload only before
this closure returns.
To use Transferable types directly and access a richer feature
set — including support for DropSession — use
View.dropDestination(for:isEnabled:action:) instead.
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.
- onDragActivates this view as the source of a drag and drop operation.
- onDragSessionUpdatedSpecifies an action to perform on each update of an ongoing dragging operation activated by draggable(:) or anther drag modifiers.
- 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.