Skip to content

aarons2222/Toastie

Repository files navigation

🍞 Toastie

Swift Package Manager iOS Swift License

A lightweight, modern toast notification library for iOS. Works with both UIKit and SwiftUI. Built for iOS 15+.

Features

  • Dual API — SwiftUI modifier + UIKit manager
  • Slide & Fade — Two animation styles out of the box
  • Top or Bottom — Position toasts where you want them
  • Smart Queue — Multiple toasts display one at a time
  • 5 Styles — Success, error, warning, info, message
  • Swipe to Dismiss — Natural gesture support
  • Haptic Feedback — Configurable tactile response
  • Custom Colours — Override backgrounds and text
  • Thread Safe — Call from any thread
  • Accessibility — VoiceOver ready

Installation

Swift Package Manager

Xcode: File → Swift Packages → Add Package Dependency

https://github.com/aarons2222/Toastie

Package.swift:

dependencies: [
    .package(url: "https://github.com/aarons2222/Toastie", from: "2.0.0")
]

Quick Start

SwiftUI

import SwiftUI
import Toastie

struct ContentView: View {
    @State private var toast: Toastie?
    
    var body: some View {
        VStack(spacing: 20) {
            Button("Success") {
                toast = Toastie(
                    type: .success,
                    title: "Done!",
                    message: "Your changes have been saved."
                )
            }
            
            Button("Error") {
                toast = Toastie(
                    type: .error,
                    title: "Error",
                    message: "Something went wrong."
                )
            }
        }
        .toastieView(toast: $toast)
    }
}

UIKit

import UIKit
import Toastie

class ViewController: UIViewController {
    
    @IBAction func showToast(_ sender: UIButton) {
        ToastieManager.showToastie(
            type: .success,
            title: "Saved",
            message: "Your profile has been updated.",
            in: self
        )
    }
}

Styles

Style Colour Icon
.success Green ✓ Checkmark
.error Red ✕ X mark
.warning Orange ⚠ Triangle
.info Blue ℹ Info
.message Blue 💬 Bubble

Configuration

let config = ToastieConfiguration(
    duration: 5.0,                    // Display time (default: 3s)
    position: .bottom,                // .top or .bottom (default: .top)
    appearance: .slide,               // .slide or .fade (default: .slide)
    enableHapticFeedback: true,       // Vibration (default: true)
    backgroundColor: .purple,         // Custom background
    textColor: .white,                // Custom text colour
    enableSwipeToDismiss: true        // Swipe gesture (default: true)
)

toast = Toastie(
    type: .info,
    title: "Custom",
    message: "Fully configured toast.",
    configuration: config
)

Animation

Toastie supports two animation styles:

Slide (default) — Toasts slide in from the top or bottom edge with a spring animation.

let config = ToastieConfiguration(appearance: .slide)

Fade — Toasts fade in and out.

let config = ToastieConfiguration(appearance: .fade)

Queue

Fire multiple toasts — they'll display one at a time automatically:

for style in ToastieStyle.allCases {
    toast = Toastie(type: style, title: "Queued", message: "Shows in order.")
}

UIKit API

// Basic
ToastieManager.showToastie(type: .success, title: "Title", message: "Message", in: self)

// With config
ToastieManager.showToastie(type: .error, title: "Title", message: "Message", in: self, configuration: config)

// From model
let toast = Toastie(type: .warning, title: "Title", message: "Message")
ToastieManager.showToastie(toast: toast, in: self)

// Dismiss all
ToastieManager.dismissAll()

Demo App

The repo includes a ToastieDemo project with interactive controls for testing all styles, positions, animations, and configurations.

Requirements

  • iOS 15.0+
  • Swift 5.7+
  • Xcode 14+

License

MIT License — see LICENSE for details.


Made with ❤️ by Aaron Strickland

About

iOS toast

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages