I'm using a DropDelegate to handle drag/drop in SwiftUI on iOS. I have a simplified sample app here:
https://gist.github.com/jhaungs/6ac2c3a34309b7115eef40925c27b1ab
The problem seems to be an interaction between the SwiftUI framework and my code. If you attempt to load the itemProvider from DropInfo on the dropEntered or dropUpdated call, the system never calls the loadData function on the model; but somehow the same code works fine when it's called from performDrop.
If you set a breakpoint or add a print statement in getItem, you can see that itemProviders is never empty; it has exactly one item provider of the correct type (utf8 text). But calling loadObject on it only invokes loadData, when getItem is called from performDrop. So there's some opaque internal state mediating the data transfer.
Any ideas why this is not consistent? It seems like a bug to me.
In dropEntered and dropUpdated, I want to know what I'm dragging so I can do stuff like highlight it, or animate it, or perhaps even forbid or cancel the drop, but there's no feedback.
I could be doing this all wrong, too. I've spent quite a bit of time on it, and this is the closest I've gotten it to working. It's not clear that one DropDelegate per item is correct or wise. The documentation is sorely lacking, especially working examples.
There was a suggestion on another StackOverflow question to assign the current item to a viewModel variable in the onDrag, but this creates race conditions where the variable is not consistently set or cleared.
SwiftUI | Using onDrag and onDrop to reorder Items within one single LazyGrid?