I've found the solution in Stack Overflow. It's because by default SwiftUI views with zero opacity doesn't have a content shape. Use .contentShape(Rectangle()) makes the view use the Rectangle content shape so it becomes tappable:
Color.clear
.contentShape(Rectangle())
.onTapGesture {
counter += 1
}
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: