SwiftUI Drag image OK on macOS but KO on iPadOS

Hello.


I am implementing a SwiftUI Drag and Drop application which runs fine on both macOX and IpadOS.


The only problem I have is that on iPadOS, the Dragged image is rendered just as an empty rectangle, while on macOS I have a correct dragged image.


The body of the view from which the items are dragged is :


var body: some View {

HStack {

ForEach( libraryRowItems, id: \.self) { thelibraryItem in

libraryItemView(item: thelibraryItem)

.onDrag {

return NSItemProvider(object: NuageIdentifier(identifier:thelibraryItem.id))

}

}

}

}


and the body for libraryItemView :


var body: some View {

let topColorGradient = Color(Color.RGBColorSpace.sRGB, red: 0.298, green: 0.301, blue: 0.301);

let bottomColorGradient = Color(Color.RGBColorSpace.sRGB, red: 0.235, green: 0.239, blue: 0.239);

return ZStack {

RoundedRectangle(cornerRadius: 5)

.fill(LinearGradient(gradient: Gradient(colors: [topColorGradient, bottomColorGradient]), startPoint: .top, endPoint: .bottom))

Text("\(text)").foregroundColor(.white).font(.custom("STIX2Math", size: fontSize))

}

.frame(width:50, height: 33)

}


On my late 2013 mac everything is ok

On my Ipad 5th generation the dragged iage is just a rectangle.

My mac is unable to run it on a Simulator (seems to be too slow now) to see if it could depends on the generation of the device.


I am the only one to encounter this problem ?


Regards



Chris Tof

Accepted Reply

This is fixed in iOS 14

Replies

You are not the only one. I haven't tested on my iPad yet (still 13.3) but I am experiencing the same empty rectange on my iPhone 11 (13.4.1). Others have experienced a similar bug on the mac, https://swiftui-lab.com/drag-drop-with-swiftui/ .The preview image is rendered properly in the iOS simulator though for me. You can submit a bug report in the Feedback App.

Actually a simple application showing just a draggable image has the problem on my iPad. It looks like this works from the simulator but not on ios devices. I submitted a bug report.
Thanks for your feedback.

This is fixed in iOS 14