iosswiftui

swipeActions button in List cannot be pressed when there is a gesture/onTapGesture on List


Based on my research, this appears to be a SwiftUI bug related to tap localization in List.
I am trying to find a way that I can tap in empty space in List and it unfocuses the textfield but it override with Gesture in swipeAction that make the button untappable.

struct ContentView: View {
    var body: some View {
        List {
            Text("Hello, World!")
                .swipeActions {
                    Button(role: .destructive) {
                        print("Tapped Delete button")
                    } label: {
                        Label("Delete", systemImage: "trash")
                    }
                }
        }
        .onTapGesture {
            print("Tapped List")
        }
    }
}

I am also trying to use LongPressGesture(minimumDuration: 0.001) hack but since the swipeAction button does not receive custom gestures, it also can't be done.


Solution

  • It seem like the problem exist in older version Xcode 15.4, target iOS-17.5 and macOS Sonoma 14.5. Currently i updated to the latest version macOS Sequoia 15.4, using Xcode 16.3, target iOS-18.4 and it got fixed.