The code below illustrates my problem which is apparent using XCode 14.01 with Simulator for IPad Pro 12.9 2nd generation with IOS 16.0
It shows that the part of the green triangle which is outside .border does not detect onTapGesture.
How would I amend the code so that all the green triangle detects onTapGesture?
This code is just to illustrate the problem.
Thank you in advance for any ideas
import SwiftUI
struct TestTapArea{
let x = 500.0
let y = 700.0
let oX = 800.0
let oY = -300.0
func path(_ choice: String) -> some View {
var corners: [CGPoint] = []
var color: Color = .black
if choice == "red" {
corners = [CGPoint(x: 100.0, y: 100.0), CGPoint(x: x, y: 100.0), CGPoint(x: x, y: y) ]
color = Color.red
}
if choice == "green" {
corners = [CGPoint(x: oX , y: oY), CGPoint(x: oX + x, y: oY), CGPoint(x: oX + x, y: oY + y) ]
color = Color.green
}
return
myPath(corners, color)
.onTapGesture {
print(choice)
}
func myPath(_ corners: [CGPoint], _ color: Color)
-> _ShapeView<Path, Color> {
return
Path { path in
path.move(to: corners[0])
path.addLine(to: corners[1])
path.addLine(to: corners[2])
path.closeSubpath()
}
.fill(color) as! _ShapeView<Path, Color>
}
}
}
struct ContentView: View {
let testTapArea = TestTapArea()
var body: some View {
ZStack {
testTapArea.path("red")
testTapArea.path("green")
}
.border(.black, width: 1)
.scaleEffect(0.5)
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
code-block