🍞 Loaf is a Swifty Framework for Easy iOS Toasts

Overview

Loaf 🍞

Inspired by Android's Toast,
Loaf is a Swifty Framework for Easy iOS Toasts

Version Liscence Platform Swift4.2 Readme Score


Usage

From any view controller, a Loaf can be presented by calling:

Loaf("Message goes here", sender: self).show()

Which will result in:

screen shot 2019-02-27 at 3 59 07 pm

Bellow, I will discuss how to further customize your Loaf!

Playground

I've provided an example project to showcase uses of Loaf! Simply clone this repo, and open LoafExamples.xcodeproj. From here you can see and experiment custom Loaf styles in Examples.swift

Customization

Basic styles

Loaf comes with 4 basic style out of the box.

Success Error
screen shot 2019-02-27 at 3 45 44 pm screen shot 2019-02-27 at 3 45 52 pm
Warning Info
screen shot 2019-02-27 at 3 45 58 pm screen shot 2019-02-27 at 3 53 26 pm

These styles can be specified in the style property. For instance, to use Success styled Loaf, call it like so:

Loaf("This is a success loaf", state: .success, sender: self).show()

Custom styles

Loaf allows you to specify a custom style! This will let you set the colors, font, icon. and icon alignment. Here are some examples of custom Loaf styles!

Colors and icon Right icon alignment No icon
screen shot 2019-02-27 at 6 09 33 pm screen shot 2019-02-27 at 6 13 13 pm screen shot 2019-02-27 at 6 13 22 pm

All of these properties are specified as part of custom state, like so:

Loaf("Switched to light mode", state: .custom(.init(backgroundColor: .black, icon: UIImage(named: "moon"))), sender: self).show()

Presenting and dismissing

Loaf allows you to specify the presenting and dismissing direction. The presenting direction is independant from the dismissal direction. Here are some examples:

Vertical Left
vertical left
Right Mix
right mix

These are specified in the function signature, like so:

Loaf("Loaf message", presentingDirection: .left, dismissingDirection: .vertical, sender: self).show()

Location

Toasts are typically presented at the bottom of the screen, but Loaf allows you to also present them at the top of the screen. Here is an example of a Loaf being presented at the top of the view:

screen shot 2019-02-27 at 8 30 04 pm

This is also specified in the function signature, like so:

Loaf("Loaf message", location: .top, sender: self).show()

Other

Specify the presentation duration. When presenting a Loaf with .show(), a presentation duration can be specified. The default value is 4s, but there are presets for 2s and 8s. This is done by using .show(.short) for 2s, or .show(.long) for 8s. A custom duration can also be specified with .show(.custom(x)), where x represents the duration in seconds.

⚠️ New in 0.5.0:

  • A completion handler can be specified in the Loaf show() function signature. This block will be called when the dismissal animation is completed, or when the Loaf is tapped. This completion handler is now passed with a enum representing whether the Loaf was tapped or timmed out. Here is an example of using a completion handler:
Loaf(example.rawValue, sender: self).show { dismissalType in
     switch dismissalType {
          case .tapped: print("Tapped!")
          case .timedOut: print("Timmed out!")
     }
}
  • A Loaf's width can be specified via the Style component. The width can be specifed as a fixed size (i.e. 280px) or as a percentage of the screen's width. (i.e. 0.8 -> 80%). Here is some example usage:
Loaf(example.rawValue, state: .custom(.init(backgroundColor: .black, width: .screenPercentage(0.8))), sender: self).show()
  • Loaf's will now be presented above tab bars, when possible.
  • Loaf's can be manually dismissed through a global method:
Loaf.dismiss(sender: self) // Where `self` is the Loaf's presenter

Installation

Cocoapods

Loaf is on Cocoapods! After setting up Cocoapods in your project, simply add the folowing to your Podfile:

pod 'Loaf'

then run pod install from the directory containing the Podfile!

Don't forget to include import Loaf in every file you'd like to use Loaf

Requirements

  • Swift 4.2+
  • iOS 9.0+

Contributing

Pull requests, feature requests and bug reports are welcome πŸš€


Thanks to @kirkbyo for helping me through the tough parts of this πŸ’ͺ

Made with ❀️ in πŸ‡¨πŸ‡¦ by Mat Schmid

Comments
  • Cannot install Loaf

    Cannot install Loaf

    I followed the instructions and added Load to my Podfile:

    pod 'Loaf'

    then ran pod install, which resulted in the following error:

    [!] CocoaPods could not find compatible versions for pod "Loaf":
      In Podfile:
        Loaf
    
    Specs satisfying the `Loaf` dependency were found, but they required a higher minimum deployment target.
    

    Cocoapods version 1.9.1 Project target is set to 10.3

    opened by pepejeria 5
  • Loaf 0.3 crashes app

    Loaf 0.3 crashes app

    This piece of code causes 'Thread 1: signal SIGABRT'

    Loaf( "message" , sender: self).show (.short, onTap: { print("Dismissal complete") })

    opened by 64knl 4
  • Add SPM support and migrate to Swift 5.1

    Add SPM support and migrate to Swift 5.1

    This PR bumps to Swift 5.1 and adds support for Swift Package Manager. It also lowers the required deployment target to 9.0 since there is nothing in the library that requires a higher target sdk.

    I have verified that it still works by adding it to a SwiftUI project using SPM, then presenting toasts from the application's key window's root view controller.

    opened by danielsaidi 2
  • add dismiss method

    add dismiss method

    This PR adds a dismiss method to the Loaf object.

    This is super beneficial for the following circumstance--- say you present a loaf and then while it is displaying, the user takes an action from within your main controller and you need to present a new view controller.

    With the current code, this isn't possible because the main view controller is not allowed to present while the LoadViewController is being presented. And dismissing that view controller manually so that it can present, will cause the Loaf library issues since it will not reset its state via the isPresenting variable.

    The solution is to retain your Loaf object while it is presenting and then if the main view controller must present, it may call currentLoaf.dismiss(animated: false) and then present its new view controller.

    opened by logansease 2
  • textAlignment

    textAlignment

    Great library!
    It got mentioned on the Swift over coffee podcast, so I wanted to try it out.
    I didn't see it anywhere, but is it possible to customize the text further? Like setting the textAlignment to .center for example?

    opened by MartinP7r 2
  • Programmatic Dismissal

    Programmatic Dismissal

    Is it possible to have the Loaf dismiss programmatically? I.e. it appears with the message β€œConnecting ...” and it dismisses on a completion callback?

    opened by mazz 1
  • Is there a way to adjust the size of the loaf?

    Is there a way to adjust the size of the loaf?

    Is it possible to adjust the height/width of the loaf? It looks like the width is hard coded as 200, but it would be nice to either override this, or if that is undesirable for some reason, perhaps it should be 0.8 of the view's width?

    opened by isupremedyou 1
  • Display on top of tabbar

    Display on top of tabbar

    First of all, great and useful library here!

    Currently when showing a Loaf inside a UITabBarController, the Loaf will display on top of the tabbar. Hereby interfering with the user interaction by blocking the buttons.

    Like this: LoafNow

    Can we make it an option to set the location above the tabbar?

    Like so: LoafProposed

    opened by CollinHemeltjen 1
  • completionHandler stopped working

    completionHandler stopped working

    This example code from readme no longer works:

        Loaf("Loaf message", sender: self, completionHandler: {
            print("Dismissal complete")
        }).show()
    

    Error messages in xCode:

    1. Argument 'completionHandler' must precede argument 'sender'
    2. Incorrect argument label in call (have ':completionHandler:sender:', expected ':state:sender:')
    opened by 64knl 1
  • Replaced hardcoded container view insets

    Replaced hardcoded container view insets

    Replaced hardcoded container view insets in Presenter/Controller with the safe area ones to fix appearance for devices like iPhone 7. Added proper margins for iOS pre-11 to take into account status bar, including rotation support and in-call status bar.

    opened by ptiz 0
  • Fix retain cycle + renamed and moved completion handler

    Fix retain cycle + renamed and moved completion handler

    Resolves https://github.com/schmidyy/Loaf/issues/1

    Fixes retain cycle in sender Renames completionHandler to onTap, and move call to show()

    cc @RollingGoron

    opened by schmidyy 0
  • Adding center display location

    Adding center display location

    I needed to ability to display a Loaf center screen, so made a pull request, feel free to discard if you don't feel it will be useful to anyone else.

    Thanks for the great repo, you have done a great job and it's come in very useful!

    opened by Hayd25 0
  • UITabBarController inset not respected if UIViewController is wrapped inside UINavigationController

    UITabBarController inset not respected if UIViewController is wrapped inside UINavigationController

    basically the title. Changes introduced in #15 did not take into account that UIViewController might be wrapped inside a UINavigationController.

    PR is ready

    opened by fgeistert 0
  • Queue visibility

    Queue visibility

    The Queue used in Loaf.swift is visible out side. I believe it should be visible only to LoafManager The idea is to move it's scope within Loaf manager class

    opened by amankumar303 1
  • Unable to compile due to UIApplication.shared error

    Unable to compile due to UIApplication.shared error

    I have tried on xcode 12.5.1 as well as xcode 13.1 and get the error: "'shared' is unavailable in application extensions for iOS: Use view controller based solutions where appropriate instead."

    • on Controller.swift -> line 40
    opened by JGVB 0
  • SwiftUI Support

    SwiftUI Support

    Thanks Mr. Schmid for the great framework! It works like a charm.

    Having some native SwiftUI Support in the Framework would be awesome - or at least something in the readme. So far this worked out for me in my project:

    Loaf("There was an error", state: .error, sender:  UIApplication.shared.keyWindow!.rootViewController!).show()
    

    But it feels more like a workaround to me. If you want me to, I can extend the README.md file with such a sample.

    opened by xremix 3
Releases(v0.6.0)
Owner
Mat Schmid
iOS @Shopify
Mat Schmid
Toasts and popups library written with SwiftUI

Popup View Toasts and popups library written with SwiftUI We are a development agency building phenomenal apps. Usage Put all your body code into a ZS

Exyte 1.6k Sep 27, 2022
Create Apple-like alerts & toasts using SwiftUI

AlertToast-SwiftUI Present Apple-like alert & toast in SwiftUI ?? Example ?? Overview Currently in SwiftUI, the only way to inform the user about some

Elai Zuberman 976 Sep 18, 2022
Swifty, modern UIAlertController wrapper.

Alertift Alertift.alert(title: "Alertift", message: "Alertift is swifty, modern, and awesome UIAlertController wrapper.") .action(.default("❀️"))

Suguru Kishimoto 286 Aug 17, 2022
A Swift package for iOS/tvOS for easy alert presentation

AlertPresenter Listed on the Swift Package Index and originally posted on my blog. It can be fiddly to handle the presentation of alerts on a specific

Chris Mash 14 Jul 1, 2022
πŸ’Œ Easy to use and customizable messages/notifications for iOS Γ  la Tweetbot

Notice: TSMessages is no longer being maintained/updated. We recommend everyone migrate to RMessage. This repository will be kept as is for those who

Felix Krause 4.9k Sep 17, 2022
[iOS] Easy, customizable notifications displayed on top of the statusbar. With progress and activity. iPhone X ready.

JDStatusBarNotification Show messages on top of the status bar. Customizable colors, font and animation. Supports progress display and can show an act

M Emrich 3.8k Sep 22, 2022
It is a highly configurable iOS library which allows easy styling with built in styles as well as extra header and footer views so that you can make extremely unique alerts and action sheets.

ο£Ώ CFAlertViewController CFAlertViewController is a library that helps you display and customise Alerts, Action Sheets, and Notifications on iPad and i

Crowdfire Inc. 1.1k Sep 9, 2022
Easy Swift UIAlertController

EZAlertController Easy Swift UIAlertController One line setup for all UIAlertControllers Button action with closures instead of selectors Easily custo

Kan Yilmaz 366 Sep 14, 2022
BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

BottomSheet makes it easy to take advantage of the new UISheetPresentationController in SwiftUI with a simple .bottomSheet modifier on existing views.

Adam Foot 338 Sep 23, 2022
BottomSheet makes it easy to add custom bottom sheets to your SwiftUI apps.

BottomSheet About BottomSheet BottomSheet makes it easy to add custom bottom sheets to your SwiftUI apps. The result can look like this...or completel

Daniel Saidi 163 Sep 16, 2022
An easy to use UIAlertController builder for swift

LKAlertController An easy to use UIAlertController builder for swift Features Short and simple syntax for creating both Alerts and ActionSheets from U

Lightning Kite 97 Feb 8, 2022
✨ Super easy Parallax and Haptic Effect.

IParallaxAndHapticEffect ✨ Super easy Parallax and Haptic Effect. This library helps you easily use the 'Parallax' and 'Haptic' effects. Customized 3D

Hae Chan 2 Feb 9, 2022
🧰 MacOS menubar for easy copy gitmoji

gitmojiBar Introdution ?? ?? MacOS status bar for easy copy gitmoji emoticons, Written in Swift 5.0 Preview ?? Requirements gitmoji-bar written in Swi

Fernando 17 Sep 8, 2022
Ipraktikum-swift-solutions - The solutions of the easy entrance swift quiz for the IPraktikum

ipraktikum-swift-solutions The solutions of the easy entrance swift quiz for the

Eugenio Berretta 0 Feb 13, 2022
🧰 MacOS menubar for easy copy gitmoji

gitmojiBar Introdution ?? ?? MacOS status bar for easy copy gitmoji emoticons, Written in Swift 5.0 Preview ?? gitmojibar.mov AppStore Requirements gi

Fernando 17 Sep 8, 2022
A customizable, full-feature, lightweight iOS framework to be used instead of UIAlertController.

A customizable, full-feature, lightweight iOS framework to be used instead of UIAlertController.

Ali Samaiee 11 Jun 6, 2022
A customizable framework to create draggable views

CFNotify CFNotify is written in Swift. Using UIKit Dynamics as animator. It can make ANY UIView object draggable and throwable. This library mainly us

Johnny Tsoi 491 Aug 18, 2022
Bursts πŸ”₯ A Funny Framework is showing alerts, Have been Adapting Swift and SwiftUI

Bursts ?? A Funny Framework is showing alerts, Have been Adapting Swift and SwiftUI Features iOS 10+ Can be used in UIKit and SwiftUI applications Lig

Jovins 11 Apr 22, 2022
A customizable framework to create draggable views

CFNotify CFNotify is written in Swift. Using UIKit Dynamics as animator. It can make ANY UIView object draggable and throwable. This library mainly us

Johnny Tsoi 491 Aug 18, 2022