This second problem – the nonexistence of a drag gesture once the long press has completed – prevents access to the location of the long-press-then-drag. Access to this location is critical for displaying to the user that the drag interaction has commenced.
Problem: the LongPressGesture doesn't provide the touch location. And when you sequence the LongPressGesture before the DragGesture, the DragGesture doesn't provide the touch location until the drag actually starts.
Workaround: I created a second DragGesture that's independent of the composed LongPress/DragGesture:
let dragGesture2 = DragGesture(minimumDistance: 0)
.onChanged { value in
dragStartLocation = value.location
}
I then added it to my view as a simultaneousGesture:
.simultaneousGesture(dragGesture2)
This second DragGesture fires immediately when the view is touched so I can get the location and save it to "dragStartLocation". I then use that location to update the UI after the LongPressGesture is triggered (after minimumDuration) but before the main DragGesture runs.
Downside: there will be two DragGestures. But you only use the second one to get the initial touch location so this is pretty minor.
Conclusion: you can use a sequenced LongPressGesture and DragGesture as outlined in the OP's code. But if you need the initial touch location, you can add a second DragGesture in order to capture that initial location.
Topic:
UI Frameworks
SubTopic:
SwiftUI
Tags: