Consider the following example of a List view containing sections of rows.
import SwiftUI struct ListSectionView: View { @State private var sectionHeaders = ["section1", "section2", "section3"] var body: some View { List { ForEach(sectionHeaders, id: \.self) { sectionHeader in Section(header: Text(sectionHeader)) { Text("1") Text("2") Text("3") } } .onMove { indices, newOffset in // ... } } } }
I would like to reorder the sections within the list by dragging the respective section header to its new position in the list - similar to moving individual rows via onMove-dragging but with the sections instead of the rows.
The above approach does not work. It "activates" moving the rows and then the .onMove code acts on those. The sections themselves are not moved.
How can I move/reorder the sections within the list?
Thanks.