Drag drop nested list in swiftui

Hi, I managed to have a nested list in swiftui 3 (with foreach) and drag and drop to reorder the list when I enter the built-in edit mode.

Problems / limitation when dragging / dropping a list item from edit mode:

  • I can't change its nesting level: for example, if I drag an item that is 3 nested levels deep, I can't seem to be able to drop it on let's say level 1.
  • When an item has children, and they are expanded, if I drag the father, the children will not follow.
  • I can't drag from one section, and drop on another.

What are the solutions to circumvent those problems? Is there built-in way to do it, if not, is it even possible without resorting to UIKit?

Interestingly, I've been toying around with exactly this kind in UIKit. Things are still a mess. I think it should be completely doable in SwiftUI, in either case it's most likely a matter of defining a set of custom methods on your nesting view's behavior correctly. I am not there yet with my UIKit implementation. But if you squint and are generous, you can see how it kind of works. I've attached a gif.

I've been surprised I couldn't find some existing work on this. I'm sure someone's done it. Searching for it led me to this post of yours.

Drag drop nested list in swiftui
 
 
Q