SwiftUI 列表移动和 select 行

SwiftUI list Move and select rows

我正在尝试对列表行执行两个操作,如下图所示

第一个是移动并重新排列它,通过使用“ForEach”和“.onMove”完成,第二个是使用“List”和“selection”进行多选行选项这样也完成了。 问题是我无法将这两个选项结合起来,因为其中一个使用“List”,另一个使用“ForEach”,当我这样做时,会发生意外行为。 那么有没有人可以帮我解决这个问题。

这里是一个可能的解决方案,如何结合 Selection 和 onMove。

struct ContentView : View {
        
    @State var items = ["Dave", "Tom", "Jeremy", "Luke", "Phil"]
    
    @State var selectedItems : Set<String> = Set<String>()
    
    var body : some View {
        NavigationView {
            List(selection: $selectedItems) {
                ForEach(items, id:\.self) { item in
                    Text(item).tag(item)
                }.onMove(perform: move)
            }
            .navigationBarItems(trailing: EditButton())
        }
    }
    
    func move(from source: IndexSet, to destination: Int) {
        items.move(fromOffsets: source, toOffset: destination)
    }
}

在我的应用程序中,davidev 的回答有点奏效。它允许选择多行,并且在移动开始时出现句柄。但是,它不允许将选择放置到新位置(即,没有移动)。仍在研究为什么它实际上不会移动。