I have an app that needs audio input, and the button gesture needs to recognize long press.
The View is like
VStack {
ScrollView
InputButton
}
The gesture modify is
.highPriorityGesture(
LongPressGesture(minimumDuration: 0.01, maximumDistance: 200)
.sequenced(before: DragGesture(minimumDistance: .zero, coordinateSpace: .global))
.updating($pressState, body: { (value, state, transaction) in
switch value {
case .first(true):
// start press
case .second(true, let drag):
state = .started
if let drag = drag {
//Calculate drag
}
break
default:
state = .inactive
// on end
}
})
.onEnded({ value in
// on end
}),
including: .gesture
)
The gesture works when normally used, but if I press the button while scrolling, the LongPress won’t detect the end event and the drag position is wrong.
How can I cancel any other gesture when I start this gesture?
Many thanks