SP GlassKit1.1.0

GlassTabBar

Typed wrapper around the system TabView with badges, dynamic tabs, per-tab navigation state and deep links.

  • System control
  • iOS 26 · iPadOS 26 · macOS 26
  • Version 1.1.0
  • glass-tab-bar

Drawn by the system. GlassKit configures it and leaves the glass to the system.

GlassTabBar 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-tab-bar

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-tab-bar
ModuleSPGlassNavigation
Kindnative-wrapper — the system TabView with Tab values and .tabViewStyle(.sidebarAdaptable)
PlatformsiOS 26, iPadOS 26, macOS 26
ExampleExamples/Gallery/Navigation/GlassTabBarExample.swift

Minimal usage

Swift
enum AppTab: Hashable, Sendable { case home, library }
enum AppRoute: Hashable, Sendable { case album(String) }

@State private var state = GlassTabNavigationState<AppTab, AppRoute>(selection: .home)

GlassTabBar(
    tabs: [
        GlassTabItem(id: .home, title: "Home", systemImage: "house"),
        GlassTabItem(id: .library, title: "Library", systemImage: "square.stack"),
    ],
    state: $state
) { tab in
    RootView(tab: tab)
} destination: { route in
    DetailView(route: route)
}

Variants

VariantUse
badge: .count(3) / .text("New")Badge on a tab. A count of zero and a blank text show nothing.
isSearch: trueThe search tab, which the system places apart from the others.
minimizeBehavior:.automatic, .onScrollDown, .onScrollUp, .never. iPhone only; ignored on iPad and macOS.
bottomAccessory:A view the system places above the tab bar on iOS (a mini player). Not shown on macOS.

The same code gives a floating tab bar on iPhone, a tab bar that can become a sidebar on iPad and a sidebar on macOS. GlassKit draws no bar of its own.

Parameters

ParameterTypeDefaultMeaning
tabs[GlassTabItem<ID>]—Tabs in order. The array may change while the view is on screen.
stateBinding<GlassTabNavigationState<ID, Route>>—Selected tab and the navigation path of every tab.
minimizeBehaviorGlassTabBarMinimizeBehavior.automaticTab bar minimisation on iPhone.
root(ID) -> Root—Root view of a tab, placed in that tab's own NavigationStack.
destination(Route) -> Destination—View of a route pushed on a tab's stack.
bottomAccessory() -> AccessorynoneAccessory above the tab bar (iOS).

GlassTabNavigationState offers path(for:), setPath(_:for:), push(_:in:), popToRoot(_:), open(_:) and reconcile(with:fallback:).

States

Selection is state.selection. Each tab owns a path, so a tab returns exactly where the user left it. A removed tab is handled by reconcile(with:fallback:), which drops its path and moves the selection if needed. Pressed, focused and selected appearances are drawn by the system.

Advanced example

Swift
let router = GlassTabRouter<AppTab, AppRoute>(
    schemes: ["myapp", "https"],
    tabs: ["home": .home, "library": .library]
) { tab, components, _ in
    switch (tab, components.count) {
    case (_, 0): []
    case (.library, 1): [.album(components[0])]
    default: nil            // unknown link: ignored
    }
}

GlassTabBar(tabs: tabs, state: $state, minimizeBehavior: .onScrollDown) { tab in
    RootView(tab: tab)
} destination: { route in
    DetailView(route: route)
} bottomAccessory: {
    MiniPlayer()
}
.onOpenURL { url in
    if let destination = router.destination(for: url) { state.open(destination) }
}

myapp://library/aurora and https://example.com/library/aurora both select Library and push the album. The router only parses; nothing happens until the host calls open.

Accessibility

  • Tabs are system tabs: VoiceOver reads title, position, selection and badge; keyboard and pointer navigation follow the platform.
  • Titles are required; a tab is never symbol-only for assistive technologies.
  • Badge counts are formatted for the current locale.
  • At accessibility text sizes the system shows the large content viewer for the tab bar.

Limits

  • Titles are String values supplied already localised, because tabs are data.
  • All tabs share one Route type; use an enum with one case per destination.
  • minimizeBehavior and bottomAccessory do nothing on macOS, where the SDK marks them unavailable or without effect.
  • Tab bar minimisation, the bottom accessory and the iPad sidebar switch were compiled for both platforms but not exercised in a running simulator here.

Example

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

public struct GlassTabBarExample: GlassExample {
    public static let componentID = "glass-tab-bar"

    enum DemoTab: String, Hashable, Sendable {
        case today, library, inbox, search
    }

    enum DemoRoute: Hashable, Sendable {
        case album(String)
        case track(String)
    }

    @State private var state = GlassTabNavigationState<DemoTab, DemoRoute>(selection: .today)
    @State private var unread = 3
    @State private var showsInbox = true

    /// Deep links of the demo: `glasskit-demo://library/<album>/<track>`.
    static let router = GlassTabRouter<DemoTab, DemoRoute>(
        schemes: ["glasskit-demo"],
        tabs: ["today": .today, "library": .library, "inbox": .inbox, "search": .search]
    ) { tab, components, _ in
        switch (tab, components.count) {
        case (_, 0): []
        case (.library, 1): [.album(components[0])]
        case (.library, 2): [.album(components[0]), .track(components[1])]
        default: nil
        }
    }

    public init() {}

    private var tabs: [GlassTabItem<DemoTab>] {
        var tabs = [
            GlassTabItem(id: DemoTab.today, title: "Today", systemImage: "sun.max"),
            GlassTabItem(id: DemoTab.library, title: "Library", systemImage: "square.stack"),
        ]
        if showsInbox {
            tabs.append(GlassTabItem(id: .inbox, title: "Inbox", systemImage: "tray", badge: .count(unread)))
        }
        tabs.append(GlassTabItem(id: .search, title: "Search", systemImage: "magnifyingglass", isSearch: true))
        return tabs
    }

    public var body: some View {
        GlassTabBar(tabs: tabs, state: $state, minimizeBehavior: .onScrollDown) { tab in
            root(tab)
        } destination: { route in
            switch route {
            case .album(let name):
                List(1...12, id: \.self) { number in
                    NavigationLink("Track \(number)", value: DemoRoute.track("\(name) · \(number)"))
                }
                .navigationTitle(name)
            case .track(let name):
                Text(verbatim: name).font(.title2).navigationTitle("Now playing")
            }
        }
        .onOpenURL { url in
            if let destination = Self.router.destination(for: url) { state.open(destination) }
        }
        .onChange(of: showsInbox) {
            state.reconcile(with: tabs.map(\.id), fallback: .today)
        }
    }

    @ViewBuilder
    private func root(_ tab: DemoTab) -> some View {
        switch tab {
        case .today:
            List {
                Section("Deep links") {
                    Button("Open “Aurora” in Library") {
                        state.open(GlassTabDestination(tab: .library, path: [.album("Aurora")]))
                    }
                    Button("Open track 4 of “Tides”") {
                        if let url = URL(string: "glasskit-demo://library/Tides/4"),
                           let destination = Self.router.destination(for: url) {
                            state.open(destination)
                        }
                    }
                }
                Section("Dynamic tabs") {
                    Toggle("Show the Inbox tab", isOn: $showsInbox)
                    Stepper("Unread: \(unread)", value: $unread, in: 0...99)
                }
            }
            .navigationTitle("Today")
        case .library:
            List(["Aurora", "Tides", "Quiet Hours", "Granite"], id: \.self) { album in
                NavigationLink(album, value: DemoRoute.album(album))
            }
            .navigationTitle("Library")
        case .inbox:
            List(0..<unread, id: \.self) { index in
                Text("Sample message \(index + 1)")
            }
            .overlay {
                if unread == 0 { ContentUnavailableView("No messages", systemImage: "tray") }
            }
            .navigationTitle("Inbox")
        case .search:
            Text("Search results appear here.")
                .foregroundStyle(.secondary)
                .navigationTitle("Search")
        }
    }
}

#Preview("GlassTabBar") { GlassTabBarExample() }

Registry entry

Identifierglass-tab-bar
Version1.1.0
Depends onglass-foundation, glass-navigation-support
FrameworksSwiftUI
Public symbolsGlassTabBarMinimizeBehavior, GlassTabBar, GlassTabBadgeFormatter
LicenceMIT
Manifestmanifest.json

Files