### Complete AlertToast Setup Example Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md This example demonstrates how to configure success, error, and loading toasts with custom durations, dismiss behaviors, and styling. It utilizes different display modes and error handling via Identifiable items. ```swift import SwiftUI import AlertToast struct ContentView: View { @State private var showSuccess = false @State private var showError: ErrorType? = nil @State private var isLoading = false enum ErrorType: String, Identifiable { case network = "Network Error" case validation = "Validation Failed" case unknown = "Unknown Error" var id: String { self.rawValue } } var body: some View { VStack(spacing: 20) { Button("Show Success (2s auto-dismiss)") { showSuccess = true } Button("Show Error (tap to dismiss)") { showError = .network } Button("Show Loader (manual dismiss)") { isLoading = true DispatchQueue.main.asyncAfter(deadline: .now() + 3) { isLoading = false } } } // Success Alert .toast( isPresenting: $showSuccess, duration: 2, tapToDismiss: true, alert: { AlertToast( displayMode: .banner(.pop), type: .complete(.green), title: "Success", subTitle: "Your changes were saved", style: AlertStyle.style( backgroundColor: Color.white, titleColor: Color.green, subTitleColor: Color.gray ) ) }, completion: { print("Success alert dismissed") } ) // Error Alert .toast( item: $showError, duration: 0, tapToDismiss: true, alert: { error in AlertToast( displayMode: .alert, type: .error(.red), title: error?.rawValue ?? "Error", subTitle: "Please try again", style: AlertStyle.style( backgroundColor: Color(red: 1, green: 0.95, blue: 0.95), titleColor: Color.red ) ) } ) // Loading Alert .toast( isPresenting: $isLoading, alert: { AlertToast( displayMode: .hud, type: .loading, title: "Saving", style: AlertStyle.style( activityIndicatorColor: Color.blue ) ) } ) } } ``` -------------------------------- ### Complete Alert Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Example of configuring a success alert with custom colors. Best for operation success and confirmations. ```swift AlertToast( type: .complete(.green), // Required: Color title: "Success", // Optional subTitle: "Operation completed", // Optional style: AlertStyle.style( backgroundColor: Color.white, titleColor: Color.black ) ) ``` -------------------------------- ### Toast with All Parameters Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/toast-modifier.md This example demonstrates how to configure a toast notification with all available parameters, including custom duration, tap-to-dismiss behavior, offset, and callbacks for tap and completion. ```swift struct ContentView: View { @State private var showAlert = false var body: some View { VStack { Button("Show Alert") { showAlert = true } } .toast( isPresenting: $showAlert, duration: 3, tapToDismiss: true, offsetY: -20, alert: { AlertToast( displayMode: .hud, type: .systemImage("checkmark.circle", .green), title: "Processing", subTitle: "Your request is being processed" ) }, onTap: { print("Alert was tapped") }, completion: { print("Alert dismissed") } ) } } ``` -------------------------------- ### DisplayMode Enum Usage Examples Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/types.md Examples demonstrating how to use the DisplayMode enum to configure alert presentations. ```swift // Centered alert let centered = AlertToast(displayMode: .alert, type: .regular, title: "Alert") // Top HUD let topHud = AlertToast(displayMode: .hud, type: .complete(.green), title: "Done") // Bottom banner with slide animation let banner = AlertToast(displayMode: .banner(.slide), type: .error(.red), title: "Error") // Bottom banner with pop animation let popBanner = AlertToast(displayMode: .banner(.pop), type: .regular, title: "Notice") ``` -------------------------------- ### AlertToast Short Initializer Example Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToast.md Shows how to create a simple HUD-style alert with a regular type and a title. This is useful for quick, less customizable notifications. ```swift let simpleAlert = AlertToast( displayMode: .hud, type: .regular, title: "Processing..." ) ``` -------------------------------- ### Basic AlertToast Setup Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/quick-start.md Demonstrates the fundamental integration of AlertToast into a SwiftUI view. Use this to display a simple alert with a title. Requires importing SwiftUI and AlertToast. ```swift import SwiftUI import AlertToast struct ContentView: View { @State private var showAlert = false var body: some View { VStack { Button("Show Alert") { showAlert = true } } .toast(isPresenting: $showAlert, alert: { AlertToast(type: .regular, title: "Hello!") }) } } ``` -------------------------------- ### AlertToast Full Initializer Example Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToast.md Demonstrates creating a banner-style alert with a success type, title, subtitle, and custom styling. Use this for detailed alert configurations. ```swift let alert = AlertToast( displayMode: .banner(.slide), type: .complete(.green), title: "Success", subTitle: "Your message was sent", style: AlertStyle.style( backgroundColor: Color.white, titleColor: Color.black, titleFont: .headline ) ) ``` -------------------------------- ### AlertStyle Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/index.md Example of configuring AlertStyle with custom colors for background, title, and subtitle. Optional parameters allow for system defaults. ```swift AlertStyle.style( backgroundColor: Color.white, titleColor: Color.black ) ``` -------------------------------- ### System Image Alert Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Example of configuring an alert using an SF Symbol. Best for custom notifications and specific actions. ```swift AlertToast( type: .systemImage("star.fill", .yellow), // Required: SF Symbol name, Color title: "Favorite", subTitle: "Added to favorites", displayMode: .banner(.slide), style: AlertStyle.style() ) ``` -------------------------------- ### Install AlertToast with Swift Package Manager Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/README.md Add the AlertToast library to your project using Swift Package Manager by specifying the repository URL and branch. ```swift .package(url: "https://github.com/elai950/AlertToast.git", branch: "master") ``` -------------------------------- ### Loading Alert Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Example of configuring a loading alert with a custom activity indicator color. Automatically prevents auto-dismiss and tap-to-dismiss. ```swift AlertToast( type: .loading, title: "Processing", subTitle: "Please wait...", style: AlertStyle.style( activityIndicatorColor: Color.blue // Controls spinner color ) ) // When shown with modifier: .toast( isPresenting: $isLoading, alert: { /* AlertToast */ } // duration and tapToDismiss are automatically overridden: // duration = 0 (no auto-dismiss) // tapToDismiss = false (cannot dismiss by tapping) ) ``` -------------------------------- ### Styling an AlertToast Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToast.md Example demonstrating how to apply custom styling to an AlertToast, including background color, text colors, and fonts for a complete alert type. ```swift let styledAlert = AlertToast( displayMode: .alert, type: .complete(.green), title: "Success", subTitle: "Changes saved", style: AlertStyle.style( backgroundColor: Color.white, titleColor: Color.black, subTitleColor: Color.gray, titleFont: .system(.headline, design: .rounded), subTitleFont: .system(.caption, design: .rounded) ) ) ``` -------------------------------- ### AlertToast Usage Examples Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/types.md Demonstrates how to instantiate AlertToast with various AlertType cases. This includes success, error, system images, custom images, loading indicators, and regular text-only alerts. ```swift // Success indicator AlertToast(type: .complete(.green), title: "Success") ``` ```swift // Error indicator AlertToast(type: .error(.red), title: "Failed") ``` ```swift // System symbol AlertToast(type: .systemImage("star.fill", .yellow), title: "Favorite") ``` ```swift // Custom image AlertToast(type: .image("appLogo", .blue), title: "Welcome") ``` ```swift // Loading spinner AlertToast(type: .loading, title: "Processing...") ``` ```swift // Text only AlertToast(type: .regular, title: "Message") ``` -------------------------------- ### Install AlertToast with CocoaPods Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/README.md Integrate the AlertToast library into your project using CocoaPods by adding the 'AlertToast' pod to your Podfile. ```ruby pod 'AlertToast' ``` -------------------------------- ### Customizing Alert Appearance with AlertStyle Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/types.md Demonstrates how to create custom AlertStyle instances with specific colors and fonts for alerts. Shows examples of full customization, minimal changes, and dark mode styling. ```swift // Custom colors and fonts let style = AlertStyle.style( backgroundColor: Color.white, titleColor: Color.black, subTitleColor: Color.gray, titleFont: .system(.headline, design: .rounded), subTitleFont: .system(.caption, design: .rounded), activityIndicatorColor: Color.blue ) let alert = AlertToast( type: .complete(.green), title: "Complete", subTitle: "All set", style: style ) // Minimal customization (blur background, custom title color) let minimalStyle = AlertStyle.style( titleColor: Color.green ) // Dark background with light text let darkStyle = AlertStyle.style( backgroundColor: Color.black, titleColor: Color.white, subTitleColor: Color.lightGray ) ``` -------------------------------- ### Error Alert Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Example of configuring an error alert with custom colors. Best for errors, failures, and warnings. ```swift AlertToast( type: .error(.red), // Required: Color title: "Error", subTitle: "Operation failed", style: AlertStyle.style( backgroundColor: Color(red: 1.0, green: 0.9, blue: 0.9), titleColor: Color.red ) ) ``` -------------------------------- ### Custom Image Alert Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Example of configuring an alert using a custom image from the Assets catalog. Best for branded or app-specific icons. ```swift AlertToast( type: .image("customIcon", .blue), // Required: Asset name, Color title: "Custom", subTitle: "Custom image alert" ) ``` -------------------------------- ### BannerAnimation Enum Usage Examples Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/types.md Examples showing how to use BannerAnimation to set slide or pop animations for banners. ```swift // Smooth slide let slideAlert = AlertToast(displayMode: .banner(.slide), type: .regular) // Bouncy pop let popAlert = AlertToast(displayMode: .banner(.pop), type: .complete(.green)) ``` -------------------------------- ### Multiple Toasts Chained Example Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/toast-modifier.md Demonstrates how to chain multiple .toast() modifiers on a single view to manage different alert types independently. ```swift VStack { /* content */ } .toast(isPresenting: $showSuccess, alert: { AlertToast(type: .complete(.green), title: "Success") }) .toast(isPresenting: $showError, alert: { AlertToast(type: .error(.red), title: "Error") }) .toast(isPresenting: $showInfo, alert: { AlertToast(type: .regular, title: "Info") }) ``` -------------------------------- ### Regular Text Alert Configuration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Example of configuring a text-only alert with custom styling. Best for simple messages and informational alerts. ```swift AlertToast( type: .regular, title: "Notification", subTitle: "This is a text-only alert", displayMode: .banner(.pop), style: AlertStyle.style( backgroundColor: Color.blue, titleColor: Color.white, subTitleColor: Color(white: 0.9) ) ) ``` -------------------------------- ### macOS makeNSView: Create and Start Spinner Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/ActivityIndicator.md Creates an NSProgressIndicator configured as a spinning, indeterminate activity indicator. The animation starts automatically upon creation. ```swift let nsView = NSProgressIndicator() nsView.isIndeterminate = true nsView.style = .spinning nsView.startAnimation(context) return nsView ``` -------------------------------- ### Display a Success Message with Duration Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/00-START-HERE.md This example shows how to display a success toast with a specified duration. The `.complete(.green)` type indicates a successful completion with a green theme. ```swift .toast(isPresenting: $show, duration: 2, alert: { AlertToast(type: .complete(.green), title: "Success") }) ``` -------------------------------- ### Localization with LocalizedStringKey Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Configure AlertToast titles and subtitles using LocalizedStringKey for automatic localization. Examples show English and Spanish strings. ```swift // English AlertToast( type: .complete(.green), title: "Success", // Looks for "Success" in Localizable.strings subTitle: "Profile updated" // Looks for "Profile updated" ) // In Localizable.strings (English): "Success" = "Success"; "Profile updated" = "Profile updated"; // In Localizable.strings (Spanish): "Success" = "Éxito"; "Profile updated" = "Perfil actualizado"; ``` -------------------------------- ### AlertToast Display Mode Usage Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/index.md Example of how to instantiate AlertToast with a specific display mode. The display mode determines the visual presentation of the toast. ```swift AlertToast(displayMode: .banner(.slide), type: .regular) ``` -------------------------------- ### Loading Toast Example Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/toast-modifier.md Use this snippet to display a loading toast. The modifier automatically forces duration to 0 and tapToDismiss to false for loading types. ```swift .toast( isPresenting: $isLoading, alert: { AlertToast(type: .loading, title: "Processing") } ) ``` -------------------------------- ### Complete AlertToast Modifier Example Source: https://github.com/elai950/alerttoast/blob/master/README.md Shows the full signature of the `.toast` modifier, including parameters for duration, tap-to-dismiss behavior, alert content, tap handling, and completion callbacks. ```swift .toast(isPresenting: $showAlert, duration: 2, tapToDismiss: true, alert: { //AlertToast goes here }, onTap: { //onTap would call either if `tapToDismis` is true/false //If tapToDismiss is true, onTap would call and then dismis the alert }, completion: { //Completion block after dismiss }) ``` -------------------------------- ### Display a System Icon Alert Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/quick-start.md Utilize system SF Symbols for alerts, offering a consistent look and feel. This example uses a heart icon with a red color and the `.hud` display mode. ```swift .toast(isPresenting: $showInfo, alert: { AlertToast( displayMode: .hud, type: .systemImage("heart.fill", .red), title: "Favorited" ) }) ``` -------------------------------- ### Full AlertToast Initialization Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Illustrates the complete initialization of an AlertToast object, showing all available parameters for display mode, type, text, fonts, and bold title. ```swift AlertToast(displayMode: .alert/.hud, type: AlertType, title: Optional(String), subTitle: Optional(String), titleFont: Optional(Font), subTitleFont: Optional(Font), boldTitle: Optional(Bool)) ``` -------------------------------- ### main() Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToastModifier.md Renders the alert view with appropriate transition animations based on the display mode. It handles tap gestures and view disappearance, conditionally rendering based on the `isPresenting` state. ```APIDOC ## main() ### Description Renders the alert view with appropriate transition animations based on the display mode. This method conditionally renders the view based on `isPresenting` and applies specific transitions for alert, HUD, and banner display modes. It also attaches gesture and lifecycle handlers. ### Method Signature ```swift @ViewBuilder public func main() -> some View ``` ### Usage This method is typically called internally by the `body` method of the `AlertToastModifier` to construct the view content. ### Animations and Transitions - **Alert**: `.scale(scale: 0.8).combined(with: .opacity)` - **HUD**: `.move(edge: .top).combined(with: .opacity)` - **Banner**: `.slide.combined(with: .opacity)` or `.move(edge: .bottom)` ### Gesture and Lifecycle Handling - **onTapGesture**: If `tapToDismiss` is true, calls `onTap?()` and sets `isPresenting` to false. - **onDisappear**: Calls `completion?()`. ``` -------------------------------- ### iOS makeUIView Implementation Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/ActivityIndicator.md Creates and starts an animated UIActivityIndicatorView with a large style. This function is part of the UIViewRepresentable protocol for iOS. ```swift func makeUIView(context: UIViewRepresentableContext) -> UIActivityIndicatorView { let progressView = UIActivityIndicatorView(style: .large) progressView.startAnimating() return progressView } ``` -------------------------------- ### AlertToast Initializers Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/index.md Provides details on how to initialize AlertToast objects with various configurations. ```APIDOC ## AlertToast Initializers ### Full Init This initializer allows for comprehensive configuration of an AlertToast. ```swift public init( displayMode: DisplayMode = .alert, type: AlertType, title: String? = nil, subTitle: String? = nil, style: AlertStyle? = nil ) ``` ### Short Init A simplified initializer for basic AlertToast creation. ```swift public init( displayMode: DisplayMode, type: AlertType, title: String? = nil ) ``` ``` -------------------------------- ### AlertToast Initialization Parameters Source: https://github.com/elai950/alerttoast/blob/master/README.md Illustrates the available parameters for initializing an `AlertToast` object, including display mode, type, title, subtitle, and style. ```swift AlertToast(displayMode: DisplayMode, type: AlertType, title: Optional(String), subTitle: Optional(String), style: Optional(AlertStyle)) //This is the available customizations parameters: AlertStyle(backgroundColor: Color?, titleColor: Color?, subTitleColor: Color?, titleFont: Font?, subTitleFont: Font?) ``` -------------------------------- ### Efficient AlertToast Construction Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/toast-modifier.md Demonstrates the recommended way to build an AlertToast by constructing it once and capturing it. This avoids rebuilding the alert on every frame. ```swift // GOOD: AlertToast built once, captured let myAlert = AlertToast(type: .complete(.green), title: "Done") .toast(isPresenting: $show, alert: { myAlert }) // WORKS BUT LESS EFFICIENT: Built every frame .toast(isPresenting: $show, alert: { AlertToast(type: .complete(.green), title: "Done") }) ``` -------------------------------- ### Documentation Structure Overview Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/INDEX.md This snippet illustrates the directory structure of the AlertToast documentation, showing the purpose of each file and directory. ```tree /output/ ├── INDEX.md ← You are here ├── README.md ← Project overview ├── quick-start.md ← Common patterns & examples ├── types.md ← Type definitions ├── configuration.md ← Parameters & defaults └── api-reference/ ├── index.md ← Component navigation ├── AlertToast.md ← Main view ├── toast-modifier.md ← Presentation API ├── AlertToastModifier.md ← Internal implementation ├── BlurView.md ← Background effects └── ActivityIndicator.md ← Loading spinner ``` -------------------------------- ### AlertToast Full Initializer Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToast.md Creates an AlertToast with detailed configuration including display mode, type, title, subtitle, and custom styling. ```APIDOC ## AlertToast Full Initializer ### Description Creates an AlertToast with detailed configuration including display mode, type, title, subtitle, and custom styling. ### Method `init` (SwiftUI View Initializer) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **displayMode** (`DisplayMode`) - Optional - Default: `.alert` - How the alert appears on screen (alert/hud/banner) - **type** (`AlertType`) - Required - What content to display in the alert - **title** (`String?`) - Optional - Default: `nil` - Main title text; supports localized strings via `LocalizedStringKey` - **subTitle** (`String?`) - Optional - Default: `nil` - Secondary subtitle text; supports localized strings - **style** (`AlertStyle?`) - Optional - Default: `nil` - Customization options for colors, fonts, and appearance ### Request Example ```swift let alert = AlertToast( displayMode: .banner(.slide), type: .complete(.green), title: "Success", subTitle: "Your message was sent", style: AlertStyle.style( backgroundColor: Color.white, titleColor: Color.black, titleFont: .headline ) ) ``` ### Response #### Success Response - **Return Type**: `AlertToast` (a SwiftUI `View`) ``` -------------------------------- ### AlertToast Short Initializer Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/index.md A concise initializer for basic alert creation, requiring only the display mode, type, and an optional title. ```swift public init( displayMode: DisplayMode, type: AlertType, title: String? = nil ) ``` -------------------------------- ### Presenting AlertToast in SwiftUI Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToast.md Use the .toast() view modifier on any SwiftUI view to present an AlertToast. This example shows how to trigger a completion alert with a title and subtitle. ```swift struct ContentView: View { @State private var showAlert = false var body: some View { VStack { Button("Show Alert") { showAlert = true } } .toast(isPresenting: $showAlert, alert: { AlertToast( displayMode: .banner(.slide), type: .complete(.green), title: "Done", subTitle: "Task completed successfully" ) }) } } ``` -------------------------------- ### Initializing ActivityIndicator with a Specific Color Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/ActivityIndicator.md Illustrates how to initialize an ActivityIndicator with a custom color value. ```swift let indicator = ActivityIndicator(color: .white) ``` -------------------------------- ### Complete or Error Alert Initialization Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Initializes an AlertToast with either a complete (checkmark) or error (xmark) animation, optionally with a specified color. Title and subtitle are also optional. ```swift AlertToast(type: .complete(Color)/.error(Color), title: Optional(String), subTitle: Optional(String)) ``` -------------------------------- ### AlertToast Short Initializer Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToast.md Creates a simplified AlertToast with essential configuration for display mode, type, and an optional title. ```APIDOC ## AlertToast Short Initializer ### Description Creates a simplified AlertToast with essential configuration for display mode, type, and an optional title. ### Method `init` (SwiftUI View Initializer) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters - **displayMode** (`DisplayMode`) - Required - How the alert appears on screen - **type** (`AlertType`) - Required - What content to display - **title** (`String?`) - Optional - Default: `nil` - Main title text ### Request Example ```swift let simpleAlert = AlertToast( displayMode: .hud, type: .regular, title: "Processing..." ) ``` ### Response #### Success Response - **Return Type**: `AlertToast` ``` -------------------------------- ### AlertToast Parameters Reference Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/DOCUMENTATION.md Provides a detailed reference for the parameters available when initializing an AlertToast. This includes display mode, content type, text, and styling options. ```swift AlertToast( displayMode: DisplayMode = .alert, // Position: alert, hud, banner type: AlertType, // Content: complete, error, etc. title: String? = nil, // Main text subTitle: String? = nil, // Secondary text style: AlertStyle? = nil // Colors, fonts, effects ) ``` -------------------------------- ### AlertToast Initializer Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/INDEX.md Parameters available when initializing an AlertToast instance. ```APIDOC ## AlertToast Initializer Parameters ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **displayMode** (DisplayMode) - Optional - Controls how the alert is displayed. - **type** (AlertType) - Required - Specifies the type of alert. - **title** (String?) - Optional - The main title of the alert. - **subTitle** (String?) - Optional - The subtitle for the alert. - **style** (AlertStyle?) - Optional - Customizes the appearance of the alert. ``` -------------------------------- ### Image Alert Initialization Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Initializes an AlertToast using a custom image from the asset catalog. Optional title and subtitle can be provided. ```swift AlertToast(type: .image(String), title: Optional(String), subTitle: Optional(String)) ``` -------------------------------- ### Data-Driven Alerts with NotificationData Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/quick-start.md Implement alerts that are driven by state variables, allowing dynamic content. This example uses a `NotificationData` struct to manage alert properties like title and type, and dismisses automatically after 2 seconds. ```swift @State private var notification: NotificationData? = nil var body: some View { VStack { Button("Show") { notification = NotificationData(title: "Done", type: .complete(.green)) } } .toast(item: $notification, duration: 2, alert: { data in AlertToast( type: data?.type ?? .regular, title: data?.title ) }) } struct NotificationData: Identifiable { let id = UUID() let title: String let type: AlertToast.AlertType } ``` -------------------------------- ### System Image Alert Initialization Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Initializes an AlertToast using an image from SF Symbols, specifying the symbol name and color. Optional title and subtitle can be included. ```swift AlertToast(type: .systemImage(String, Color), title: Optional(String), subTitle: Optional(String)) ``` -------------------------------- ### Basic AlertToast Usage Source: https://github.com/elai950/alerttoast/blob/master/README.md Demonstrates how to show a simple text-based alert toast using the `.toast` modifier. Assign a Binding to `isPresenting` to control visibility. ```swift import AlertToast import SwiftUI struct ContentView: View{ @State private var showToast = false var body: some View{ VStack{ Button("Show Toast"){ showToast.toggle() } } .toast(isPresenting: $showToast){ // ".alert" is the default displayMode AlertToast(type: .regular, title: "Message Sent!") //Choose .hud to toast alert from the top of the screen //AlertToast(displayMode: .hud, type: .regular, title: "Message Sent!") //Choose .banner to slide/pop alert from the bottom of the screen //AlertToast(displayMode: .banner(.slide), type: .regular, title: "Message Sent!") } } } ``` -------------------------------- ### Full User Sign-In Flow with AlertToast Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage This Swift code implements a complete sign-in screen. It includes a button that simulates a sign-in process, displaying a loading indicator, handling incorrect passwords with an error alert, and showing a success alert upon correct credentials. The `presentAlert` modifier is used to display different `AlertToast` types. ```swift var body: some View { VStack{ if loginComplete{ Text("Welcome to AlertToast!") .font(.largeTitle) .bold() .transition(.opacity) }else{ // some content ... Button("Some Login Button") { showLoader.toggle() //Simulate sign-in process: DispatchQueue.main.asyncAfter(deadline: .now() + 2) { //Dismiss the loader because the duration is 0! showLoader.toggle() //Replace with another if password == "123456"{ showComplete.toggle() }else{ showError.toggle() } } } } // some content ... } .presentAlert(isPresenting: $showLoader, duration: 0, tapToDismiss: false){ AlertToast(type: .loading) } .presentAlert(isPresenting: $showError){ AlertToast(type: .error(.red), title: "Error", subTitle: "Incorrect password") } .presentAlert(isPresenting: $showComplete, alert: { AlertToast(type: .complete(.green), title: "Signed In!") }, completion: { dismissed in if dismissed{ withAnimation(.spring()){ loginComplete = true } } }) } ``` -------------------------------- ### Simple Text Alert Initialization Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Initializes an AlertToast with the regular type, allowing for optional title and subtitle. ```swift AlertToast(type: .regular, title: Optional(String), subTitle: Optional(String)) ``` -------------------------------- ### Basic Loading Alert Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/ActivityIndicator.md Demonstrates how to present a basic loading alert with a title and subtitle. The loading state is controlled by a boolean state variable and automatically dismissed after a delay. ```swift import SwiftUI import AlertToast struct ContentView: View { @State private var isLoading = false var body: some View { VStack { Button("Start Loading") { isLoading = true DispatchQueue.main.asyncAfter(deadline: .now() + 3) { isLoading = false } } } .toast(isPresenting: $isLoading, alert: { AlertToast( type: .loading, title: "Processing", subTitle: "Please wait..." ) }) } } ``` -------------------------------- ### AlertToast Full Initializer Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Use this initializer to set up AlertToast with all available display and content options. It allows customization of display mode, alert type, title, subtitle, and overall style. ```swift public init( displayMode: DisplayMode = .alert, type: AlertType, title: String? = nil, subTitle: String? = nil, style: AlertStyle? = nil ) ``` -------------------------------- ### BlurView Initialization Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Initializes a BlurView instance. This struct abstracts platform differences for applying system blur effects. ```APIDOC ## BlurView Initialization ### Description Initializes a BlurView instance. This struct abstracts platform differences for applying system blur effects. ### Method `init()` ### Parameters No parameters are required for initialization. ### Request Example ```swift let blur = BlurView() ``` ### Response - **blurView** (BlurView) - An instance of BlurView configured for the current platform. ``` -------------------------------- ### AlertToast Initialization Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/DOCUMENTATION.md Initializes an AlertToast view with various display and content configurations. It supports full and short initializations, and allows customization of its appearance. ```APIDOC ## AlertToast (Main View) ### Description Initializes an AlertToast view with specified display mode, type, title, subtitle, and style. ### Method `AlertToast(...)` ### Parameters #### AlertToast Parameters - **displayMode** (DisplayMode) - Optional - Controls where the alert appears. Options: `.alert`, `.hud`, `.banner(.slide/.pop)`. - **type** (AlertType) - Required - Controls what content displays. Options: `.complete(Color)`, `.error(Color)`, `.systemImage(name, Color)`, `.image(name, Color)`, `.loading`, `.regular`. - **title** (String?) - Optional - The main text of the alert. - **subTitle** (String?) - Optional - The secondary text of the alert. - **style** (AlertStyle?) - Optional - Customizes the appearance of the alert, including colors and fonts. ### Request Example ```swift AlertToast( displayMode: .banner(.slide), type: .complete(.green), title: "Success", subTitle: "All saved", style: AlertStyle.style(...) ) ``` ``` -------------------------------- ### BlurView Initialization Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Initializes a BlurView instance using its default initializer. No parameters are required. ```swift let blur = BlurView() ``` -------------------------------- ### Basic Alert Display Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Demonstrates how to present a simple alert with a title using the `.presentAlert` modifier. Ensure AlertToast and SwiftUI are imported. ```swift import AlertToast import SwiftUI struct ContentView: View{ @State private var showAlert = false var body: some View{ VStack{ Button("Show Alert"){ showAlert.toggle() } } .presentAlert(isPresenting: $showAlert){ AlertToast(type: .regular, title: "Message Sent!") } } } ``` -------------------------------- ### Create a Basic Success Alert Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/INDEX.md Instantiate an AlertToast with a success type and a title. ```swift AlertToast(type: .complete(.green), title: "Success") ``` -------------------------------- ### AlertToast Essential Parameters Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/quick-start.md Understand the core parameters required for presenting a toast. `isPresenting` controls the visibility, and `alert` defines the content of the toast. ```swift .toast( isPresenting: Binding, alert: () -> AlertToast ) ``` -------------------------------- ### Display a Simple Alert Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/00-START-HERE.md Use this snippet to show a basic alert with a title. Ensure the `show` binding is managed to control presentation. ```swift .toast(isPresenting: $show, alert: { AlertToast(type: .regular, title: "Hello!") }) ``` -------------------------------- ### makeUIView Implementation (iOS) Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Creates and configures a UIVisualEffectView with a system material blur effect for iOS. The blur effect adapts to system appearance changes. ```swift return UIVisualEffectView(effect: UIBlurEffect(style: .systemMaterial)) ``` -------------------------------- ### makeUIView (iOS) Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Creates and configures a UIVisualEffectView with a system material blur effect for iOS. ```APIDOC ## makeUIView (iOS) ### Description Creates and configures a `UIVisualEffectView` with a system material blur effect for iOS. This method is part of the `UIViewRepresentable` protocol. ### Method `makeUIView(context: Context) -> UIVisualEffectView` ### Parameters - **context** (Context) - The context for creating the view. ### Return - **UIVisualEffectView** - A fully configured `UIVisualEffectView` with `.systemMaterial` blur style, ready for display. ``` -------------------------------- ### Displaying Multiple Alert Types Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/quick-start.md Show how to present different toast types (success, error, info) based on separate binding variables. Ensure the binding variables are correctly managed to control toast visibility. ```swift var body: some View { VStack { /* content */ } .toast(isPresenting: $showSuccess, alert: { AlertToast(type: .complete(.green), title: "Success") }) .toast(isPresenting: $showError, alert: { AlertToast(type: .error(.red), title: "Error") }) .toast(isPresenting: $showInfo, alert: { AlertToast(type: .regular, title: "Info") }) } ``` -------------------------------- ### View Extension: toast() Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/index.md Methods for displaying AlertToast instances using view extensions. ```APIDOC ## View Extension: toast() ### Binding-Based Displays an alert based on a binding boolean value. ```swift func toast( isPresenting: Binding, duration: TimeInterval = 2, tapToDismiss: Bool = true, offsetY: CGFloat = 0, alert: @escaping () -> AlertToast, onTap: (() -> ())? = nil, completion: (() -> ())? = nil ) -> some View ``` ### Item-Based Displays an alert based on an identifiable item binding. ```swift func toast( item: Binding, duration: Double = 2, tapToDismiss: Bool = true, offsetY: CGFloat = 0, alert: @escaping (Item?) -> AlertToast, onTap: (() -> ())? = nil, completion: (() -> ())? = nil ) -> some View where Item : Identifiable ``` ``` -------------------------------- ### SwiftUI: Switching Between Blur and Solid Color Backgrounds Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Shows how to conditionally apply either a blurred background (using BlurView implicitly) or a solid color background for AlertToast based on a user-controlled toggle. ```swift struct ContentView: View { @State private var useBlur = true @State private var showAlert = false var body: some View { VStack { Toggle("Use Blur Background", isOn: $useBlur) Button("Show Alert") { showAlert = true } } .toast(isPresenting: $showAlert, alert: { if useBlur { // Uses BlurView implicitly AlertToast(type: .regular, title: "Blur Background") } else { // Uses solid color background AlertToast( type: .regular, title: "Solid Background", style: AlertStyle.style(backgroundColor: Color.white) ) } }) } } ``` -------------------------------- ### Loading Alert Initialization Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Initializes an AlertToast with a loading indicator (spinner). It is recommended to set the duration to 0 in the `.presentAlert` modifier for loading alerts. Optional title and subtitle can be included. ```swift //When using loading, set the duration at the .presentAlert modifier to 0. AlertToast(type: .loading, title: Optional(String), subTitle: Optional(String)) ``` -------------------------------- ### SwiftUI: Using Default Blur Background with AlertToast Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Demonstrates how to present an alert with a default blurred background by simply configuring the AlertToast. BlurView is applied automatically when no specific style is provided. ```swift import SwiftUI import AlertToast struct ContentView: View { @State private var showAlert = false var body: some View { VStack { Button("Show Alert with Blur") { showAlert = true } } .toast(isPresenting: $showAlert, alert: { // BlurView is used automatically as background AlertToast( type: .complete(.green), title: "Success" // No style specified, so BlurView applies ) }) } } ``` -------------------------------- ### Main View Rendering Logic Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToastModifier.md Renders the alert view with transitions based on display mode. Handles tap and disappear events. ```swift @ViewBuilder public func main() -> some View { if isPresenting { switch alert().displayMode { case .alert: alert() .onTapGesture { ... } .onDisappear { ... } .transition(AnyTransition.scale(scale: 0.8).combined(with: .opacity)) case .hud: alert() .overlay(GeometryReader { geo -> AnyView in ... }) .onTapGesture { ... } .onDisappear { ... } .transition(AnyTransition.move(edge: .top).combined(with: .opacity)) case .banner: alert() .onTapGesture { ... } .onDisappear { ... } .transition(alert().displayMode == .banner(.slide) ? AnyTransition.slide.combined(with: .opacity) : AnyTransition.move(edge: .bottom)) } } } ``` -------------------------------- ### makeNSView Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md Creates and configures an NSVisualEffectView with HUD appearance for macOS, suitable for toast notifications. ```APIDOC ## makeNSView ### Description Creates and configures an `NSVisualEffectView` with HUD appearance, suitable for toast notifications. ### Signature ```swift public func makeNSView(context: Context) -> NSVisualEffectView ``` ### Usage ```swift let effectView = NSVisualEffectView() effectView.material = .hudWindow effectView.blendingMode = .withinWindow effectView.state = NSVisualEffectView.State.active return effectView ``` ### Details - **Material**: `.hudWindow` — Designed for floating windows/panels, provides dark semi-transparent blur. - **Blending Mode**: `.withinWindow` — Blurs only the content within the view, not the window itself. - **State**: `.active` — Ensures effect is visible even when window is not focused. ``` -------------------------------- ### Alert Mode Body Implementation Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToastModifier.md Implements the body for the alert display mode, applying a full-screen overlay with centered positioning and spring animation. ```swift case .alert: content .overlay( ZStack { main().offset(y: offsetY) } .frame(maxWidth: screen.width, maxHeight: screen.height, alignment: .center) .edgesIgnoringSafeArea(.all) .animation(Animation.spring(), value: isPresenting) ) .valueChanged(value: isPresenting, onChange: { presented in if presented { onAppearAction() } }) ``` -------------------------------- ### AlertToast Initialization Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/DOCUMENTATION.md Initializes an AlertToast with specified display mode, type, title, subtitle, and style. Use this for custom alert notifications. ```swift AlertToast( displayMode: .banner(.slide), type: .complete(.green), title: "Success", subTitle: "All saved", style: AlertStyle.style(...) ) ``` -------------------------------- ### AlertStyle with Activity Indicator Color Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/ActivityIndicator.md Shows how to set background and activity indicator colors using AlertStyle. Note that the activity indicator color is ignored on macOS but the background ensures contrast. ```swift AlertStyle.style( backgroundColor: Color.black, // Dark background activityIndicatorColor: Color.white // Light spinner (works on iOS, ignored on macOS but background ensures contrast) ) ``` -------------------------------- ### ActivityIndicator makeUIView Context Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/ActivityIndicator.md Demonstrates the makeUIView function for ActivityIndicator, showing that the context parameter is passed for API consistency but not directly used in this implementation. ```swift func makeUIView(context: UIViewRepresentableContext) -> UIActivityIndicatorView { // context not used; passed for API consistency } ``` -------------------------------- ### AlertStyle Parameters Reference Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/DOCUMENTATION.md Lists the parameters for customizing the appearance of an AlertToast using AlertStyle. Allows modification of background, text colors, fonts, and activity indicator color. ```swift AlertStyle.style( backgroundColor: Color? = nil, // nil = blur effect titleColor: Color? = nil, subTitleColor: Color? = nil, titleFont: Font? = nil, subTitleFont: Font? = nil, activityIndicatorColor: Color? = nil ) ``` -------------------------------- ### AlertToast Common Optional Parameters Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/quick-start.md Explore optional parameters to customize toast behavior, such as auto-dismiss duration, tap-to-dismiss functionality, vertical offset, and callback closures for tap and completion events. ```swift .toast( isPresenting: $show, duration: 2, tapToDismiss: true, offsetY: 0, alert: { /* ... */ }, onTap: { /* called on tap */ }, completion: { /* called after dismiss */ } ) ``` -------------------------------- ### Banner Mode Body Implementation Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/AlertToastModifier.md Implements the body for the banner display mode, applying a simple overlay with spring animation. No geometry tracking is needed as the banner handles its own positioning. ```swift case .banner: content .overlay( ZStack { main().offset(y: offsetY) } .animation(Animation.spring(), value: isPresenting) ) .valueChanged(value: isPresenting, onChange: { presented in if presented { onAppearAction() } }) ``` -------------------------------- ### Configure AlertToast for HUD Mode Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Use `.hud` display mode for non-intrusive, top-dropping status updates. This mode is ideal for quick feedback that doesn't interrupt user flow. ```swift AlertToast( displayMode: .hud, type: .systemImage("checkmark.circle", .green), title: "Success", subTitle: "Saved" ) ``` -------------------------------- ### Loading Alert Configuration Source: https://github.com/elai950/alerttoast/wiki/Wiki-Usage Presents a loading alert that does not auto-dismiss and cannot be dismissed by tapping. Set the duration to 0 for indefinite display. ```swift import AlertToast import SwiftUI struct ContentView: View{ @State private var isLoading = false var body: some View{ VStack{ Button("Login Button For Example"){ isLoading.toggle() } } .presentAlert(isPresenting: $isLoading, duration: 0, tapToDismiss: false){ AlertToast(type: .loading) } } } ``` -------------------------------- ### Custom Transparent Background for Alert Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/BlurView.md To control transparency, use a solid background color with an alpha value instead of adjusting blur opacity directly. ```swift AlertStyle.style(backgroundColor: Color.black.opacity(0.3)) ``` -------------------------------- ### Configure AlertToast for Banner Mode (Pop) Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/configuration.md Use `.banner(.pop)` for bottom-popping notifications. This mode offers a slightly more emphasized entrance animation compared to the slide effect. ```swift AlertToast( displayMode: .banner(.pop), // or .banner(.slide) type: .error(.red), title: "Error", subTitle: "Failed to save" ) ``` -------------------------------- ### Chain Alerts Sequentially Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/api-reference/toast-modifier.md Display alerts one after another by setting the presentation binding for the next alert in the completion handler of the current alert. ```swift @State private var showFirst = false @State private var showSecond = false var body: some View { VStack { /* content */ } .toast(isPresenting: $showFirst, alert: { ... }, completion: { showSecond = true // Show next alert after first completes }) .toast(isPresenting: $showSecond, alert: { ... }) ``` -------------------------------- ### Loading AlertToast Source: https://github.com/elai950/alerttoast/blob/master/README.md Displays an `AlertToast` with an activity indicator. When using `.loading`, auto-dismiss is disabled, and `tapToDismiss` is set to false. ```swift //When using loading, duration won't auto dismiss and tapToDismiss is set to false AlertToast(type: .loading, title: Optional(String), subTitle: Optional(String)) ``` -------------------------------- ### Display a Loading Spinner Source: https://github.com/elai950/alerttoast/blob/master/_autodocs/00-START-HERE.md Use this snippet to show a loading indicator. The `loading` binding controls the presentation of the spinner while an operation is in progress. ```swift .toast(isPresenting: $loading, alert: { AlertToast(type: .loading, title: "Processing...") }) ```