SPB Git

Repository Public MIT

doc-glass-tab-bar.md 4.1 KB 101 lines markdown

1# GlassTabBar23| | |4|---|---|5| Identifier | `glass-tab-bar` |6| Module | `SPGlassNavigation` |7| Kind | `native-wrapper` — the system `TabView` with `Tab` values and `.tabViewStyle(.sidebarAdaptable)` |8| Platforms | iOS 26, iPadOS 26, macOS 26 |9| Example | `Examples/Gallery/Navigation/GlassTabBarExample.swift` |1011## Minimal usage1213```swift14enum AppTab: Hashable, Sendable { case home, library }15enum AppRoute: Hashable, Sendable { case album(String) }1617@State private var state = GlassTabNavigationState<AppTab, AppRoute>(selection: .home)1819GlassTabBar(20    tabs: [21        GlassTabItem(id: .home, title: "Home", systemImage: "house"),22        GlassTabItem(id: .library, title: "Library", systemImage: "square.stack"),23    ],24    state: $state25) { tab in26    RootView(tab: tab)27} destination: { route in28    DetailView(route: route)29}30```3132## Variants3334| Variant | Use |35|---|---|36| `badge: .count(3)` / `.text("New")` | Badge on a tab. A count of zero and a blank text show nothing. |37| `isSearch: true` | The search tab, which the system places apart from the others. |38| `minimizeBehavior:` | `.automatic`, `.onScrollDown`, `.onScrollUp`, `.never`. iPhone only; ignored on iPad and macOS. |39| `bottomAccessory:` | A view the system places above the tab bar on iOS (a mini player). Not shown on macOS. |4041The 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.4243## Parameters4445| Parameter | Type | Default | Meaning |46|---|---|---|---|47| `tabs` | `[GlassTabItem<ID>]` | — | Tabs in order. The array may change while the view is on screen. |48| `state` | `Binding<GlassTabNavigationState<ID, Route>>` | — | Selected tab and the navigation path of every tab. |49| `minimizeBehavior` | `GlassTabBarMinimizeBehavior` | `.automatic` | Tab bar minimisation on iPhone. |50| `root` | `(ID) -> Root` | — | Root view of a tab, placed in that tab's own `NavigationStack`. |51| `destination` | `(Route) -> Destination` | — | View of a route pushed on a tab's stack. |52| `bottomAccessory` | `() -> Accessory` | none | Accessory above the tab bar (iOS). |5354`GlassTabNavigationState` offers `path(for:)`, `setPath(_:for:)`, `push(_:in:)`, `popToRoot(_:)`, `open(_:)` and `reconcile(with:fallback:)`.5556## States5758Selection 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.5960## Advanced example6162```swift63let router = GlassTabRouter<AppTab, AppRoute>(64    schemes: ["myapp", "https"],65    tabs: ["home": .home, "library": .library]66) { tab, components, _ in67    switch (tab, components.count) {68    case (_, 0): []69    case (.library, 1): [.album(components[0])]70    default: nil            // unknown link: ignored71    }72}7374GlassTabBar(tabs: tabs, state: $state, minimizeBehavior: .onScrollDown) { tab in75    RootView(tab: tab)76} destination: { route in77    DetailView(route: route)78} bottomAccessory: {79    MiniPlayer()80}81.onOpenURL { url in82    if let destination = router.destination(for: url) { state.open(destination) }83}84```8586`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`.8788## Accessibility8990- Tabs are system tabs: VoiceOver reads title, position, selection and badge; keyboard and pointer navigation follow the platform.91- Titles are required; a tab is never symbol-only for assistive technologies.92- Badge counts are formatted for the current locale.93- At accessibility text sizes the system shows the large content viewer for the tab bar.9495## Limits9697- Titles are `String` values supplied already localised, because tabs are data.98- All tabs share one `Route` type; use an enum with one case per destination.99- `minimizeBehavior` and `bottomAccessory` do nothing on macOS, where the SDK marks them unavailable or without effect.100- Tab bar minimisation, the bottom accessory and the iPad sidebar switch were compiled for both platforms but not exercised in a running simulator here.101
Files main
Menu

Theme