A SwiftUI button that initiates action on tap or long press.
Usage
Create LongPressButton similar to how you would create a regular Button passing it a title, action to perform on tap and an action to perform on long press.
LongPressButton("Tap or long press me") {
// Tapped
} longPressAction: {
// Long pressed
}
Additionally you can configure minimum long press duration, maximum finger travel distance or provide custom label.
Supporting Both Tap and Long Press on a Button in SwiftUI by Peter Steinberger - Great article with few potential solution on how to create button with long press action. Unfortunately none of them worked correctly for my use case.
LongPressButton
A SwiftUI button that initiates action on tap or long press.
Usage
Create
LongPressButton
similar to how you would create a regularButton
passing it a title, action to perform on tap and an action to perform on long press.Additionally you can configure minimum long press duration, maximum finger travel distance or provide custom label.
Installation
Swift Package Manager
Add the following to the dependencies array in your “Package.swift” file:
Or add https://github.com/Tunous/LongPressButton.git, to the list of Swift packages for any project in Xcode.
Credits
Supporting Both Tap and Long Press on a Button in SwiftUI by Peter Steinberger - Great article with few potential solution on how to create button with long press action. Unfortunately none of them worked correctly for my use case.