Skip to content

A SwiftUI button that can trigger actions for different gestures.

License

danielsaidi/GestureButton

Repository files navigation

Project Icon

Version Swift 6.1 Documentation MIT License Sponsor my work

GestureButton

GestureButton can trigger many different actions with a single gesture.

You can use a GestureButton just like a regular Button, and can define different actions for different gestures:

struct ContentView: View {

    @State private var isPressed = false
    
    var body: some View {
        GestureButton(
            isPressed: $isPressed,
            pressAction: { print("Pressed") },
            releaseInsideAction: { print("Released Inside") },
            releaseOutsideAction: { print("Released Outside") },
            longPressAction: { print("Long Pressed") },
            doubleTapAction: { print("Double Tapped") },
            repeatAction: { print("Repeating Action") },
            dragStartAction: { value in print("Drag Started") },
            dragAction: { value in print("Drag \(value)") },
            dragEndAction: { value in print("Drag Ended") },
            endAction: { print("Gesture Ended") }
        ) { isPressed in
            Color.yellow // You can use any button content view.
        }
        .gestureButtonConfiguration(...)
    }
}

You can pass in custom configurations to change how the button behaves, e.g. the max time between two taps for the taps to count as a double-tap. You can use any content View as the button label, based on the isPressed state.

Installation

GestureButton can be installed with the Swift Package Manager:

https://github.com/danielsaidi/GestureButton.git

Support My Work

You can become a sponsor to help me dedicate more time on my various open-source tools. Every contribution, no matter the size, makes a real difference in keeping these tools free and actively developed.

Documentation

The online documentation has more information, articles, code examples, etc.

Demo Application

The Demo folder has a demo app that lets you explore the library and its components.

Contact

Feel free to reach out if you have questions or if you want to contribute in any way:

License

GestureButton is available under the MIT license. See the LICENSE file for more info.

About

A SwiftUI button that can trigger actions for different gestures.

Topics

Resources

License

Stars

Watchers

Forks

Sponsor this project