### Present a Toast with Loading State and Callbacks (SwiftUI) Source: https://github.com/sunghyun-k/swiftui-toasts/blob/main/README.md This advanced usage example demonstrates presenting a toast that indicates a loading state. It utilizes a `task` closure for the asynchronous operation and provides `onSuccess` and `onFailure` closures to handle the outcome, displaying appropriate messages and icons. ```swift 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) } ) ``` -------------------------------- ### Install Toast in Root View (SwiftUI) Source: https://github.com/sunghyun-k/swiftui-toasts/blob/main/README.md This code snippet demonstrates how to install the toast notification library in the root view of a SwiftUI application. It uses the `.installToast` modifier to set the default position of the toasts. This is a prerequisite for presenting any toasts. ```swift import SwiftUI import Toasts @main struct MyApp: App { var body: some Scene { WindowGroup { ContentView() .installToast(position: .bottom) } } } ``` -------------------------------- ### Present a Basic Toast with Icon and Message (SwiftUI) Source: https://github.com/sunghyun-k/swiftui-toasts/blob/main/README.md This snippet shows how to present a simple toast notification using the `presentToast` environment variable. It includes an icon and a message. The `ToastValue` struct is used to define the content of the toast. ```swift @Environment(\.presentToast) var presentToast Button("Show Toast") { let toast = ToastValue( icon: Image(systemName: "bell"), message: "You have a new notification." ) presentToast(toast) } ``` -------------------------------- ### Present a Toast with a Button Action (SwiftUI) Source: https://github.com/sunghyun-k/swiftui-toasts/blob/main/README.md This snippet shows how to add an actionable button to a toast notification. The `ToastButton` struct allows defining a title, color, and an action closure that is executed when the button is tapped. ```swift let toast = ToastValue( message: "Toast with action required.", button: ToastButton(title: "Confirm", color: .green, action: { // Handle button action }) ) ``` -------------------------------- ### Present a Toast with Only a Message (SwiftUI) Source: https://github.com/sunghyun-k/swiftui-toasts/blob/main/README.md This code illustrates how to create and present a toast notification that only contains a message, without any icon. This is useful for simple informational toasts where an icon is not necessary. ```swift let toast = ToastValue( message: "Message only toast." ) ``` -------------------------------- ### Add Toast Safe Area Observer (SwiftUI) Source: https://github.com/sunghyun-k/swiftui-toasts/blob/main/README.md This modifier, `.addToastSafeAreaObserver()`, is used to manually manage safe area insets for toasts, particularly in complex view hierarchies like TabView. It ensures toasts are displayed correctly in relation to safe areas. ```swift struct ContentView: View { var body: some View { TabView { Tab1View() Tab2View() } } } struct Tab1View: View { var body: some View { ScrollView { // Your content here } .addToastSafeAreaObserver() } } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.