I have a view placed somewhere in my ContentView. I want to be able to drop images onto it. So I've added and .onDrop to it. In UIKit, I would use universeView.convert(point, to: targetView). How do I do this in SwiftUI?
Example utility could be to draw the thumbnail of the dropped image where it was dropped on the orange square
struct ContentView: View {
@State var isTargeted: Bool = false
var body: some View {
VStack {
Spacer()
.frame(width: 600, height: 200)
.background(Color.yellow.opacity(0.3))
HStack {
Spacer()
.frame(width: 200, height: 200)
.background(Color.yellow.opacity(0.3))
Spacer()
.frame(width: 200, height: 200)
.background(Color.orange)
.onDrop(of: [ "public.image"], isTargeted: $isTargeted, perform: { (providers, point) -> Bool in
print(point) // i.e. (x:336.0, y:486.5)
// but I want it in the context of this views frame
// let bodyView: View
// let targetView: View
// let thePoint = bodyView.convert(point, to: targetView)
return true
})
Spacer()
.frame(width: 200, height: 200)
.background(Color.yellow.opacity(0.3))
}
.frame(width: 600, height: 200)
Spacer()
.frame(width: 600, height: 200)
.background(Color.yellow.opacity(0.3))
}
.frame(width: 600, height: 600)
}
}