onMove with hierarchical List or OutlineGroup

Hey everyone, is it possible to use the onMove drag and drop functionally that a flat list gets for free? I can't seem to get it working for hierarchical lists. I have a tree model that can be arbitrarily deep.

Thanks

Hi @chipotleboy ,

Unfortunately this is not built-in behavior. You can attempt to work around it by doing:

List(items, editActions: .move) { item in 
   DisclosureGroup(item.description) {
        ForEach(item.children ?? [], id: \.self) { child in 
             Text(child.description)
        }
            .onMove { fromIndexes, to in
                            item.children?.move(
                                fromOffsets: fromIndexes,
                                toOffset: to
                            )
                        }
  }
}

This is only possible with a single level of list though, it's going to be much much more difficult with an arbitrarily deep hierarchy.

Figured I'd leave that there in case you want to experiment, but I'd really appreciate it if you have a chance to file an enhancement report asking for this behavior at https://feedbackassistant.apple.com and paste the FB number here. That's definitely a requested feature so the more requests we have, the better!

Thanks,

Sydney

onMove with hierarchical List or OutlineGroup
 
 
Q