draggable

Activates this view as the source of a drag and drop operation.

View ModifieriOS 16.0+macOS 13.0+

Overloads

7 ways to call compose().draggable(). Each is one SwiftUI overload, picked by the arguments you pass.

React
compose().draggable<T>(payload: T)
Swift
nonisolated func draggable<T>(
    _ payload: @autoclosure @escaping () -> T
) -> some View
where T : Transferable

Parameters

  • payload*T

    A 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 draggable(_:) 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.

instance or a value conforming to doc://com.apple.documentation/documentation/coretransferable/transferable that represents the draggable data from this view.

See also

More in Drag and drop.