/Toast

Ephemeral Toast-style messages for your SwiftUI app.

Primary LanguageSwiftMIT LicenseMIT

Toast 🍞

A simple weekend project for rendering toast-style elements in the current frame in SwiftUI. This is not a recommended iOS design pattern and should only be used when you need some way to epehemerally and unobtrusively inform the user of something. It is also not production ready and comes with no warranty.

Usage

With a flag

import SwiftUI
import Toast

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

  var body: some View {
    Button("Show a toast!") {
      showToast = true
    }.toast(isPresented: $showToast) {
      Label("I am a toast. 🍞", systemImage: "ladybug")
    }
  }
}

With an Identifiable item

import SwiftUI
import Toast

struct ContentView: View {
    enum Item: String, CaseIterable, Identifiable {
        case misty
        case brock
        case tracy
        case may
        case max
        case dawn

        var id: Self {
            self
        }
    }

    @State private var item: Item?

    var body: some View {
        List(Item.allCases) { item in
            Button(item.rawValue) {
                withAnimation(.easeOut) {
                    self.item = item
                }
            }
        }
        .toast(item: $item) { item in
            Label(item.rawValue, systemImage: "ladybug")
        }
    }
}

License

The MIT License © 2021 Aaron Sky