GlassTabBar
| 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.