Skip to content

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

License

Notifications You must be signed in to change notification settings

banghuazhao/EasyToast

Repository files navigation

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.5.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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages