0

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.

Jonas
  • 21
  • 1
  • 3
  • The problem maybe in Playgrounds, as it works well for me on real ios-15 devices and macos 12 Catalyst using Xcode 13.2. – workingdog support Ukraine Dec 12 '21 at 07:10
  • Thanks for your answer, i used it however in an app deployed on macOS 12 and it does not work on that either with the same problem. I just extracted the relevant part for playgrounds, but the issue is the same in my larger codebase. If anyone thinks that is relevant i'd be happy to post more code. – Jonas Dec 12 '21 at 12:11
  • If you want to use it in a macos 12 only environment, place the `.listStyle(.sidebar)` inside the `List`, just after the `.swipeActions`. Seems to work for me. – workingdog support Ukraine Dec 12 '21 at 12:23
  • The swipe actions then work, however the listStyle is then not applied. As i said, not applying any listStyle resolves the problem, but i would like the list to be translucent and the .sidebar listStyle seems to be the only way of doing that – Jonas Dec 12 '21 at 13:04
  • It doesn't seem to work with `.sidebar` style as of macOS 13, works with eg. `.inset` style. – Marcin Jan 05 '23 at 13:40

0 Answers0