Open bardigolriz opened 1 year ago
Thank you @bardigolriz
Although I aimed for GestureButton
to be pretty straightforward, I can see the use case where you would not want to trigger the release action after the long press.
I will try to find time to add this to the two buttons 👍
I have a GestureButton that I have events for when the user taps as well as long presses (with a minimum delay).
I can’t depend on plain SwiftUI gesture modifiers for this because when the two are chained together, the long press minimum duration set appears to be ignored.
With GestureButton, I am trying to use
releaseInsideAction
combined withlongPressAction
with alongPressDelay
of 0.1.When I tap on the button, the
releaseInsideAction
is called correctly.When I long press on the button, the
longPressAction
after the correct delay is called correctly. However, it also then proceeds to call thereleaseInsideAction
too, which isn’t what I want or expected.To workaround this, I have added a new @State variable:
private var isLongPressed: Bool = false
Inside
tryTriggerLongPressAfterDelay()
, after itsaction()
call, I flag it to be true:Finally, in
tryHandleRelease()
, I check whetherisLongPressed
is true to determine whether to proceed with its associated action:In my tests, this seems to work really well without any issues. Can’t see where it could possibly trip up! Thank you so much for implementing such a versatile button that helps workaround SwiftUI limitations.