Text with onTapGesture instead of Button

I have seen tutorial videos where they do this. What could the rationale be? I don’t currently see an advantage over using a Button.

I think it's in general a bad practice. Button has a few accessibility affordances you lose when using a tap gesture for the same function.
There are very few use-cases for isolated single-tap gestures. The only ones I can think of right now is to provide a "tap to change state" function (like flipping a card or dismissing a presented view). Other than that, I think that a Button is more appropriate.
Of course, TapGesture has its uses when you need to count them or compose with other gestures, but if it has the function of a button, it should be a button.
Now, SwiftUI being a declarative framework, it could be possible that onTapGesture on Text resolves to a button, but I didn't checked and I'm not sure of that. It seems unlikely.

1 Like