This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
TabView
一个用于分页或选项卡内容的 SwiftUI TabView 组件。
Expo UI TabView 与官方 SwiftUI TabView API 一致,并通过 tabViewStyle 修饰符在不同样式之间切换。


**注意:**对于跨全屏路由的带路由底部标签导航,请改用
expo-router/unstable-native-tabs。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
每个页面都是一个 <TabView.Tab> 子组件,通过 value 属性进行标识。TabView 本身不会强制设定高度——请为它设置一个 frame,或者将它放在一个会提供高度的父容器中。
页面样式(可滑动分页器)
使用 tabViewStyle({ type: 'page' }) 可获得带可选圆点指示器的横向分页器。传入 defaultSelection 可让分页器从指定页面开始,而无需由 React 来控制它。
受控选择
将 selection 和 onSelectionChange 传入,即可通过 React 状态控制当前标签页。每个 <TabView.Tab> 的 value 会与 selection 进行匹配。当 selection 从 JS 发生变化时,添加 animation 修饰符即可为过渡添加动画效果。
页面指示圆点
结合 tabViewStyle({ type: 'page' }) 使用 indexViewStyle 修饰符来控制圆点指示器。将 indexDisplayMode 设为 'always'、'never' 或 'automatic',并设置 backgroundDisplayMode 以在圆点后渲染一个半透明胶囊背景。
底部标签栏
使用 tabViewStyle({ type: 'automatic' }) 可获得 SwiftUI 默认的标签栏。每个标签页的 label 和 systemImage 会填充到栏项目中。可在某个标签页上使用 badge 修饰符,为其栏项目添加徽标。
注意: 对于跨全屏路由的底部标签导航,请改用
expo-router/unstable-native-tabs。
API
import { TabView } from '@expo/ui/swift-ui';
Component
Type: React.Element<TabViewProps>
A SwiftUI TabView. Pair with modifiers to choose the appearance:
tabViewStyle({ type: 'page' })— swipeable pager.tabViewStyle({ type: 'automatic' })— bottom tab bar.tabViewStyle({ type: 'sidebarAdaptable' })— sidebar on iPad, tab bar on iPhone.
Use <TabView.Tab> children to define pages. Each tab is identified by its
value prop, which is used for selection.
For routed bottom-tab navigation across full-screen routes, prefer
expo-router/unstable-native-tabs.
stringIdentifies this tab. Matched against the parent TabView's selection
and defaultSelection props.
union<TabView.Tab> elements defining the pages.
Acceptable values are: React.ReactElement | React.ReactElement
stringThe initially selected tab when the component is uncontrolled
(no selection prop). Ignored if selection is provided.
(selection: string) => voidCalled when the selected tab changes.
stringThe selected tab (controlled mode). Pair with onSelectionChange.
Pass defaultSelection instead to let the native view manage state.