Skip to content

A lightweight package adding Toast messages to SwiftUI

Notifications You must be signed in to change notification settings

kemkriszt/ToastyUI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ToastyUI

A lightweight SwiftUI toast message library

Add toast messages to your SwiftUI app with ease preview

Usage

Make a toast container

Apply the toastContainer() modifier on the root of your view hierarchy. Usually the best place for this is directly in your app, but it can go anywhere in your hierarchy. Important is to apply it to a view that is taking app the whole screen so that your toast messages can appear in the right place

struct YourApp: App {
    var body: some Scene {
        WindowGroup {
            ContentView()
                .toastContainer()
        }
    }
} 

Show a toast

Access the showToast environment value inside your view hierarchy. It takes a Toast object as argument and presents it on the screen.

Simple toast with message

showToast(Toast(message: "Hello, world!"))

// or shorthand

showToast("Hello, world!")

Toast with icon

showToast(Toast(icon: Image(systemNaned: "globe", message: "Hello, world!")))

Toast with type

showToast(Toast(type: .error, "My error"))
showToast(Toast(type: .warning, "My warning"))
showToast(Toast(type: .info, "My info")) // equals to Toast("My info")

Each toast type has a predefined icon and icon color. The default type is info and it shows no icon

About

A lightweight package adding Toast messages to SwiftUI

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages