LongPressGesture.updating(_:body:)

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?

Answered by DTS Engineer in 801191022

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

Accepted Answer

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

Thank you. I can see onLongPressGesture(minimumDuration:perform:onPressingChanged:) is triggering correctly and I've used this to work around my issue.

See FB14372706 for the bug report.

I have found that onLongPressGesture(minimumDuration:perform:onPressingChanged:) appears to work only when minmumDuration is set to 0.1 or 0.2

Hello,

The issue is still there with iOS 18.3 and even Mac Catalyst on macOS 15.3. See Bug report ID: FB16449802

.onLongPressGesture(...)

works but for instance can't be used for

.simultaneousGesture(...)

In fact on iOS 18, the LongPressGesture object never calls

func updating<State>(GestureState<State>, body: (Self.Value, inout State, inout Transaction) -> Void) -> GestureStateGesture<Self, State>

func onChanged((Self.Value) -> Void) -> _ChangedGesture<Self>

Thank you

LongPressGesture.updating(_:body:)
 
 
Q