SwiftUI-ContentShape
dummy

What I encountered.

Recently when I'm testing Tap Gesture, but however I've got in some trouble. And touch event doesn't work.

However, after find some answers on stackoverflow. I noticed that Color.clear's contentShape is zero, which means it is untouchable.

And the solution is to add modifier .contentShape(Rectangle()) before .onTapGesture modifier.

Here's my test code. You can comment or uncommnet the contentShape modifier to see what happened.

In Hacking with Swift 100 days learning SwiftUI, it mentioned that when adding gestures to a Stack, it will allocate gestures to the Views in this Stack, but area that outside the Views, and inside the Stack is not. So, if we want to add some gestures to a Stack, we can use .contentShape() modifier.