Drag and Drop operations fail when executed from within the same List

I am working on creating a file viewer to browse a network directory as a way to introduce myself to iOS app development, and was trying to implement a feature that would allow users to drag and drop both files and folders onto another folder inside of the app to move items around. However, it seems that if the View that is set to draggable, and then the view that is set as the Drop Destination is in the same List, then the Drop Destination will not detect when the draggable view has been dropped onto it. Here is the structure of my code:

List {
            Section(header: Text("Folders")) {
                ForEach($folders, id: \.id) { $folder in
                    FolderCardView()
                        .onDrop(of: [UTType.item], isTargeted: $fileDropTargeted, perform: { (folders, cgPoint) -> Bool in
                            print("Dropped")
                            return true
                        })
                }
            }
            Section(header: Text("Files")) {
                ForEach($files, id: \.id) { $file in
                        FileCardView()
                        .onDrag({
                            let folderProvider = NSItemProvider(object: file)
                            return folderProvider
                        })
                }
            }
        }

I have verified that the issue comes down to the list, because if I move both of the ForEach loops out on their own, or even into their own respective lists, the code works perfectly. I have not only tested this with the older .onDrop and .onDrag modifiers as shown above, but also the newer .draggable and .dropDestination modifiers, and the result is the same.

Does anyone know if this is intended behavior? I really like the default styling that the List element applies to other elements within, so I am hoping that it might just be a bug or an oversight. Thanks!

Does onMove() cover what you are trying to achieve here?

@julia_brockovich Thanks for the reply! I did try your suggestion, but onMove seems to mostly be for rearranging list items. What I need is a little more complex than that. I need to be able to know that the what the user dragged and what was dragged onto. onMove does give me the indices as closure variables after the user has released the list element, so I could theoretically get something going, but I don't think it would make for the best user experience, compared to using the onDrop APIs.

Hi, I face the same issue. I wrote here a short code for it: https://stackoverflow.com/questions/79129283/swiftui-drag-and-drop-in-the-same-list

Drag and Drop operations fail when executed from within the same List
 
 
Q