Hello, I'm trying to accept drags from outside my app to create a new row in a list.
I've observed .onInsert
not getting called in this scenario and I'm curious if it's 100% not possible, or if there's an obscure view modifier that I am missing.
Thank you.
struct ContentView: View {
@State var data = ["One", "Two", "Three"]
var body: some View {
HStack {
List {
ForEach(data, id: \.self) { item in
Text(item)
}
.onMove(perform: { indices, newOffset in
data.move(fromOffsets: indices, toOffset: newOffset)
})
.onInsert(of: [UTType.plainText], perform: { index, items in
// WORKS
data.insert("new", at: index)
})
.onInsert(of: [UTType.data], perform: { index, items in
// Never called
data.insert("OUTSIDE", at: index)
})
}
Text("DragMe")
.onDrag {
return NSItemProvider(item: "DragMe" as NSString, typeIdentifier: UTType.plainText.identifier)
}
}
}
}