Skip to content

Instantly share code, notes, and snippets.

@a2
Created August 5, 2021 19:14
Show Gist options
  • Save a2/8b2cbf63f5994c674c392347ca41d90c to your computer and use it in GitHub Desktop.
Save a2/8b2cbf63f5994c674c392347ca41d90c to your computer and use it in GitHub Desktop.
import SwiftUI
struct LocationTapGesture: Gesture {
enum Value {
case recognized(CGPoint)
case failed
}
var coordinateSpace: CoordinateSpace
var body: AnyGesture<Value> {
let gesture = TapGesture()
.simultaneously(with: DragGesture(minimumDistance: 0, coordinateSpace: coordinateSpace))
.map { value -> Value in
if value.first != nil, let dragValue = value.second, hypot(dragValue.translation.width, dragValue.translation.height) <= 10 {
return .recognized(dragValue.location)
} else {
return .failed
}
}
return AnyGesture(gesture)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment