Clipped Image calls TapAction outside frame Clipped Image calls TapAction outside frame swift swift

Clipped Image calls TapAction outside frame


Update

I updated my answer. This is the proper way of doing it. There is a modifier called contentShape() that you can use to define the hit test area:

import SwiftUIstruct ContentView: View {    @State private var tapped = false    var body: some View {        Image(systemName: "circle.fill")            .resizable()            .aspectRatio(contentMode: .fill)            .frame(height: 200, alignment: .center)            .presentation(tapped ? Modal(Image(systemName: "photo")) : nil)            .clipped()            .cornerRadius(10)            .border(Color.black, width: 2, cornerRadius: 10)            .contentShape(TapShape())            .tapAction {                self.tapped.toggle()            }    }    struct TapShape : Shape {        func path(in rect: CGRect) -> Path {            return Path(CGRect(x: 0, y: 0, width: rect.width, height: 200))        }    }}