This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
Toolbar
将项目放入所包装视图工具栏中的 SwiftUI Toolbar 组件。
Expo UI Toolbar 与官方 SwiftUI toolbar(content:) API 一致,并为所包装的视图添加工具栏。


将工具栏项目放入 Toolbar.Content。Toolbar 中的其他内容就是工具栏所属的视图。在 NavigationStack 中,项目会显示在导航栏中。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
导航栏中的按钮
在 Toolbar 上使用 navigationTitle 修饰符设置标题。
工具栏项目位置
使用 ToolbarItem 包装项目并设置其 placement。未使用 ToolbarItem 的项目使用 automatic 位置。
ToolbarItem 必须位于 Toolbar.Content 内。如果当前平台或操作系统版本不提供某个位置,项目会使用 automatic。
弹窗中的关闭按钮
底部弹窗没有自己的导航栏,因此请为其内容添加 NavigationStack。在 iOS 26 及更高版本中,不带 label 或子项且 role="close" 的 Button 会显示为关闭(X)图标。在更早的版本中,请改为设置 label 和 systemImage="xmark"。
API
import { Toolbar, ToolbarItem } from '@expo/ui/swift-ui';
Components
Type: React.Element<ToolbarProps>
Adds a toolbar to the view it wraps, matching SwiftUI's toolbar(content:).
Example
<NavigationStack> <Toolbar> <Text>Bird description</Text> <Toolbar.Content> <Button role="close" onPress={() => setIsPresented(false)} /> </Toolbar.Content> </Toolbar> </NavigationStack>
ReactNodeThe view the toolbar belongs to, together with the Toolbar.Content that fills it.
Type: React.Element<ToolbarItemProps>
A single item in a toolbar, matching SwiftUI's ToolbarItem. Place it inside Toolbar.Content
to control where the item appears.
Example
<Toolbar> <Text>Bird description</Text> <Toolbar.Content> <ToolbarItem placement="topBarTrailing"> <Button systemImage="square.and.arrow.up" onPress={share} /> </ToolbarItem> </Toolbar.Content> </Toolbar>
ToolbarItemPlacement • Default: 'automatic'The semantic placement of the item within the toolbar.
ToolbarItemVisibilityPriority • Default: 'automatic'How readily the item gives up its place. Items overflow lowest priority first. low and
high apply on iOS and macOS.
Types
Literal type: string
Where an item sits in the toolbar. A placement the current platform or OS version does not
offer falls back to automatic.
See: Official SwiftUI documentation.
Acceptable values are: 'automatic' | 'principal' | 'navigation' | 'primaryAction' | 'secondaryAction' | 'status' | 'confirmationAction' | 'cancellationAction' | 'destructiveAction' | 'keyboard' | 'topBarLeading' | 'topBarTrailing' | 'topBarPinnedTrailing' | 'largeTitle' | 'bottomBar'
Literal type: string
How readily a toolbar item gives up its place when the toolbar runs out of room.
See: Official SwiftUI documentation.
Acceptable values are: 'automatic' | 'low' | 'high'