EasyToast

0.5.0

EasyToast is a lightweight and customizable SwiftUI package that provides easy-to-use toast notifications. Display brief messages to your users with minimal effort.
banghuazhao/EasyToast

What's New

0.5.0

2025-07-19T08:18:19Z

Item-based & Custom Toasts

EasyToast

A lightweight, customizable SwiftUI toast notification library for iOS and macOS.

Version License

📸 Screenshots


📚 Table of Contents


✨ Features

  • Simple Text Toasts: Display a quick message to the user with just a few lines of code.
  • Flexible Positioning: Position the toast at the top, center, or bottom of the screen.
  • Configurable Duration: Control how long the toast remains visible.
  • Customizable Appearance: Background color, text color, corner radius, font, padding, shadow, and text alignment.
  • Predefined Toast Types: Use built-in styles like .success, .error, .warning, and .info.
  • Interactive Toasts: Add custom behavior when the toast is tapped.
  • Custom Toast Views: Display fully custom-designed toast notifications.
  • Item-based Toasts: Show a toast for any optional item, with a custom view for each value.
  • Swift Package Manager Support: Easy integration into your project.

❓ Why EasyToast?

EasyToast is designed for SwiftUI developers who want a simple, flexible, and modern way to show toast notifications. It supports both quick messages and fully custom views, with smooth animations and easy configuration.


💻 Installation

Swift Package Manager

Add EasyToast to your project:

.package(url: "https://github.com/banghuazhao/EasyToast.git", from: "0.4.0")

Or use Xcode:
File > Add Packages... and enter the repo URL.


🚀 Getting Started

import EasyToast

struct ContentView: View {
    @State private var showToast = false

    var body: some View {
        VStack {
            Button("Show Toast") { showToast = true }
        }
        .toast(isPresented: $showToast, message: "Hello, EasyToast!")
    }
}

🛠 Usage

Simple Toast

.toast(isPresented: $showToast, message: "This is a toast message!")

Toast on Top

.toast(isPresented: $showToast, message: "On Top", position: .top)

Customization

.toast(
    isPresented: $showToast,
    message: "Custom Style",
    style: ToastStyle(backgroundColor: .blue, textColor: .white)
)

Predefined Types

.toast(isPresented: $showToast, message: "Success!", type: .success)

🍭 Item-based & Custom Toasts

Item-based Toast

@State var selectedToast: String? = nil

Button("Show Custom Toast") { selectedToast = "Custom Toast!" }

.toast(item: $selectedToast) { value in
    HStack {
        Image(systemName: "checkmark.circle").foregroundColor(.white)
        Text(value).foregroundColor(.white)
    }
    .padding()
    .background(Color.green)
    .cornerRadius(20)
}

Advanced Custom Toasts

Gradient Toast:

.toast(item: $selectedGradientToast) { value in
    HStack {
        Image(systemName: "flame.fill").foregroundColor(.white)
        Text(value).foregroundColor(.white)
    }
    .padding()
    .background(
        LinearGradient(
            gradient: Gradient(colors: [.purple, .blue]),
            startPoint: .leading,
            endPoint: .trailing
        )
    )
    .cornerRadius(20)
}

Toast with Action:

.toast(item: $selectedActionToast, duration: 5) {
    selectedActionToast = nil
} content: { value in
    HStack {
        Image(systemName: "arrow.uturn.left").foregroundColor(.white)
        Text(value).foregroundColor(.white)
        Spacer()
        Text("Undo").bold().foregroundColor(.yellow)
    }
    .padding()
    .background(Color.orange)
    .cornerRadius(20)
}

🕰️ Backward Compatibility

.easyToast is still available for backward compatibility, but is deprecated. Please migrate to .toast and .toast(item:) for new code.


License

EasyToast is released under the MIT License. See LICENSE for details.


Keywords: SwiftUI toast, toast notification, custom toast, iOS, macOS, Swift Package Manager, SPM, SwiftUI library

Description

  • Swift Tools 5.8.0
View More Packages from this Author

Dependencies

  • None
Last updated: Mon Oct 27 2025 09:25:53 GMT-0900 (Hawaii-Aleutian Daylight Time)