Thanks to visit codestin.com
Credit goes to GitHub.com

Skip to content

ukushu/TOASTack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TOASTack = Toast Stack

[email protected]:ukushu/TOASTack.git
https://github.com/ukushu/TOASTack.git

Works on:

  • iOS >= .v16
  • macOS >= .v13

How to use:

  1. apply on your MainView:
MainView()
    .applyToaster()
  1. Make your own design of ToastView or use ToastSample1, ToastSample2

  2. Add toast to the stack of toasts:

Button(action: {
    Toaster.shared.make { id in
        ToastSample1(id: id)
    }
}) {
    Text(verbatim: "Make toast for me!")
}

And that’s it.

Seriously — nothing else needed.

This is result:

1

2

But also there is also exist configs :)

Toaster.shared.config.animation = .easeInOut
Toaster.shared.config.dimOnToast = true
Toaster.shared.config.edge = .bottom
//... and other

How to create more awesome custom designs?

Check out ToastSample2.swift. It demonstrates how to:

  • Populate your toast with dynamic data
  • Create a custom design
  • Add an animated icon
  • Dismiss the toast with a horizontal swipe in either direction

Now, let’s implement a “random toast generator” using the ToastSample2 view:

func makeSomeToast() {
    let title = ["Hello", "Title", "You miss the call", "Banana", "I'm waiting for you", "Why so sad?"]
        .randomElement()!
    let sf = ["bell", "bell.and.waves.left.and.right.fill","music.note","exclamationmark.3","exclamationmark.shield"]
        .randomElement()!
    let color = [Color.black, Color.blue, Color.red, Color.brown].randomElement()!
    
    let toastData = SampleToastData(title: title, descr: "Some descr text blablabla bla", sfSymbol: sf, color: color)
    
    Toaster.shared
        .make { id in
            // custom design of the toast
            ToastSample2(id: id)
                // Put data to display into the toast
                .environmentObject(toastData)
        }
}

result:

IMG_8529

Current Toast design templates:

CapsuleToast:

image
  • iOS/macOS polished
  • Title
  • Optional description (displayed in one line only)
  • Optional SF Symbol (displayed on the left corner)
  • Close button (displayed on the right corner)

CRToast:

image

  • Multiline title
  • Optional SF Symbol (displayed on the left corner)
  • Close button (displayed on the right corner)
  • Toast color

How you can help this project?

  1. Create your own custom toast design
  2. Polish it for both iOS and macOS
  3. Place your design in the "Toast_Designs" directory as a separate file
  4. Submit a Pull Request — share your toast template with the community! :)

OR

You can improve existed designs :) Feel free to do this as you want :)

PS: If you need support of watchOS/ VisionOS - feel free to make Pull Request with edit of "Package.swift" after testing on real device.

Releases

No releases published

Packages

No packages published

Languages