Last active
April 1, 2021 20:58
-
-
Save jpmcglone/1dfbf87beaa51e2d2b8eaa4706620a02 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 GestureTester: View { | |
@State var isPressed = false | |
@State var location = CGPoint.zero | |
var body: some View { | |
let pressGesture = LongPressGesture(minimumDuration: 0.5).onEnded { | |
self.isPressed = $0 | |
} | |
let dragGesture = DragGesture(minimumDistance: 0) | |
.onChanged { location = $0.location } | |
.onEnded { location = $0.location; self.isPressed = false } | |
let combined = pressGesture.sequenced(before: dragGesture) | |
return Color.red | |
.frame(width: 200, height: 200) | |
.overlay( | |
VStack { | |
Text("is pressed: \(isPressed ? "true" : "false")") | |
Text("location: \(location.x)") | |
} | |
) | |
.gesture(combined) | |
} | |
} | |
#if DEBUG | |
public struct GestureTester_Previews: PreviewProvider { | |
public static var previews: some View { | |
GestureTester() | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment