GlassTimeline
Dated events in order, grouped by day and localised, with an empty state.
- Content
- iOS 26 · iPadOS 26 · macOS 26
- Version 1.1.0
glass-timeline
Content on an opaque, readable surface. Glass is kept for controls.
CaptureInstallation
spglass add glass-timelineCopies 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-timeline |
|---|---|
| Module | SPGlassData |
| Kind | content-component — plain content, no surface and no glass |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Data/GlassTimelineExample.swift |
Minimal usage
ScrollView {
GlassTimeline(events)
}let events = [
GlassTimelineEvent(id: "ordered", date: orderedAt, title: "Order placed"),
GlassTimelineEvent(id: "shipped", date: shippedAt, title: "Handed to the carrier", systemImage: "shippingbox"),
]Variants
| Variant | Use |
|---|---|
order: .ascending | Oldest first (default): a history read from the beginning. |
order: .descending | Most recent first: an activity feed. |
Event with systemImage | The marker is the SF Symbol instead of a dot. |
Event with detail | A second line under the title. |
Parameters
| Parameter | Type | Default | Meaning |
|---|---|---|---|
events | [GlassTimelineEvent] | — | Events in any order. |
order | GlassTimelineOrder | .ascending | Chronological direction. |
emptyTitle | LocalizedStringKey? | nil | Text of the empty state; defaults to the localised "No events". |
GlassTimelineEvent(id:date:title:detail:systemImage:) — title and detail are data and displayed as they are.
Calendar, time zone and locale come from the environment (\.calendar, \.timeZone, \.locale).
Layout and tone
| Parameter | Type | Default | Meaning |
|---|---|---|---|
GlassTimelineEvent.tone | GlassBadgeTone | .accent | Colour of the event's marker. Decorative: the title carries the meaning. |
Each event shows its time in a leading column, a marker on a rail (a tinted tile holding the event's symbol, or a ring) and its title and detail. Day titles are uppercase eyebrow labels followed by a hairline. At accessibility text sizes the time moves above the title. The timeline has no surface of its own: place it in a GlassCard or on a page.
States
- Empty: a
ContentUnavailableViewwithemptyTitle. - Populated: one header per calendar day (complete localised date) followed by that day's events with their time.
Advanced example
GlassTimeline(log, order: .descending, emptyTitle: "Nothing has happened yet")
.environment(\.timeZone, TimeZone(identifier: "Asia/Tokyo") ?? .gmt)
.environment(\.locale, Locale(identifier: "fr_CA"))
// Grouping is a pure function, usable for exports or tests:
var calendar = Calendar(identifier: .gregorian)
calendar.timeZone = TimeZone(identifier: "America/Toronto") ?? .gmt
let days = GlassTimelineLogic.groups(log, order: .ascending, calendar: calendar)
let title = GlassTimelineLogic.dayTitle(days[0].day, calendar: calendar, locale: Locale(identifier: "fr_CA"))Accessibility
- Day titles are headers, so VoiceOver users can jump from day to day with the rotor.
- Each event is one element reading its time, title and detail.
- Markers and the connecting line are decorative and hidden from assistive technologies.
- Dates and times are formatted with
Date.FormatStylein the environment's locale, calendar and time zone; text follows Dynamic Type and wraps. - Layout uses leading and trailing only, so it mirrors in right-to-left languages.
Limits
- The day of an event depends on the time zone: the same instant can appear under different days for two users. This is intended; pass the time zone you want through the environment.
- Days of 23 or 25 hours (daylight saving time) are single groups; grouping relies on
Calendar.startOfDay(for:). - Events with the same date keep the order of the input array.
- Events are sorted and grouped in
bodyon every update; for very long logs paginate in the model. - The timeline has no scroll view of its own and no interaction (no selection, no expansion).
- Events are a fixed value type; a timeline with custom rows should use
GlassTimelineLogicwith its own views.
Example
import SwiftUI
import SPGlassKit
public struct GlassTimelineExample: GlassExample {
public static let componentID = "glass-timeline"
// Fictitious delivery log, relative to a fixed instant so that the example is reproducible.
private static let events: [GlassTimelineEvent] = {
let start = Date(timeIntervalSince1970: 1_780_300_800)
func at(_ hours: Double) -> Date { start.addingTimeInterval(hours * 3600) }
return [
GlassTimelineEvent(id: "ordered", date: at(0), title: "Order placed", detail: "Order A-1042, three items", systemImage: "cart"),
GlassTimelineEvent(id: "paid", date: at(0.2), title: "Payment confirmed"),
GlassTimelineEvent(id: "packed", date: at(21), title: "Parcel packed", detail: "Warehouse 4, aisle 12 — a long note that wraps over several lines on a narrow screen without being cut off."),
GlassTimelineEvent(id: "shipped", date: at(27.5), title: "Handed to the carrier", systemImage: "shippingbox"),
GlassTimelineEvent(id: "transit", date: at(52), title: "In transit 🚚", detail: "مركز الفرز · Centre de tri"),
GlassTimelineEvent(id: "delivered", date: at(76), title: "Delivered", systemImage: "checkmark", tone: .success),
]
}()
@State private var order = GlassTimelineOrder.descending
@State private var showsEmpty = false
public init() {}
public var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 16) {
Picker("Order", selection: $order) {
Text("Newest first").tag(GlassTimelineOrder.descending)
Text("Oldest first").tag(GlassTimelineOrder.ascending)
}
.pickerStyle(.segmented)
Toggle("Show the empty state", isOn: $showsEmpty)
GlassTimeline(showsEmpty ? [] : Self.events, order: order, emptyTitle: "Nothing has happened yet")
}
.padding()
}
}
}
#Preview("GlassTimeline") { GlassTimelineExample() }
#Preview("GlassTimeline — français, Tokyo") {
GlassTimelineExample()
.environment(\.locale, Locale(identifier: "fr_CA"))
.environment(\.timeZone, TimeZone(identifier: "Asia/Tokyo") ?? .gmt)
}
Registry entry
| Identifier | glass-timeline |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-components-support, glass-foundation |
| Frameworks | SwiftUI |
| Public symbols | GlassTimelineEvent, GlassTimelineOrder, GlassTimelineDay, GlassTimelineLogic, GlassTimeline |
| Licence | MIT |
| Manifest | manifest.json |
Files
Data/Data/GlassTimeline.swift12380 bytes · sha256 9cb4419d830a…