Created
August 5, 2021 19:14
-
-
Save a2/8b2cbf63f5994c674c392347ca41d90c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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