I've seen an earlier post on this with no response.
Has anyone else gotten a response from Apple or have run across a solution to onDrag lagging when released to drop on iOS 18? I've been chasing this for a week thinking it was me and then I woke up and started testing it on older iOS versions and the issue goes away. I happens on simulators and real phones. A little more digging and I'm seeing occasional chatter about this .5 to 1 second delay.
Here's a code example that reproduces it:
import SwiftUI
import UniformTypeIdentifiers
struct ContentView: View {
@State private var draggableText: String = "Move this"
var body: some View {
VStack(spacing: 80) {
DraggableItem(content: $draggableText)
DropZone {
Text("Place Here!")
.font(.headline)
.foregroundColor(.white)
}
.frame(width: 150, height: 150)
.background(Color.green)
.cornerRadius(12)
}
.padding()
}
}
struct DraggableItem: View {
@Binding var content: String
var body: some View {
Text(content)
.frame(width: 120, height: 120)
.background(Color.red)
.foregroundColor(.white)
.cornerRadius(8)
.onDrag {
NSItemProvider(object: NSString(string: content))
}
}
}
struct DropZone<Content: View>: View {
var content: () -> Content
var body: some View {
ZStack {
content()
}
.onDrop(of: [UTType.text], delegate: DropHandler())
}
}
struct DropHandler: DropDelegate {
func performDrop(info: DropInfo) -> Bool {
// Add logic to handle the drop
print("Item dropped!")
return true
}
}
#Preview {
ContentView()
}