Post

Replies

Boosts

Views

Activity

How to create swipeActions for a multi-level list?
How do I create swipeActions for a multi-level (recursive) list? With a simple list I can do this, and everything works just fine: struct ContentView: View { @State private var data = ["One", "Two", "Three"]     var body: some View {         List(data, id: \.self) { item in             Text(item)                 .swipeActions(edge: .trailing, allowsFullSwipe: true) {                      Button("Delete", role: .destructive) {                          data.removeAll { $0 == item }                      }                  }         }     } } But when I try the same with a multi-level list, I cannot swipe any of its rows (nothing happens when I try to swipe): struct MyData: Hashable {     let value: String     var children: [MyData]? = nil } struct ContentView: View {     @State private var data: [MyData] = [         .init(             value: "One",             children: [                 .init(value: "Two"),                 .init(                     value: "Three",                     children: [                         .init(value: "Four"),                         .init(value: "Five")                     ]                 )             ]         )     ]     var body: some View {         List(data, id: \.self, children: \.children) { item in             Text(item.value)                 .swipeActions(edge: .trailing, allowsFullSwipe: true) {                     Button("Delete", role: .destructive) {                         data.removeAll { $0 == item }                     }                 }         }     } } How to make this work?
0
0
237
Dec ’22