SwiftUI full screen transparent button

Viewed 729

I try to add full screen transparent button:

Button(action: {
       // my action
}) {
    Rectangle()
     .opacity(0)
}

But in case .opacity() is less than 0.1 button action stop working. How to implement full screen transparent button?

Tested on iOS 14.3(Sim), iOS 14.2(iPhone X), Xcode 12.3

1 Answers

Here is possible solution. Tested with Xcode 12.1 / iOS 14.1

struct DemoClearButton: View {
    var body: some View {
        Color.clear
            .contentShape(Rectangle())
            .onTapGesture {
                print(">> transparent tapped")
            }
    }
}

Note: probably in place of usage you'd wanted to add .edgesIgnoringSafeArea(.all)

Related