SPB Git

Repository Public MIT

example-glass-navigation-bar.txt 2.3 KB 57 lines text

1import SwiftUI2import SPGlassKit34public struct GlassNavigationBarExample: GlassExample {5    public static let componentID = "glass-navigation-bar"6    @State private var notes = ["Quarterly review", "Trip to Lisbon", "A much longer note title that has to wrap or truncate gracefully"]7    @State private var isFlagged = false89    public init() {}1011    public var body: some View {12        GlassNavigationBar(13            "Notes",14            subtitle: "\(notes.count) notes",15            titleDisplay: .large,16            leading: [17                GlassToolbarAction(id: "sort", title: "Sort", systemImage: "arrow.up.arrow.down") { notes.sort() },18            ],19            trailing: [20                GlassToolbarAction(id: "new", title: "New note", systemImage: "square.and.pencil", shortcut: KeyboardShortcut("n"), priority: .high) {21                    notes.append("Untitled \(notes.count + 1)")22                },23                GlassToolbarAction(id: "shuffle", title: "Shuffle", systemImage: "shuffle") { notes.shuffle() },24                GlassToolbarAction(id: "clear", title: "Delete all", systemImage: "trash", role: .destructive, isEnabled: !notes.isEmpty, priority: .low) {25                    notes.removeAll()26                },27            ]28        ) {29            List(notes, id: \.self) { note in30                NavigationLink(note, value: note)31            }32            .overlay {33                if notes.isEmpty { ContentUnavailableView("No notes", systemImage: "note.text") }34            }35            .navigationDestination(for: String.self) { note in36                ScrollView {37                    Text(verbatim: note)38                        .font(.title3)39                        .frame(maxWidth: .infinity, alignment: .leading)40                        .padding()41                }42                .glassNavigationBar(43                    "Note",44                    titleDisplay: .inline,45                    trailing: [46                        GlassToolbarAction(id: "flag", title: isFlagged ? "Remove flag" : "Flag", systemImage: isFlagged ? "flag.fill" : "flag") {47                            isFlagged.toggle()48                        },49                    ]50                )51            }52        }53    }54}5556#Preview("GlassNavigationBar") { GlassNavigationBarExample().glassTheme(.ocean) }57
Files main
Menu

Theme