---
title: "onDrag(_:preview:)"
framework: swiftui
role: symbol
role_heading: Instance Method
path: "swiftui/view/ondrag(_:preview:)"
---

# onDrag(_:preview:)

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

## Declaration

```swift
nonisolated func onDrag<V>(_ data: @escaping () -> NSItemProvider, @ContentBuilder preview: () -> V) -> some View where V : View

```

## Parameters

- `data`: A closure that returns a single doc://com.apple.documentation/documentation/Foundation/NSItemProvider that represents the draggable data from this view.
- `preview`: A doc://com.apple.SwiftUI/documentation/SwiftUI/View to use as the source for the dragging preview, once the drag operation has begun. The preview is centered over the source view.

## Return Value

Return Value A view that activates this view as the source of a drag-and- drop operation, beginning with user gesture input.

## Discussion

Discussion Applying the onDrag(_:preview:) modifier adds the appropriate gestures for drag and drop to this view. When a drag operation begins, a rendering of preview is generated and used as the preview image. To customize the lift preview, shown while the system transitions to show your custom preview, apply a contentShape(_:_:eoFill:) with a dragPreview kind. For example, you can change the preview’s corner radius or use a nested view as the preview. To use Transferable types directly and access a richer feature set — including multi-item drag via dragContainer(for:in:_:) — use draggable(_:) instead.

## See Also

### Moving items using item providers

- [itemProvider(_:)](swiftui/view/itemprovider(_:).md)
- [onDrag(_:)](swiftui/view/ondrag(_:).md)
- [onDrop(of:isTargeted:perform:)](swiftui/view/ondrop(of:istargeted:perform:).md)
- [onDrop(of:delegate:)](swiftui/view/ondrop(of:delegate:).md)
- [DropDelegate](swiftui/dropdelegate.md)
- [DropProposal](swiftui/dropproposal.md)
- [DropOperation](swiftui/dropoperation.md)
- [DropInfo](swiftui/dropinfo.md)
