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.
CaptureInstallation
spglass add glass-tab-barCopies 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-tab-bar |
|---|---|
| Module | SPGlassNavigation |
| Kind | native-wrapper — the system TabView with Tab values and .tabViewStyle(.sidebarAdaptable) |
| Platforms | iOS 26, iPadOS 26, macOS 26 |
| Example | Examples/Gallery/Navigation/GlassTabBarExample.swift |
Minimal usage
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
| Variant | Use |
|---|---|
badge: .count(3) / .text("New") | Badge on a tab. A count of zero and a blank text show nothing. |
isSearch: true | The 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
| Parameter | Type | Default | Meaning |
|---|---|---|---|
tabs | [GlassTabItem<ID>] | — | Tabs in order. The array may change while the view is on screen. |
state | Binding<GlassTabNavigationState<ID, Route>> | — | Selected tab and the navigation path of every tab. |
minimizeBehavior | GlassTabBarMinimizeBehavior | .automatic | Tab 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 | () -> Accessory | none | Accessory 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
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
Stringvalues supplied already localised, because tabs are data. - All tabs share one
Routetype; use an enum with one case per destination. minimizeBehaviorandbottomAccessorydo 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
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
| Identifier | glass-tab-bar |
|---|---|
| Version | 1.1.0 |
| Depends on | glass-foundation, glass-navigation-support |
| Frameworks | SwiftUI |
| Public symbols | GlassTabBarMinimizeBehavior, GlassTabBar, GlassTabBadgeFormatter |
| Licence | MIT |
| Manifest | manifest.json |
Files
Navigation/Navigation/GlassTabBar.swift7285 bytes · sha256 c01ed0d697eb…