Skip to content

Beautiful toast notifications with flexible view settings.

License

Notifications You must be signed in to change notification settings

bullinnyc/Toast

Repository files navigation

Toast

Swift Package Manager compatible

Beautiful toast notifications with flexible view settings.

Screenshots

Installation

Going to Xcode File > Add Packages... and add the repository by giving the URL
https://github.com/bullinnyc/Toast
Enjoy!

Usage

import Toast
@main
struct MyApp: App {
    @StateObject private var toast = Toast()
    
    var body: some Scene {
        WindowGroup {
            MyView()
                .environmentObject(toast)
        }
    }
}
struct MyView: View {
    @EnvironmentObject private var toast: Toast
    
    var body: some View {
        Button(
            "Show toast",
            action: {
                // Show toast.
                toast.show(
                    title: "Some title",
                    message: "Some message"
                ) { isShowToast in
                    print(isShowToast)
                }
            }
        )
    }
}

#Preview {
    MyView()
        // Adding an object to a view’s environment makes
        // the toast available to preview.
        .environmentObject(Toast())
}

Cancel next toasts or all toasts if needed

struct MyView: View {
    @EnvironmentObject private var toast: Toast
    
    var body: some View {
        // ...
    }
    
    // Cancel next toasts.
    private func cancelNextToasts() {
        toast.cancelNextToasts()
    }
    
    // Cancel all toasts.
    private func cancelAllToasts() {
        toast.cancelAllToasts()
    }
}

Set the style of Toast

Note: Default style is set to space.
You can try other styles or create your own style with extension ToastStyle.

.space
.mars

Requirements

License

  • Toast is distributed under the MIT License.