Hello,
I'm using LongPressGesture to provide haptic & color change feedback on a long press action. This fails to call the .updating(_:body:) method on every iOS 18.0 beta. It works fine on iOS 17.
The following code, taken directly from Apple's documentation illustrates the problem. The .updating()
closure is never called, while the .onEnded()
closure is called correctly. Instead of a gradual color transition the example code generates a delayed sharp switch from Red to Blue, preventing interactive user feedback.
struct LongPressGestureView: View {
@GestureState private var isDetectingLongPress = false
@State private var completedLongPress = false
var longPress: some Gesture {
LongPressGesture(minimumDuration: 3)
.updating($isDetectingLongPress) { currentState, gestureState,
transaction in
gestureState = currentState
transaction.animation = Animation.easeIn(duration: 2.0)
}
.onEnded { finished in
self.completedLongPress = finished
}
}
var body: some View {
Circle()
.fill(self.isDetectingLongPress ?
Color.red :
(self.completedLongPress ? Color.green : Color.blue))
.frame(width: 100, height: 100, alignment: .center)
.gesture(longPress)
}
}
Can anyone share tips on a workaround or potential fix application-side?
Hi @Rob321 Thanks for flagging thing, I was able to repduce the issue as well, please file a bug report using Feedback Assistant., see Bug Reporting: How and Why? for more details.
Could you try using the onLongPressGesture(minimumDuration:perform:onPressingChanged:) or the onLongTouchGesture(minimumDuration:perform:onTouchingChanged:) modifier instead, the closure gets triggered using those modifiers