Repository Public MIT
1import SwiftUI2import SPGlassKit34public struct GlassTimelineExample: GlassExample {5 public static let componentID = "glass-timeline"67 // Fictitious delivery log, relative to a fixed instant so that the example is reproducible.8 private static let events: [GlassTimelineEvent] = {9 let start = Date(timeIntervalSince1970: 1_780_300_800)10 func at(_ hours: Double) -> Date { start.addingTimeInterval(hours * 3600) }11 return [12 GlassTimelineEvent(id: "ordered", date: at(0), title: "Order placed", detail: "Order A-1042, three items", systemImage: "cart"),13 GlassTimelineEvent(id: "paid", date: at(0.2), title: "Payment confirmed"),14 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."),15 GlassTimelineEvent(id: "shipped", date: at(27.5), title: "Handed to the carrier", systemImage: "shippingbox"),16 GlassTimelineEvent(id: "transit", date: at(52), title: "In transit 🚚", detail: "مركز الفرز · Centre de tri"),17 GlassTimelineEvent(id: "delivered", date: at(76), title: "Delivered", systemImage: "checkmark", tone: .success),18 ]19 }()2021 @State private var order = GlassTimelineOrder.descending22 @State private var showsEmpty = false2324 public init() {}2526 public var body: some View {27 ScrollView {28 VStack(alignment: .leading, spacing: 16) {29 Picker("Order", selection: $order) {30 Text("Newest first").tag(GlassTimelineOrder.descending)31 Text("Oldest first").tag(GlassTimelineOrder.ascending)32 }33 .pickerStyle(.segmented)34 Toggle("Show the empty state", isOn: $showsEmpty)35 GlassTimeline(showsEmpty ? [] : Self.events, order: order, emptyTitle: "Nothing has happened yet")36 }37 .padding()38 }39 }40}4142#Preview("GlassTimeline") { GlassTimelineExample() }43#Preview("GlassTimeline — français, Tokyo") {44 GlassTimelineExample()45 .environment(\.locale, Locale(identifier: "fr_CA"))46 .environment(\.timeZone, TimeZone(identifier: "Asia/Tokyo") ?? .gmt)47}48