Consider following simplified code for an element that can be dragged
HStack {
Icon(icon: .iconDrag)
Text("Title")
Spacer()
}
.padding(16)
.onDrag {
return NSItemProvider(object: id.uuidString as NSString)
}
This results in behavior below, where once drag starts preview element is shown, but it is a fraction of a size from original element and has transparency.
I tried adding preview : {} to onDrag with same original element duplicate, but it's size is still inaccurate and it has transparency. Is there a way to extend a preview somehow (say with uikit) so that it remains exactly the same as original element? I believe there is a maximum width of preview element at which point it starts shrinking down perhaps?

You could try implementing a custom drag preview by adopting the
UIDragInteractionDelegatein aUIViewRepresentablethat wraps your SwiftUI view: by usingUIDragPreviewand setting the preview provider of theUIDragItem, you can specify a custom view for the preview that will be the same size as the original view and without any transparency.This is inspired from
Client/Frontend/TabChrome/TopBar/LocationView/LocationViewTouchHandler.swiftThe key part in the code which should allow for a "Same size, no transparency" drag preview is the
previewProviderclosure ofUIDragItem.The
UIDragPreviewinitializer is passed theinteraction.view, which is the UIView that was created by theUIHostingControllerwith the SwiftUI view inside of it. Since you are using the original view itself for the preview, it should have the same size as the original.