GithubHelp home page GithubHelp logo

raphaellesourd / bauly Goto Github PK

View Code? Open in Web Editor NEW

This project forked from wiencheck/bauly

0.0 0.0 0.0 48 KB

Display compact banners in your app with ease. Inspired by iOS 13+ stock banners

Swift 100.00%

bauly's Introduction

Bauly

Bauly Demo

Bauly is a neat little library used to display compact message banners in your app. The design is inspired by stock banners visible in iOS 13 and newer.

  • Written in Swift 5
  • iOS 10+ support
  • Rotation, Dynamic Type, and Dark Mode support
  • Haptic feedback
  • Available via Swift Package Manager
Installation

Bauly can be installed via Swift Package Manager. To use it in your project, open Xcode, go to menu File -> Swift Packages -> Add Package Dependency, and paste this repo's URL:

https://github.com/wiencheck/Bauly.git

Usage

Bauly is managed via a shared singleton instance. It internally manages a queue of pending banners. Only one banner can be displayed at a time. Remember to call these methods only from the main thread.

Displaying banner

To display a banner, simply use the present method and provide title and other information for the banner:

public func present(title: String, 
                subtitle: String?, 
                icon: UIImage?, 
                duration: TimeInterval, 
                dismissAfter delay: TimeInterval, 
                in window: UIWindow?, 
                feedbackStyle: UIImpactFeedbackGenerator.FeedbackStyle?, pressHandler: (() -> Void)?, 
                completionHandler: (() -> Void)?)
Customizing banner

In addition to the method described above, banners can be presented using a present(configurationHandler:...) method which provides the ability for directly customization of the banner:

func present(configurationHandler: ((BaulyView) -> Void)?, 
            duration: TimeInterval, 
            dismissAfter delay: TimeInterval, 
            in window: UIWindow?, 
            feedbackStyle: UIImpactFeedbackGenerator.FeedbackStyle?, 
            pressHandler: (() -> Void)?, 
            completionHandler: (() -> Void)?)

By calling this method, you can customize the appearance of the banner and its other properties directly, for example:

Bauly.shared.present(configurationHandler: { bauly in
    // Tint is applied to the icon and title of the banner
    bauly.tintColor = .systemPurple
    bauly.visualEffect = .extraLight
    bauly.title = "This is Bauly!"
    bauly.subtitle = """
    Press me to have a little fun with colors.
    Btw, I support mutli-lined text and emojis easily
    ๐Ÿ˜
    """
    }...)
Displaying banner immediately

Both methods used for presenting a banner have a sibling method which forces the banner to be displayed immediately. It takes the same arguments as normal methods.

func forcePresent(...)
Dismissing banner

To manually dismiss the banner, use the dismiss method

func dismiss(completionHandler: (() -> Void)?)

Note If you want to use the completionHandler of this method, you should always check if any banner is currently visible before calling this method, by reading the currentBanner property, for example:

...
if Bauly.shared.currentBanner == nil {
    return
}
Bauly.shared.dismiss {
    print("Old banner dismissed!")
}
...

It's important as the completionHandler of this method doesn't get called if no banner has actually been dismissed.

Todos

  • Write Tests
  • Support dismissal by dragging the banner out of the screen

License

MIT

Check out my apps in App Store!, downloading and buying in-app purchases greatly helps me in developing more stuff!

bauly's People

Contributors

wiencheck avatar dhritzkiv 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.