SP GlassKit1.1.0

GlassToast

Transient message with a bounded queue, duration, optional action and an accessibility announcement.

  • Custom glass
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-toast

Draws its own Liquid Glass surface, with an opaque form when Reduce Transparency is on.

GlassToast running in SP Glass Studio.Capture
Capture of the component running in SP Glass Studio on the iOS 26.5 simulator. Liquid Glass is rendered by the system; this is an image, not a live preview.

Installation

spglass add glass-toast

Copies the sources and their dependencies into your project. Set up the CLI.

Swift
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")

import SPGlassKit
Identifierglass-toast
ModuleSPGlassComponents
Kindcustom-glass — each toast is one glassSurface; toasts on screen share a GlassGroup
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Feedback/GlassToastExample.swift

Minimal usage

Swift
@State private var toasts = GlassToastCenter()

content
    .glassToastHost(toasts)

toasts.show("Link copied", systemImage: "doc.on.doc")

Variants

VariantUse
GlassToast("…")Message, dismissed after 4 seconds.
title:, systemImage:Optional short title and decorative symbol.
action: GlassToastAction("Undo") { … }One button; the default duration becomes 6 seconds. Activating it runs the handler and dismisses the toast.
GlassToast.persistent("…")Stays until dismissed by the user or the host.
id: "saved"Stable identity: showing the same id again replaces the toast in place and restarts its timer.
placement: .top / .bottomEdge of the host, inside the safe area.

Parameters

GlassToast:

ParameterTypeDefaultMeaning
messageString—Text, already localised by the host.
titleString?nilShort title above the message.
systemImageString?nilDecorative SF Symbol.
idStringrandom UUIDIdentity, used for replacement and dismissal.
durationDuration?4 s, or 6 s with an actionTime on screen; raised to GlassToast.minimumDuration (2 s).
actionGlassToastAction?nilOptional button.

GlassToastCenter(capacity:sleep:announce:):

ParameterDefaultMeaning
capacity3Largest number of toasts kept (at least 1).
sleepTask.sleep(for:)How a duration is awaited; injectable for tests.
announceAccessibilityNotification.Announcement(_:).post()How a new toast is announced.

Methods: show(_:), dismiss(_:), dismissAll(), performAction(of:); toasts is observable.

Appearance

The symbol sits in a small circular tile, the action is a compact capsule and the toast uses neutral glass (never the theme's glass tint) so that the message stays legible in every theme.

States

  • Bounded queue: when a toast arrives while the centre is full, the oldest toast is dropped (the newest event is the one worth showing) and its timer is cancelled.
  • Each toast has its own cancellable timer, started when it is shown. Dismissing, replacing or dropping a toast cancels its timer, so a stale timer can never remove a newer toast with the same id.
  • Nothing is persisted and the centre makes no network call.

Advanced example

Swift
@Environment(GlassToastCenter.self) private var toasts   // placed by glassToastHost

func delete(_ message: Message) {
    store.delete(message)
    toasts.show(GlassToast(String(localized: "Message deleted"), systemImage: "trash", id: "deleted-\(message.id)",
                           action: GlassToastAction(String(localized: "Undo")) { store.restore(message) }))
}

Accessibility

  • Every toast is announced when shown (title, then message) through AccessibilityNotification.Announcement, so VoiceOver users hear it without moving focus.
  • The symbol is decorative and hidden; the action and dismiss buttons are labelled and keep the minimum hit target.
  • With Reduce Motion toasts fade instead of sliding. With Reduce Transparency the surface is opaque.
  • Durations are never shorter than 2 seconds and default to 4 or 6 seconds.

Limits

  • A toast must never be the only carrier of critical information. It disappears by itself and can be missed: errors that need a decision belong in a GlassAlert or a GlassBanner, and an undoable action must remain reversible elsewhere when feasible.
  • Timers are not paused while VoiceOver reads the toast or while the pointer hovers it; use persistent for anything a user must be able to reach at their own pace.
  • Attach glassToastHost once per scene to a view that respects the safe area; the overlay does not avoid the keyboard by itself beyond the host's own safe area.
  • Timing, ordering, bounds, replacement and cancellation are unit-tested with an injected clock; the on-screen placement and the VoiceOver announcement were not exercised in a running application by the automated tests.

Example

Complete example (compiled with the package)
import SwiftUI
import SPGlassKit

public struct GlassToastExample: GlassExample {
    public static let componentID = "glass-toast"
    @State private var toasts = GlassToastCenter(capacity: 3)
    @State private var savedCount = 0
    @State private var restored = false

    public init() {}

    public var body: some View {
        VStack(spacing: 16) {
            GlassButton("Save draft", systemImage: "tray.and.arrow.down") {
                savedCount += 1
                // A stable identifier: saving twice replaces the toast instead of stacking a duplicate.
                toasts.show(GlassToast("Draft saved (\(savedCount))", systemImage: "checkmark.circle", id: "saved"))
            }
            GlassButton("Delete message", systemImage: "trash", role: .destructive) {
                restored = false
                toasts.show(GlassToast("Message deleted", systemImage: "trash", action: GlassToastAction("Undo") { restored = true }))
            }
            GlassButton("Show offline notice", systemImage: "wifi.slash") {
                toasts.show(.persistent("You are offline", title: "Connection", systemImage: "wifi.slash", id: "offline"))
            }
            GlassButton("Dismiss all") { toasts.dismissAll() }
            Text(restored ? "Message restored" : "\(toasts.toasts.count) toasts on screen")
                .font(.callout)
                .foregroundStyle(.secondary)
        }
        .padding()
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .glassToastHost(toasts)
    }
}

#Preview("GlassToast") { GlassToastExample() }

Registry entry

Identifierglass-toast
Version1.1.0
Depends onglass-foundation
FrameworksSwiftUI
Public symbolsGlassToastPlacement, GlassToastView, GlassToastAction, GlassToast, GlassToastCenter
LicenceMIT
Manifestmanifest.json

Files