[email protected]:ukushu/TOASTack.git
https://github.com/ukushu/TOASTack.git
Works on:
- iOS >= .v16
- macOS >= .v13
- apply on your MainView:
MainView()
.applyToaster()-
Make your own design of ToastView or use
ToastSample1,ToastSample2 -
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:
Toaster.shared.config.animation = .easeInOut
Toaster.shared.config.dimOnToast = true
Toaster.shared.config.edge = .bottom
//... and otherCheck 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:
- 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)
- Multiline title
- Optional SF Symbol (displayed on the left corner)
- Close button (displayed on the right corner)
- Toast color
- Create your own custom toast design
- Polish it for both iOS and macOS
- Place your design in the "Toast_Designs" directory as a separate file
- 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.