Skip to content

NickTrienens2025/OverlayToastStack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SwiftOverlayToast

A lightweight Swift package for displaying toast notifications as overlay windows in iOS and iPadOS applications. The library uses SwiftUI for rendering toast messages and works with both UIKit and SwiftUI applications.

Features

  • Display any SwiftUI view as a toast message
  • Customizable display duration
  • Multiple toasts appear in a vertical stack
  • Automatic dismissal with animations
  • Works in any app state without interfering with existing UI

Installation

Swift Package Manager

Add the following to your Package.swift file:

dependencies: [
    .package(url: "https://github.com/yourusername/SwiftOverlayToast.git", from: "1.0.0")
]

Or add it directly in Xcode:

  1. File > Swift Packages > Add Package Dependency
  2. Enter the repository URL: https://github.com/yourusername/SwiftOverlayToast.git

Usage

Basic Example

import SwiftOverlayToast
import SwiftUI

// Show a simple text toast
SwiftOverlayToast.present(
    view: Text("Hello, World!")
        .padding()
        .background(Color.black.opacity(0.7))
        .foregroundColor(.white)
        .cornerRadius(10),
    duration: 2.0
)

With Custom Content

SwiftOverlayToast.present(
    view: HStack {
        Image(systemName: "checkmark.circle.fill")
            .foregroundColor(.green)
        Text("Success!")
    }
    .padding()
    .background(Color.black.opacity(0.7))
    .foregroundColor(.white)
    .cornerRadius(10),
    duration: 3.0
)

With Interactive Elements

SwiftOverlayToast.present(
    view: VStack {
        Text("Action Required")
            .font(.headline)
        
        HStack {
            Button("Confirm") {
                // Do something
                SwiftOverlayToast.dismissAll()
            }
            .padding(.horizontal)
            
            Button("Cancel") {
                SwiftOverlayToast.dismissAll()
            }
            .padding(.horizontal)
        }
    }
    .padding()
    .background(Color.black.opacity(0.8))
    .foregroundColor(.white)
    .cornerRadius(12),
    duration: 10.0  // Longer duration for interaction
)

Dismiss All Toasts

SwiftOverlayToast.dismissAll()

Requirements

  • iOS 14.0+ / iPadOS 14.0+
  • Swift 5.5+
  • Xcode 13.0+

License

This project is available under the MIT license. See the LICENSE file for more info.

About

A toast framework using a window for each toast with swiftUI content

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages