I am trying to get the position of the finger during a drag gesture (from an origin point of where the finger first began the drag). I want to do this while simultaneously allowing for scrolling within a ScrollView.
I can do these independently, but it seems scrolling in a ScrollView prevents the drag gesture.
I have tried adding the .gesture() part of the code below to the Component(), the VStack, and I also tried wrapping all of this in a GeometryReader and adding it to that. Each time, the .gesture() only prints when no scrolling happens (so, it prints when dragging horizontally).
How can I achieve this?
ScrollView {
VStack(alignment: .center, spacing: 0) {
ForEach((0..<reports.count), id: .self) {i in
Component(report: reports[i])
.offset(y: -(CGFloat(i) * 12.0))
}
}
}
.gesture(
DragGesture()
.onChanged { value in
self.position = value.translation
print(self.position)
}
.onEnded { _ in
self.position = .zero
}
)
2
Answers
Thanks to everyone for the suggestions (some of which were deleted by their authors). Unfortunately, as DatBlaueHus states:
I've solved my issue by using a custom
ScrollView
implementation. I need to play around with the feel of it — it doesn't scroll quite as smoothly as the stockScrollView
, but it solves my issue and recognises gestures simultaneously.this answer might work, but it also seems like a weird workaround.
worst case you must build your own scrollview, as to have access to all touches and then offsetting stuff so scroll also works..