I started with a sequenced DragGesture and ran into the same problem: no way to get the start location (before the drag starts). Then I tried using .simultaneously instead of .sequenced:
let longPressDrag = LongPressGesture(minimumDuration: 0.2)
.onEnded { value in
}
.simultaneously(with: dragGesture)
.updating($state, body: { value, state, trans in
dragStartLocation = value.second?.location ?? .zero
})
.onEnded({ value in
dragStartLocation = .zero
})
This kind of works: the LongPressGesture sets dragStartLocation (before releasing the touch or dragging). I'm using this with a ScrollView. If I quickly drag, the ScrollView scrolls. If I touch, then wait before dragging, I can set scrollDisabled on the ScrollView and the DragGesture takes over.
Unfortunately, there's one big problem: the LongPressGesture always takes 1 second to process. It doesn't matter if "minimumDuration" is set to 0.1 seconds or 10 seconds.
So we're left with two undesirable options:
Use a sequenced gesture, which uses the correct "minimumDuration", but there's no way to get the start location.
Use a simultaneous gesture, which correctly sets the start location, but doesn't respect the "minimumDuration".
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: