Recognize end of two sequenced LongPressGestures

I'm trying to sequence two LongPressGestures, but my onEnded handler isn't being called when the second one finishes. Here is my code:

Code Block swift
    var timerGesture: some Gesture {
        let cautionary = LongPressGesture(minimumDuration: 0.5)
            .onEnded { _ in print("cautionary done") }
        let lift = LongPressGesture(minimumDuration: .infinity)
            .onEnded { _ in print("lift done") }
        return cautionary.sequenced(before: lift)
    }


This gesture manipulates a timer. The point of the gesture is to ensure that the user must long press for at least 0.5 seconds before they may lift their finger in order to start the timer. In other words, there is a 500ms long "confirmation" period where the user must hold down their finger before they can actually complete the gesture. Doing a simple tap will cancel the gesture during cautionary.

Here's what I'm trying to accomplish:

  1. User long presses for at least 0.5 seconds. After 0.5 seconds, cautionary's onEnded is called.

  2. The user releases their finger, and lift's onEnded is called.

However, lift's onEnded is never actually called. How can I achieve something like this using SwiftUI's gesture system?
Answered by sliceofcode in 614467022
Okay, I figured it out.

You have to use a TapGesture as the second gesture instead of a LongPressGesture.
Accepted Answer
Okay, I figured it out.

You have to use a TapGesture as the second gesture instead of a LongPressGesture.
Recognize end of two sequenced LongPressGestures
 
 
Q