The code below presents a View
in the middle of the screen, and allows you to drag that View
. However, if you start the drag on the Button
, the drag does not work. You need to drag on the area of the View
around the Button
.
Is there a way to make these two gestures know about each other, so that you can start the drag from anywhere in the View
, even over the Button
?
I'm imagining that putting a finger down on the Button
would start both gestures as possibilities, and then if you would either lift up or start dragging to decide between the two.

struct ContentView: View {
@State private var dragOffset: CGSize = .zero
@State private var dragStartOffset: CGSize? = nil
var body: some View {
ZStack {
Button("Hello") { print("hello") }
.padding(30)
.background(.regularMaterial)
.gesture(dragGesture)
.offset(dragOffset)
}
}
private var dragGesture: some Gesture {
DragGesture(minimumDistance: 0, coordinateSpace: .global)
.onChanged { value in
if dragStartOffset == nil {
dragStartOffset = dragOffset
}
dragOffset = dragStartOffset! + value.translation
}
.onEnded { _ in
dragStartOffset = nil
}
}
}
func +(a: CGSize, b: CGSize) -> CGSize { CGSize(width: a.width + b.width, height: a.height + b.height) }