Skip to content
forked from wiencheck/Bauly

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

Notifications You must be signed in to change notification settings

dhritzkiv/Bauly

 
 

Repository files navigation

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 and go to menu File -> Swift Packages -> Add Package Dependency and past this repo's address:

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

Usage

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

Displaying banner

To display a banner use one of the following methods:

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 methods described above, banners can be presented using methods which provide an entry for directly customizing 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 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 has the same arguments as normal methods.

func forcePresent(...)
Dismissing banner

To manually dismiss the banner use the dismiss method

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

Note You should check if any banner is currently visible before calling this method, by checking the currentBanner property, for example:

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

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

Todos

  • Write Tests
  • Add Night Mode

License

MIT

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

About

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

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 100.0%