GithubHelp home page GithubHelp logo

changemin / pressablebutton Goto Github PK

View Code? Open in Web Editor NEW
16.0 2.0 1.0 2.23 MB

🕹Pressing Animation & Haptic Feedback SwiftUI Button

License: MIT License

Swift 100.00%
swiftui animation button pressable ios macos swift material-ui spm haptic haptic-feedback

pressablebutton's Introduction

Project logo

🕹 SwiftUI Pressable Button 🕹

License Release


📹 Preview

🏁 Getting Started

Requirements

  • Xcode 11+
  • SwiftUI
  • iOS 14+
  • macOS 10.15+

Installaion

Swift Package Manager(SPM)

File ➜ Swift Packages ➜ Add Package Dependancy..
.package(url: "https://github.com/Changemin/PressableButton", from: "1.1.0")

🎈Usage

PressableButton(action: { YOUR ACTION }) {
    // YOUR VIEW
}
  • action : Functions to execute

🛠Custom Modifiers

PressableButton(action: { YOUR ACTION }) {
    // YOUR VIEW
}.accentColor(_ color: color)
.cornerRadius(_ amount: CGFloat)
.frame(width: CGFloat, height: CGFloat)
.enableHaptic(intensity: UIImpactFeedbackGenerator.FeedbackStyle)
.disableHaptic()
  • .accentColor() : Accent color
  • .cornerRadius() : Corner Radius of the button
  • .frame() : Size of the button
  • .enableHaptic() : Enable haptic effect with insensity(.heavy, .medium, .light, .rigid, .soft)
  • .disableHaptic() : Disable haptic effect

Example

👶 Simple

import PressableButton

struct ContentView: View {
    var body: some View {
        PressableButton(action: {
            print("Button pressed")
        }) {
            Text("Simple Example").foregroundColor(.white)
        }
    }
}

Result

🛠 Custom Modifiers

import PressableButton

struct ContentView: View {
    var body: some View {
        PressableButton(action: {
            print("Button pressed")
        }) {
            Text("PUSH ME !").foregroundColor(.white)
        }
        .enableHaptic(.soft)
        .accentColor(.orange)
        .cornerRadius(0)
    }
}

Result

✅ TODO

  • support variable styles FlatStyle, PushButtonStyle, etc
  • add haptic feedback

📜 License

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

✍️ Author

pressablebutton's People

Contributors

changemin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.