Skip to content

Instantly share code, notes, and snippets.

@Amzd
Created October 17, 2019 09:00
Show Gist options
  • Save Amzd/4ed2ca32933d33e64ab91619e30bbdb6 to your computer and use it in GitHub Desktop.
Save Amzd/4ed2ca32933d33e64ab91619e30bbdb6 to your computer and use it in GitHub Desktop.
Tap gesture on Spacer
extension Spacer {
/// https://stackoverflow.com/a/57416760/3393964
public func onTapGesture(count: Int = 1, perform action: @escaping () -> Void) -> some View {
ZStack {
Color.black.opacity(0.001).onTapGesture(count: count, perform: action)
self
}
}
}
Spacer().onTapGesture {
// This will activate now
}
@pkc456
Copy link

pkc456 commented Jan 28, 2024

Why self is required inside ZStack? (Line number 6)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment