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.
CaptureInstallation
spglass add glass-toastCopies the sources and their dependencies into your project. Set up the CLI.
.package(url: "https://git.spboucher.ai/sp-glasskit.git", from: "1.1.0")
import SPGlassKit| Identifier | glass-toast |
|---|---|
| Module | SPGlassComponents |
| Kind | custom-glass — each toast is one glassSurface; toasts on screen share a GlassGroup |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Feedback/GlassToastExample.swift |
Minimal usage
@State private var toasts = GlassToastCenter()
content
.glassToastHost(toasts)
toasts.show("Link copied", systemImage: "doc.on.doc")Variants
| Variant | Use |
|---|---|
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 / .bottom | Edge of the host, inside the safe area. |
Parameters
GlassToast:
| Parameter | Type | Default | Meaning |
|---|---|---|---|
message | String | — | Text, already localised by the host. |
title | String? | nil | Short title above the message. |
systemImage | String? | nil | Decorative SF Symbol. |
id | String | random UUID | Identity, used for replacement and dismissal. |
duration | Duration? | 4 s, or 6 s with an action | Time on screen; raised to GlassToast.minimumDuration (2 s). |
action | GlassToastAction? | nil | Optional button. |
GlassToastCenter(capacity:sleep:announce:):
| Parameter | Default | Meaning |
|---|---|---|
capacity | 3 | Largest number of toasts kept (at least 1). |
sleep | Task.sleep(for:) | How a duration is awaited; injectable for tests. |
announce | AccessibilityNotification.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
@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
GlassAlertor aGlassBanner, 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
persistentfor anything a user must be able to reach at their own pace. - Attach
glassToastHostonce 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
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
| Identifier | glass-toast |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassToastPlacement, GlassToastView, GlassToastAction, GlassToast, GlassToastCenter |
| Licence | MIT |
| Manifest | manifest.json |
Files
Components/Feedback/GlassToast.swift7438 bytes · sha256 253f6a2931e0…Components/Feedback/GlassToastCenter.swift9258 bytes · sha256 127e4dc41b73…