I want to register a certain drag gesture on any SwiftUI view, including ScrollViews
simultaneously with any other gestures (i.e. without influencing existing gestures). However, when adding a DragGesture
on a ScrollView
as follows, it seems like the gesture is immediately swallowed by the ScrollView
.
ScrollView {
Rectangle()
.frame(width: 500, height: 500)
}
.simultaneousGesture(
DragGesture()
.onChanged { value in
print("changed:", value.translation)
}
.onEnded { value in
print("ended:", value.translation)
}
)
When I drag the Rectangle
, this code prints:
changed: (3.0, 16.666671752929688)
for example.
So onChanged
is only called once, onEnded
is never called.
Is there a way to make DragGestures
work with ScrollViews
as well?
Note:
I tried to find a workaround with GestureState
and the updating(_:)
modifier as well, but it didn't work either.