TabView
Switch between pages with a bottom tab bar.
TabView renders a native SwiftUI tab bar, and each Tab is one page. On iOS 26 and later, the tab bar uses the Liquid Glass style with a selection highlight.
import { app } from "onescript"
import { NavigationLink, NavigationStack, Tab, TabView, Text, useState } from "onescript/views"
function App() {
const [tab, setTab] = useState("home")
return (
<TabView
selection={tab}
onSelectionChange={setTab}
>
<Tab
value="home"
title="Home"
icon="house"
>
<NavigationStack destination={(id: string) => <Text>Item {id}</Text>}>
<NavigationLink value="1">Open item 1</NavigationLink>
</NavigationStack>
</Tab>
<Tab
value="community"
title="Community"
icon={{ name: "store.default.fill", source: "pika" }}
>
<Text>Community</Text>
</Tab>
<Tab
value="settings"
title="Settings"
icon="gearshape"
badge={3}
>
<Text>Settings</Text>
</Tab>
</TabView>
)
}
await app.show(<App />)TabView
| Prop | Type | Description |
|---|---|---|
selection | T | Optional controlled selection. T is string | number. |
onSelectionChange | (value: T) => void | Called when the user switches tabs. Required with selection. |
children | Tab | The tabs. |
Without selection, TabView manages the selection itself and selects the first tab by default.
Tab
| Prop | Type | Description |
|---|---|---|
value | string | number | Unique identifier of the tab. |
title | string | Tab label text. |
icon | string | { name: string; source?: "sf" | "pika" } | Tab icon. A string is an SF Symbol; use an object for a Pika icon. |
badge | number | string | Optional badge. |
children | ViewChild | The tab content. |
The tab bar automatically shows SF Symbols in their filled variant, for example house appears as house.fill. Pika icons are not converted, so use their .fill variants.
Behavior
TabViewmust be the root view passed toapp.show(). It cannot be nested or placed inside aNavigationStack.- Write
<Tab>elements directly insideTabView. Arrays, Fragments, and conditional rendering are allowed, but<Tab>cannot be wrapped in a custom component. - A tab can use a
NavigationStackas its only direct content. Each tab keeps its own navigation stack. - The Close and Console buttons appear on the root page of every tab. When a tab does not set
navigationTitle, itstitleis used as the title; usenavigationTitle("")to hide it. - All tabs are rendered at launch and keep their state when switching.
useEffectin every tab runs at launch. - A
toolbarwithplacement="bottomBar"inside a tab appears above the tab bar. - Widgets do not support
TabView.
How is this guide?
Last updated on