toolbar
Place items in the navigation bar or bottom bar.
toolbar(content) adds toolbar items to the page that contains the view. content accepts ToolbarItem, ToolbarItemGroup, ToolbarSpacer, components that return them, or an array of them.
import { app } from "onescript"
import {
Button, Modifier, Symbol, Text, ToolbarItemGroup, ToolbarSpacer, useState,
} from "onescript/views"
function Editor() {
const [status, setStatus] = useState("Ready")
return (
<Text modifier={Modifier.toolbar([
<ToolbarSpacer placement="bottomBar" />,
<ToolbarItemGroup placement="bottomBar">
<Button action={() => setStatus("Packages")}><Symbol name="shippingbox" /></Button>
<Button action={() => setStatus("Terminal")}><Symbol name="apple.terminal" /></Button>
<Button action={() => setStatus("Running")}><Symbol name="play" /></Button>
</ToolbarItemGroup>,
<ToolbarSpacer placement="bottomBar" />,
])}>
{status}
</Text>
)
}
await app.show(<Editor />)On iOS 26 and later, the buttons in one ToolbarItemGroup are combined into a single Liquid Glass capsule. The flexible spacers on both sides center the group.
ToolbarItem
Places a single item.
| Prop | Type | Description |
|---|---|---|
placement | ToolbarItemPlacement | Where the item appears. Defaults to "automatic". |
children | ViewChild | The item content, usually a Button. |
ToolbarItemGroup
Places several items at the same placement.
| Prop | Type | Description |
|---|---|---|
placement | ToolbarItemPlacement | Where the items appear. Defaults to "automatic". |
children | ViewChild | The items in the group. |
ToolbarSpacer
Adds space between toolbar items.
| Prop | Type | Description |
|---|---|---|
sizing | "flexible" | "fixed" | Defaults to "flexible". |
placement | ToolbarItemPlacement | Where the spacer appears. Defaults to "automatic". |
ToolbarSpacer uses the native API on iOS 26 and later. On earlier versions, a flexible spacer becomes a flexible space and a fixed spacer has no effect.
ToolbarItemPlacement
| Value | Position |
|---|---|
"automatic" | Chosen by the system. |
"principal" | Center of the navigation bar, replacing the title. |
"navigation" | Navigation actions, usually leading. |
"primaryAction" | Primary action, usually trailing. |
"secondaryAction" | Secondary actions, which may be collapsed into a menu. |
"status" | Status information, usually in the bottom bar. |
"confirmationAction" | Confirm action. |
"cancellationAction" | Cancel action. |
"destructiveAction" | Destructive action. |
"keyboard" | Above the keyboard. |
"topBarLeading" | Leading edge of the navigation bar. |
"topBarTrailing" | Trailing edge of the navigation bar. |
"bottomBar" | Bottom toolbar. |
Behavior
- Toolbars work with or without
NavigationStack. Each pushed page shows only its own toolbar items. - Modifiers chained before
toolbarapply to the content, and modifiers chained after it apply to the result, matching SwiftUI's modifier order. ToolbarItem,ToolbarItemGroup, andToolbarSpacerdo not acceptmodifier. Apply modifiers to the views inside them instead.- The root page also shows the Close and Console buttons at
cancellationActionandconfirmationAction. - Widgets do not support toolbars.
How is this guide?
Last updated on