I'm an iOS beginner.
I'm facing an issue with the trigger order of Tap Gesture which is applied to NavigationView and its subview - a Circle view.
When I tap on the Circle view, I expect that the system always prioritizes the Tap Gesture action of the Circle view over the Tap Gesture action of the NavigationView, BUT the result is not always like that.
Specifically, sometimes the system gives:
Navigation tapped
Circle tapped
sometimes the system gives
Circle tapped
Navigation tapped
The code is as below or on Gist:
struct ContentView: View {
var body: some View {
NavigationStack {
VStack {
// Button {
// print("Circle tapped")
// } label: {
// Circle()
// .fill(.red)
// .frame(width: 200, height: 200)
// }
Circle()
.fill(.red)
.frame(width: 200, height: 200)
.onTapGesture {
print("Circle tapped")
}
}
}
// .simultaneousGesture(TapGesture().onEnded({ _ in
// print("Navigation tapped")
// }))
.onTapGesture {
print("Navigation tapped")
}
}
}
What I tried (as commented code) but failed:
- use simulatneousGesture modifier.
- use Button w/ label as a Circle.
Is there any way to make the system always prioritize the Tap Gesture of the Circle over the Tap Gesture of the Navigation View?
Thanks for your reading and I appreciate your help.