I'm trying to add SwipeActions to a List in SwiftUI. It is working as expected, but as soon as i give the list the .sidebar
listStyle it stops working. Here is a minimal code example showing this problem (can be used in Swift Playgrounds):
import SwiftUI
import PlaygroundSupport
struct ContentView: View {
let strings = ["hello", "there"]
var body: some View {
List(strings, id: \.self) { str in
Text(str)
.swipeActions {
Button { print("clicked on swipe action") } label: { Label("Delete", systemImage: "trash") }
}
}
.listStyle(.sidebar) // <-- without applying this, the swipeActions work.
}
}
PlaygroundPage.current.setLiveView(ContentView())
I searched Google and Stackoverflow but did not find any answers. It seems very unintuitive that different "styles" also have different behaviour. Am i missing something? Wrapping the Text
in a ForEach
loop does not change anything either.