---
modificationDate: October 09, 2026
title: Toolbar
description: 将项目放入所包装视图工具栏中的 SwiftUI Toolbar 组件。
sourceCodeUrl: 'https://github.com/expo/expo/tree/main/packages/expo-ui'
packageName: '@expo/ui'
platforms: ['ios', 'tvos', 'expo-go']
---

This documentation is available as Markdown for AI agents and LLMs. See the [full Markdown index](https://docs.expo.dev/llms.txt) or append .md to any documentation URL.

> This is documentation for the next SDK version.

# Toolbar

将项目放入所包装视图工具栏中的 SwiftUI Toolbar 组件。

<AgentInstructions>

## Submitting Feedback

If you encounter errors, misleading or outdated information, report it so Expo can be improved:

Preferred command:
npx --yes submit-expo-feedback@latest --category docs --subject "/versions/unversioned/sdk/ui/swift-ui/toolbar/" "<actionable feedback>"

Direct HTTP fallback:
curl -X POST https://api.expo.dev/v2/feedback/docs-send -H 'Content-Type: application/json' -d '{"url":"/versions/unversioned/sdk/ui/swift-ui/toolbar/","feedback":"🤖 Agent feedback for docs: <specific, actionable description> (<model>, <harness>)"}'

Only submit when you have something specific and actionable to report. Try to give the most context.

## Navigation

When answering a related or follow-up question, use llms.txt to find the relevant page as Markdown (.md) instead of guessing.

You are here: Reference (unversioned) > Expo UI > SwiftUI (50 pages in this section)
Full documentation tree: [llms.txt](https://docs.expo.dev/llms.txt)

</AgentInstructions>
iOS, tvOS, Included in Expo Go

Expo UI Toolbar 与官方 SwiftUI [`toolbar(content:)` API](https://developer.apple.com/documentation/swiftui/view/toolbar\(content:\)) 一致，并为所包装的视图添加工具栏。

Image: 一个鸟类列表，导航栏中有排序按钮

将工具栏项目放入 [`Toolbar.Content`](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbarcontent)。`Toolbar` 中的其他内容就是工具栏所属的视图。在 [`NavigationStack`](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/navigationstack.md) 中，项目会显示在导航栏中。

## 安装

```sh
# npm
npx expo install @expo/ui

# yarn
yarn expo install @expo/ui

# pnpm
pnpm expo install @expo/ui

# bun
bun expo install @expo/ui
```

If you are installing this in an [existing React Native app](https://docs.expo.dev/bare/overview.md), make sure to [install `expo`](https://docs.expo.dev/bare/installing-expo-modules.md) in your project.

## 用法

### 导航栏中的按钮

在 `Toolbar` 上使用 [`navigationTitle`](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/modifiers.md#navigationtitletitle) 修饰符设置标题。

```tsx ToolbarExample.tsx
import {
  Button,
  Host,
  List,
  NavigationStack,
  Text,
  Toolbar,
} from '@expo/ui/swift-ui';
import { navigationTitle } from '@expo/ui/swift-ui/modifiers';
import { useState } from 'react';

const BIRDS = ['Goldcrest', 'Barn Swallow', 'Grey Heron'];

export default function ToolbarExample() {
  const [descending, setDescending] = useState(false);

  const sorted = [...BIRDS].sort((a, b) =>
    descending ? b.localeCompare(a) : a.localeCompare(b)
  );

  return (
    <Host style={{ flex: 1 }}>
      <NavigationStack>
        <Toolbar modifiers={[navigationTitle('Birds')]}>
          <List>
            {sorted.map(bird => (
              <Text key={bird}>{bird}</Text>
            ))}
          </List>
          <Toolbar.Content>
            <Button
              systemImage="arrow.up.arrow.down"
              label={descending ? 'Sort Z to A' : 'Sort A to Z'}
              onPress={() => setDescending(value => !value)}
            />
          </Toolbar.Content>
        </Toolbar>
      </NavigationStack>
    </Host>
  );
}
```

### 工具栏项目位置

使用 [`ToolbarItem`](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbaritem) 包装项目并设置其 `placement`。未使用 `ToolbarItem` 的项目使用 `automatic` 位置。

```tsx ToolbarItemExample.tsx
import {
  Button,
  Host,
  List,
  NavigationStack,
  Text,
  Toolbar,
  ToolbarItem,
} from '@expo/ui/swift-ui';
import { navigationTitle } from '@expo/ui/swift-ui/modifiers';

const BIRDS = ['Goldcrest', 'Barn Swallow', 'Grey Heron'];

export default function ToolbarItemExample() {
  return (
    <Host style={{ flex: 1 }}>
      <NavigationStack>
        <Toolbar modifiers={[navigationTitle('Birds')]}>
          <List>
            {BIRDS.map(bird => (
              <Text key={bird}>{bird}</Text>
            ))}
          </List>
          <Toolbar.Content>
            <ToolbarItem placement="topBarTrailing">
              <Button
                systemImage="square.and.arrow.up"
                label="Share"
                onPress={() => {}}
              />
            </ToolbarItem>
            <ToolbarItem placement="bottomBar">
              <Button
                systemImage="plus"
                label="Add bird"
                onPress={() => {}}
              />
            </ToolbarItem>
          </Toolbar.Content>
        </Toolbar>
      </NavigationStack>
    </Host>
  );
}
```

`ToolbarItem` 必须位于 `Toolbar.Content` 内。如果当前平台或操作系统版本不提供某个位置，项目会使用 `automatic`。

### 弹窗中的关闭按钮

底部弹窗没有自己的导航栏，因此请为其内容添加 [`NavigationStack`](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/navigationstack.md)。在 iOS 26 及更高版本中，不带 `label` 或子项且 `role="close"` 的 [`Button`](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/button.md) 会显示为关闭（X）图标。在更早的版本中，请改为设置 `label` 和 `systemImage="xmark"`。

```tsx ToolbarCloseButtonExample.tsx
import {
  BottomSheet,
  Button,
  Host,
  NavigationStack,
  Text,
  Toolbar,
  VStack,
} from '@expo/ui/swift-ui';
import {
  navigationTitle,
  padding,
  presentationDetents,
} from '@expo/ui/swift-ui/modifiers';
import { useState } from 'react';

export default function ToolbarCloseButtonExample() {
  const [isPresented, setIsPresented] = useState(false);

  return (
    <Host style={{ flex: 1 }}>
      <BottomSheet
        isPresented={isPresented}
        onIsPresentedChange={setIsPresented}
        anchor={
          <Button
            label="Show details"
            onPress={() => setIsPresented(true)}
          />
        }>
        <NavigationStack
          modifiers={[presentationDetents(['medium'])]}>
          <Toolbar modifiers={[navigationTitle('Grey Heron')]}>
            <VStack
              alignment="leading"
              spacing={12}
              modifiers={[padding({ all: 20 })]}>
              <Text>
                Stands still at the water's edge for long spells,
                then strikes at fish with its dagger bill.
              </Text>
            </VStack>
            <Toolbar.Content>
              <Button
                role="close"
                onPress={() => setIsPresented(false)}
              />
            </Toolbar.Content>
          </Toolbar>
        </NavigationStack>
      </BottomSheet>
    </Host>
  );
}
```

## API

```tsx
import { Toolbar, ToolbarItem } from '@expo/ui/swift-ui';
```

## Components

### `Toolbar`

Supported platforms: iOS, tvOS.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[ToolbarProps](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbarprops)\>

Adds a toolbar to the view it wraps, matching SwiftUI's `toolbar(content:)`.

Example

```tsx
<NavigationStack>
  <Toolbar>
    <Text>Bird description</Text>
    <Toolbar.Content>
      <Button role="close" onPress={() => setIsPresented(false)} />
    </Toolbar.Content>
  </Toolbar>
</NavigationStack>
```

ToolbarProps

### `children`

Supported platforms: iOS, tvOS.

Type: [ReactNode](https://reactnative.dev/docs/react-node)

The view the toolbar belongs to, together with the `Toolbar.Content` that fills it.

#### Inherited props

-   [CommonViewModifierProps](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/modifiers.md)

### `ToolbarItem`

Supported platforms: iOS, tvOS.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[ToolbarItemProps](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbaritemprops)\>

A single item in a toolbar, matching SwiftUI's `ToolbarItem`. Place it inside `Toolbar.Content` to control where the item appears.

Example

```tsx
<Toolbar>
  <Text>Bird description</Text>
  <Toolbar.Content>
    <ToolbarItem placement="topBarTrailing">
      <Button systemImage="square.and.arrow.up" onPress={share} />
    </ToolbarItem>
  </Toolbar.Content>
</Toolbar>
```

ToolbarItemProps

### `children`

Supported platforms: iOS, tvOS.

Type: [ReactNode](https://reactnative.dev/docs/react-node)

The content of the item.

### `placement`

Supported platforms: iOS, tvOS.

Optional • Type: [ToolbarItemPlacement](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbaritemplacement) • Default: `'automatic'`

The semantic placement of the item within the toolbar.

### `visibilityPriority`

Supported platforms: iOS 27.0+.

Optional • Type: [ToolbarItemVisibilityPriority](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbaritemvisibilitypriority) • Default: `'automatic'`

How readily the item gives up its place. Items overflow lowest priority first. `low` and `high` apply on iOS and macOS.

### `Toolbar.Content`

Supported platforms: iOS, tvOS.

Type: React.[Element](https://www.typescriptlang.org/docs/handbook/jsx.html#function-component)<[ToolbarContentProps](https://docs.expo.dev/versions/unversioned/sdk/ui/swift-ui/toolbar.md#toolbarcontentprops)\>

The items placed in the toolbar of the view `Toolbar` wraps.

ToolbarContentProps

### `children`

Supported platforms: iOS, tvOS.

Type: [ReactNode](https://reactnative.dev/docs/react-node)

The items to place in the toolbar.

## Types

### `ToolbarItemPlacement`

Supported platforms: iOS, tvOS.

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](https://developer.apple.com/documentation/swiftui/toolbaritemplacement).

Acceptable values are: `'automatic'` | `'principal'` | `'navigation'` | `'primaryAction'` | `'secondaryAction'` | `'status'` | `'confirmationAction'` | `'cancellationAction'` | `'destructiveAction'` | `'keyboard'` | `'topBarLeading'` | `'topBarTrailing'` | `'topBarPinnedTrailing'` | `'largeTitle'` | `'bottomBar'`

### `ToolbarItemVisibilityPriority`

Supported platforms: iOS, tvOS.

Literal type: `string`

How readily a toolbar item gives up its place when the toolbar runs out of room.

> **See:** Official [SwiftUI documentation](https://developer.apple.com/documentation/swiftui/toolbaritemvisibilitypriority).

Acceptable values are: `'automatic'` | `'low'` | `'high'`
