A toast notification library for SwiftUI.
- Easy-to-use toast notifications
- Support for custom icons, messages, and buttons
- Seamless integration with SwiftUI
- Dark mode support
- Slide gesture to dismiss
- Loading state interface with async/await
- Install toast in your root view:
import SwiftUI
import Toasts
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
ContentView()
.installToast(position: .bottom)
}
}
}
- Present a toast:
@Environment(\.presentToast) var presentToast
Button("Show Toast") {
let toast = ToastValue(
icon: Image(systemName: "bell"),
message: "You have a new notification."
)
presentToast(toast)
}
presentToast(
message: "Loading...",
task: {
// Handle loading task
return "Success"
},
onSuccess: { result in
ToastValue(icon: Image(systemName: "checkmark.circle"), message: result)
},
onFailure: { error in
ToastValue(icon: Image(systemName: "xmark.circle"), message: error.localizedDescription)
}
)
- Remove icon
let toast = ToastValue(
message: "Message only toast."
)
- Add button
let toast = ToastValue(
message: "Toast with action required.",
button: ToastButton(title: "Confirm", color: .green, action: {
// Handle button action
})
)
- iOS 14.0+
- Swift 5.9+