Skip to content

Instantly share code, notes, and snippets.

@jpmcglone
Last active April 1, 2021 20:58
Show Gist options
  • Save jpmcglone/1dfbf87beaa51e2d2b8eaa4706620a02 to your computer and use it in GitHub Desktop.
Save jpmcglone/1dfbf87beaa51e2d2b8eaa4706620a02 to your computer and use it in GitHub Desktop.
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