I have been trying to implement drag and drop on a List in SwiftUI. What I'm trying to do is drag a row on a List and drop it on a row in the SAME List, much like the Reminders app on iOS.
Note: It's important to note that I'm not trying to rearrange the list but rather make the dropped item a "child" of that row.
import SwiftUI
import UniformTypeIdentifiers
struct Item: Identifiable {
let id = UUID()
let title: String
}
struct EditListView: View {
@State private var items: [Item] = [
Item(title: "Apple"),
Item(title: "Banana"),
Item(title: "Papaya"),
Item(title: "Mango")
]
var body: some View {
VStack {
List {
ForEach(items) { item in
Text(item.title)
}
.onDrop(of: [UTType.text], delegate:dropDelegate() )//doesn't work
.onDrag{
NSItemProvider(item: .some(URL(string: "item")! as NSSecureCoding), typeIdentifier: String() )
}
}
Text("Drop Item Here..")
.fontWeight(.heavy)
.onDrop(of: [UTType.text], delegate:dropDelegate() )//works
}
}
}
class dropDelegate: DropDelegate {
func performDrop(info: DropInfo) -> Bool {
print("drop success")
return true
}
}
Dropping on the Text works.
Dropping on the list row fails.

