I have created a DragGesture in a View that should select a @State(Bool) whether the user swipe left or right.
The thing is that only swiping right is detected.
How to use .gesture() to capture whether a user is swiping left or right on his screen?
import SwiftUI
struct SwiftUIView: View {
//MARK: Value to change on swipe gesture
@State var swipeRight: Bool
var body: some View {
VStack {
//MARK: Value displayed after user swiped
Text($swipeRight ? "Right" : "Left")
}
.gesture(
DragGesture()
.onChanged { (value) in
//MARK: What is it missing here?
switch value.location.x {
case ...(-0.5):
self.swipeRight = false
print("Swipe Left return false")
case 0.5...:
self.swipeRight = true
print("Swipe Right return true")
default: ()
}
})
}
gesture
to be asimultaneousGesture
as they can be stack on each others on aView
when using it. – Sundin