Coder Social home page Coder Social logo

toaster's Introduction

Toaster

Build Status Swift CocoaPods Carthage compatible

Android-like toast with very simple interface. (formerly JLToast)

Screenshots

Toaster Screenshot

Features

  • Queueing: Centralized toast center manages the toast queue.
  • Customizable: See the Appearance section.
  • String or AttributedString: Both supported.
  • UIAccessibility: VoiceOver support.

At a Glance

import Toaster

Toast(text: "Hello, world!").show()

Installation

  • For iOS 9+ projects with CocoaPods:

    pod 'Toaster'
  • For iOS 9+ projects with Carthage:

    github "devxoul/Toaster"
    
  • For iOS 9+ and Xcode 11+ projects with Swift Package Manager:

    dependencies: [
        .package(url: "https://github.com/devxoul/Toaster.git", from: "master")
    ]
    

Getting Started

Setting Duration and Delay

Toast(text: "Hello, world!", duration: Delay.long)
Toast(text: "Hello, world!", delay: Delay.short, duration: Delay.long)

Removing Toasts

  • Removing toast with reference:

    let toast = Toast(text: "Hello")
    toast.show()
    toast.cancel() // remove toast immediately
  • Removing current toast:

    if let currentToast = ToastCenter.default.currentToast {
        currentToast.cancel()
    }
  • Removing all toasts:

    ToastCenter.default.cancelAll()

Appearance

Since Toaster 2.0.0, you can use UIAppearance to set default appearance. This is an short example to set default background color to red.

ToastView.appearance().backgroundColor = .red

Supported appearance properties are:

Property Type Description
backgroundColor UIColor Background color
cornerRadius CGFloat Corner radius
textInsets UIEdgeInsets Text inset
textColor UIColor Text color
font UIFont Font
bottomOffsetPortrait CGFloat Vertical offfset from bottom in portrait mode
bottomOffsetLandscape CGFloat Vertical offfset from bottom in landscape mode
shadowPath CGPath The shape of the layerโ€™s shadow
shadowColor UIColor The color of the layerโ€™s shadow
shadowOpacity Float The opacity of the layerโ€™s shadow
shadowOffset CGSize The offset (in points) of the layerโ€™s shadow
shadowRadius CGFloat The blur radius (in points) used to render the layerโ€™s shadow
maxWidthRatio CGFloat The width ratio of toast view in window
useSafeAreaForBottomOffset Bool A Boolean value that determines safeAreaInsets.bottom is added to bottomOffset

Attributed string

Since Toaster 2.3.0, you can also set an attributed string:

Toast(attributedText: NSAttributedString(string: "AttributedString Toast", attributes: [NSAttributedString.Key.backgroundColor: UIColor.yellow]))

Accessibility

By default, VoiceOver with UIAccessibility is enabled since Toaster 2.3.0. To disable it:

ToastCenter.default.isSupportAccessibility = false

License

Toaster is under WTFPL. You can do what the fuck you want with Toast. See LICENSE file for more info.

toaster's People

Contributors

butcheryl avatar cbot avatar cchitsiang avatar coeur avatar cozzin avatar devxoul avatar dkhamsing avatar dominatorvbn avatar fahimf avatar gorhom avatar hardtack avatar hypery2k avatar itlijunjie avatar jobinsjohn avatar kimdarren avatar ksloginov avatar ldiqual avatar mcblooder avatar niko-r avatar o-o-wl avatar onsissond avatar shaneog avatar

Stargazers

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

Watchers

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

toaster's Issues

[2.0.4] cancelAll() doesn't cancel toasts immediately

We're running a bunch of unit tests which ensure that toasts show with a specific message. After ensuring that the toast shows, we cancel all toasts so that the next test doesn't mess with a previously shown toast. It looks like this:

vc.submitButton.sendActions(for: .touchUpInside) // Triggers `Toast(text: "hello").show()`
expect(ToastCenter.default.currentToast.text).to(equal("hello"))
ToastCenter.default.cancelAll()
expect(ToastCenter.default.currentToast).to(beNil())

With 2.0.3, the assertions above run smoothly. With 2.0.4, ToastCenter.default.currentToast is not nil. Here's the diff: 2.0.3...2.0.4#diff-da60668d6e40aed0148429ffdc135caeR166. Not too sure what changed :/

Doesn't work after TouchID

For some reason if I use LocalAuthentication and TouchID in some view controller, Toast will not work after that in any other view controller. This is my sample code:

let context = LAContext()
var error: NSError?
let reasonString = "Authentication is needed to complete the action."
if context.canEvaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, error: &error) {
        [context .evaluatePolicy(LAPolicy.DeviceOwnerAuthenticationWithBiometrics, localizedReason: reasonString, reply: { (success: Bool, evalPolicyError: NSError?) -> Void in

 })]

and after this toast will not work, even when you push to other view controllers until you kill the app completely. I'm on iOS 9.1, Swift 2.0, JLToast 1.3.2

Toast message view did not rotate on iPad mini.

In iPad mini (iOS 9.3.1), when we rotate device from portrait to landscape mode, toast message did not rotate with latest version of JLToast(1.4.1). In older JLToast(1.0), it is working fine. In iPad air the version of JLToast(1.4.1) also working as expected. Please find attach screenshot for more reference.

img_0079

swift 2.2?

There will be a release for swift 2.2?

Toast Doesn't Appear Inside CollectionView didSelectItemAtIndexPath

I have a UICollectionView where I let the user select up to 5 photos. After 5 are selected I'm trying to show a toast message informing the user only 5 photos can be selected. I am using JLToast throughout the code, however here it does not show. The UICollectionView is within a UIViewController. Here is the code I am using within didSelectItemAtIndexPath:

        println("show toast")
        JLToast.makeText(NSLocalizedString("select_up_to_five_photos", comment: "Select up to 5 photos")).show()            

The println gets printed correctly, but I don't see a toast.

Crash

While on iPad simulator I received this crash:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[__NSOperationInternal _start:]: something is trying to start the receiver simultaneously from more than one thread'
*** First throw call stack:
(
0 CoreFoundation 0x0000000113438b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000112e9d141 objc_exception_throw + 48
2 CoreFoundation 0x00000001134a1625 +[NSException raise:format:] + 197
3 Foundation 0x00000001129a5599 -[_NSOperationInternal start:] + 277
4 Toaster 0x00000001109aefc4 TFC7Toaster5Toast5startfT_T + 132
5 Toaster 0x00000001109af2ac TFFC7Toaster5Toast5startFT_T_U_FT_T + 108
6 Toaster 0x00000001109af2f7 TTRXFo___XFdCb
+ 39
7 libdispatch.dylib 0x00000001144574a6 _dispatch_call_block_and_release + 12
8 libdispatch.dylib 0x000000011448005c _dispatch_client_callout + 8
9 libdispatch.dylib 0x000000011446140b _dispatch_main_queue_callback_4CF + 411
10 CoreFoundation 0x00000001133fd909 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9
11 CoreFoundation 0x00000001133c3ae4 __CFRunLoopRun + 2164
12 CoreFoundation 0x00000001133c3016 CFRunLoopRunSpecific + 406
13 GraphicsServices 0x0000000115dc8a24 GSEventRunModal + 62
14 UIKit 0x0000000110a0b0d4 UIApplicationMain + 159
15 carpolo 0x000000010b4485b7 main + 55
16 libdyld.dylib 0x00000001144cc65d start + 1
17 ??? 0x0000000000000008 0x0 + 8
)
libc++abi.dylib: terminating with uncaught exception of type NSException

Custom background color issue

foto 03 08 15 12 20 21

when I present it like this:

class func showError(text: String) {
    let toast = JLToast.makeText(text)
    toast.view.backgroundColor = UIColor.redColor()
    toast.duration = JLToastDelay.LongDelay
    toast.show()
}
MyToast.showError(err)

It seems like the black color is overlaying the red color.

Migrating from iOS 8 to iOS9 and swift makes toasts disappear right after shown

I don't know why this happens because I did not touch any code. I just migrated from JLToast 1.2.5 to 1.3.2. What I see is that when the toast is shown it disappears instantly. It happens for me in this code:

func messageComposeViewController(controller: MFMessageComposeViewController, didFinishWithResult result: MessageComposeResult) {   
   if result.rawValue == MessageComposeResultSent.rawValue {
       doSomething()
   } else {
       let toast = JLToast.makeText("I am Bob.")
       toast.view.backgroundView.backgroundColor = UIColor(netHex: 0xE50101)
       toast.duration = JLToastDelay.LongDelay
       toast.view.backgroundView.alpha = 0.9
       toast.show()
   }
}

The above method is a callback method of MFMessageComposeViewControllerDelegate. The toast is displayed for a second and removed instantly without animation. Do you have a clue why this happens?

Possible to use with iOS 7.0?

With iOS 7.0 still at over 16% of the market, I have to support it unfortunately. Is there a quick way to get JLToast to support iOS 7?

Library not loaded:

dyld: Library not loaded: @rpath/Toaster.framework/Toaster
Referenced from: /Users/xiang/Library/Developer/CoreSimulator/Devices/7E976FF1-33C4-437A-B562-B13CED4E674A/data/Containers/Bundle/Application/461DCDD6-7AF6-4A0A-8A72-B67C8B112CF5/SwiftDemo.app/SwiftDemo
Reason: image not found

Image support

Feature request: ability to add an image to the toast

There is a device orientation issue!

I tried to use JLToast on my app.
My app allows only portrait for device orientation.

If I rotate my device, the location of toast message is also rotated.
So, I wish JLToast would have orientation options.

How about using "[[UIApplication sharedApplication] statusBarOrientation]" instaed of "[UIDevice currentDevice].orientation"?

Thank you.

offset when using tab bar

Where can I customize toast position? this will be helpful when using tab bars, because toast shows over tab bar. Thanks

Not releasing notification observer

As per Apple docs, you should release observers on deinit, in JLToastCenter.swift:

deinit{

        NSNotificationCenter.defaultCenter().removeObserver(self)

    }

Toast is showing vertically in Landscape iPad

error

JLToastView.setDefaultValue(
            UIColor.redColor(),
            forAttributeName: JLToastViewBackgroundColorAttributeName,
            userInterfaceIdiom: .Pad
        )
        let toast = JLToast.makeText("Testing Toast long toast long toast long toast..")
        toast.show()

show() method should remove previous toasts from the UI

If you call makeText().show() many times in a row for example, when the user is trying to send data and you show a toast message. In case the user tapped the button which triggers the toast many times the UI receives a lot of toast.

Could you manage it somehow to remove previous toast when toasts are still in the UI and you want to show a new toast?

์„ค์น˜๋ฒ•์ด ์–ด๋–ป๊ฒŒ ๋˜๋‚˜์š”?

์•ˆ๋…•ํ•˜์„ธ์š”. ์ดˆ๋ณด ์•„์ดํฐ ๊ฐœ๋ฐœ์ž์ž…๋‹ˆ๋‹ค.

์–ด๋–ป๊ฒŒ ์„ค์น˜ํ•ด์•ผ ํ•˜๋‚˜์š”? Podfile์„ ํ•˜๋‚˜ ๋งŒ๋“ค์–ด์„œ pod 'JLToast', '~> 1.3'๋ฅผ ์ž…๋ ฅํ•˜๊ณ  ํ„ฐ๋ฏธ๋„์—์„œ pod install์„ ์ž…๋ ฅํ–ˆ์Šต๋‹ˆ๋‹ค. Podsํด๋”์•ˆ์— JLToast ํŒŒ์ผ๋“ค์€ ๋“ค์–ด๊ฐ”๋Š”๋ฐ ViewController์—์„œ JLToast.makeText("Basic JLToast").show()๋ฅผ ์ž…๋ ฅํ•˜๋‹ˆ JLToast๋ฅผ ์ฐพ์„ ์ˆ˜ ์—†๋‹ค๊ณ  ํ•˜๋„ค์š”.

๋ญ๊ฐ€ ์ž˜๋ชป๋œ ๊ฑธ๊นŒ์š”? ๋„์›€ ๋ถ€ํƒ๋“œ๋ฆฝ๋‹ˆ๋‹ค.

Toast appears behind keyboard, not visible to user

If the software keyboard is visible toast message appear behind the keyboard not in front of it.

Use case: validation of text inside text field. You want the keyboard to be present however you also want to display a toast. BUT the toast should not block interaction with keyboard.

SWRevealViewController ์™€์˜ UIbarStyle ๋ฌธ์ œ

SWRevealViewController ( https://github.com/John-Lluch/SWRevealViewController) ) ๋กœ ๋งŒ๋“  frontView์™€ rearView ์—์„œ์˜ UIBarStyle ์˜ ์†์„ฑ ๊ฐ’์ด ๋‹ค๋ฅผ ๋•Œ Front(.Black) ์™€ Rear(.Default) ๋ฅผ ์˜ค๊ฐˆ ๋•Œ statusBar ๊ฐ€ ์ž๋™์œผ๋กœ ์Šคํƒ€์ผ์„ ๋ณ€๊ฒฝํ•ฉ๋‹ˆ๋‹ค๋งŒ, ๋ทฐ ๋‚ด์—์„œ JLToas๋ฅผ ํ†ตํ•œ toast ๋ฅผ ํ•œ๋ฒˆ์ด๋ผ๋„ ๋„์šธ ์‹œ, Rear ๋ทฐ์˜ statusBar ๊ฐ€ Front ๋ทฐ์˜ statusBar ์†์„ฑ๊ฐ’์œผ๋กœ ๊ณ ์ •๋ฉ๋‹ˆ๋‹ค.

์‚ฌ์ง„์„ ์ฒจ๋ถ€ํ•  ๊ณณ์ด ์—†์–ด ๊ฐœ์ธ ๋ธ”๋กœ๊ทธ๋กœ ์‚ฌ์ง„์ฒจ๋ถ€๋ฅผ ๋Œ€์‹  ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค
http://ceno-loid.tistory.com/45

I built a project with SWRevealViewController (LINK) and JLToast.
When the property of rearViewโ€™s UIBarStyle is different from frontViewโ€™s one (rearViewBarStyle: .Default, frontViewBarStyle: .Black) UIStatusBar changes its own style itself, but if JLToast is shown more than one time on view, frontViewโ€™s UIBarStyle overrides rearViewโ€™s one.

Here is the link, the photo posted with my own blog.
LINK

Feature Request: Introduce color types

Would like to do:

JLToast.makeText("FooBar", type: JLToastType.Green).show()

with types:

JLToastType.Green
JLToastType.Red
JLToastType.Black (default)

or other example:

JLToast.makeText("FooBar").show(JLToastType.Green)

or

JLToast.makeText("FooBar").showSuccess()

Use-case: I want to make toasts more meaningful like "this is an error" or "entry created successfully". I know there is a way to customize the background but my suggestion would make it easier.

We should be able to customize those types.

Don't working at Alamofire

I am using for JLToast with Alamofire in swift project.
But it doesn't works in Alamofire Closure. It can catch on debugger, but not working.

Can I help for this issue?

Alamofire.request(.POST, "...", parameters: [...]).responseJSON { (req, res, data, err) in
    var json = JSON(data!)
    println(json)
    if (json["status"].stringValue == "error") {
        // Doesn't works!
        JLToast.makeText("...").show();
    } else {
         ...
    }
}

Custom UIColors for background colors

Hey,

I'm having a weird issue:

let toast: JLToast = JLToast()
toast.text = "Some text here."
toast.duration = JLToastDelay.LongDelay
toast.view.backgroundView.backgroundColor = UIColor(red: 77, green: 228, blue: 199, alpha: 1)
toast.show()

The toast does not show up/Is not displayed.

While the same code as above, but with:

...
toast.view.backgroundView.backgroundColor = UIColor.redColor()
...

This displays with a nice red background.

I'm not really sure what's going on here, but any help would be greatly appreciated.

Can't override JLToastViewValue.

Hi,

I tried to override the value of the struct JLToastViewValue but I failed.
Can you modify the code to allow people to override the value in the struct pls?

Thanks

Random crash when calling ActionSheetDialog

Sometimes when I try to call a ActionSheetDialog on my app, the app crashes.
As I don't know what causes the crash (sometimes it happens, sometimes it doesn't) I can't reproduce it with precision. But the part of the code that is crashing the app is in the Toaster Library, on this part:

override open var rootViewController: UIViewController? {
get {
guard !self.isStatusBarOrientationChanging else { return nil }
guard let firstWindow = UIApplication.shared.windows.first else { return nil }
return firstWindow is ToastWindow ? nil : firstWindow.rootViewController
}
set { /* Do nothing */ }
}

More specifically, it's on this line
guard let firstWindow = UIApplication.shared.windows.first else { return nil }

Do you guys have any idea of what could be causing this? Sorry for being so vague but I really have no idea of how to reproduce it and gather more info.

objective c ์ง€์› ์—ฌ๋ถ€

objective c๋Š” ์ง€์› ์•ˆํ•˜๋‚˜์š”?
makeText๋Š” ์ง€์› ์•ˆํ•œ๋‹ค๊ณ  init์„ ์“ฐ๋ผํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋ฒ•์„ ์ž˜ ๋ชจ๋ฅด๊ฒ ์Šต๋‹ˆ๋‹ค.

Carthage support

Skipped building JLToast due to the error:
Dependency "JLToast" has no shared framework schemes for any of the platforms: iOS

Can you make a framework so as to support building via carthage?

Cant install Toaster for Swift 3

ivan.ruiz$ pod install
Analyzing dependencies
Pre-downloading: Toaster from https://github.com/devxoul/JLToast.git
[!] Unable to find a specification for 'Toaster'.

pod 'Toaster'

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.