Expo 路由器原生标签页
一个提供原生标签页布局的 Expo Router 子模块。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
重要 Native tabs 是一个 alpha 功能,适用于 SDK 54 及更高版本,其 API 可能会发生变化。
expo-router/unstable-native-tabs 是 expo-router 的一个子模块,导出用于使用平台原生系统标签页构建标签页布局的组件。
有关适用于原生和 Web 应用的基于文件路由库的更多信息,请参阅 Expo Router 参考文档。
安装
要在你的项目中使用 expo-router/unstable-native-tabs,你需要先在项目中安装 expo-router。请按照 Expo Router 的安装指南操作:
了解如何在你的项目中安装 Expo Router。
在 app 配置中进行配置
如果你使用 默认 模板创建新项目,expo-router 的 配置插件 已经在你的 app 配置中完成配置。
Example app.json with config plugin
{ "expo": { "plugins": ["expo-router"] } }
用法
要了解如何在 Expo Router 中使用原生标签页,请阅读原生标签页指南:
了解如何在你的 Expo Router 应用中使用原生标签页。
API
import { NativeTabs, Icon, Label, Badge, VectorIcon } from 'expo-router/unstable-native-tabs';
Components
Type: React.Element<BadgeProps>
stringThe text to display as the badge for the tab. If not provided, the badge will not be displayed.
ColorValueType: React.Element<LabelProps>
NativeTabsLabelStyleType: React.Element<NativeTabsProps>
The component used to create native tabs layout.
Example
// In _layout file import { NativeTabs } from 'expo-router/unstable-native-tabs'; export default function Layout() { return ( <NativeTabs> <NativeTabs.Trigger name="home" /> <NativeTabs.Trigger name="settings" /> </NativeTabs> ); }
stringThe behavior when navigating back with the back button.
Acceptable values are: 'history' | 'none' | 'initialRoute'
unionThe background color of the tab bar.
Acceptable values are: null | ColorValue
ColorValueThe background color of every badge in the tab bar.
stringThe blur effect applied to the tab bar.
Acceptable values are: 'none' | 'systemDefault' | 'extraLight' | 'light' | 'dark' | 'regular' | 'prominent' | 'systemUltraThinMaterial' | 'systemThinMaterial' | 'systemMaterial' | 'systemThickMaterial' | 'systemChromeMaterial' | 'systemUltraThinMaterialLight' | 'systemThinMaterialLight' | 'systemMaterialLight' | 'systemThickMaterialLight' | 'systemChromeMaterialLight' | 'systemUltraThinMaterialDark' | 'systemThinMaterialDark' | 'systemMaterialDark' | 'systemThickMaterialDark' | 'systemChromeMaterialDark'
booleanWhen set to true, the tab bar will not become transparent when scrolled to the edge.
unionThe color of every tab icon in the tab bar.
Acceptable values are: ColorValue | {
default: ColorValue | undefined,
selected: ColorValue | undefined
}
unionThe style of the every tab label in the tab bar.
Acceptable values are: NativeTabsLabelStyle | {
default: NativeTabsLabelStyle,
selected: NativeTabsLabelStyle
}
stringThe visibility mode of the tab item label.
Acceptable values are: 'auto' | 'selected' | 'labeled' | 'unlabeled'
string • Default: automaticSpecifies the minimize behavior for the tab bar.
Available starting from iOS 26.
The following values are currently supported:
automatic- resolves to the system default minimize behaviornever- the tab bar does not minimizeonScrollDown- the tab bar minimizes when scrolling down and expands when scrolling back uponScrollUp- the tab bar minimizes when scrolling up and expands when scrolling back down
See: The supported values correspond to the official UIKit documentation.
Acceptable values are: 'automatic' | 'never' | 'onScrollDown' | 'onScrollUp'
ColorValueThe color of the ripple effect when the tab is pressed.
ColorValueThe tint color of the tab icon.
Can be overridden by icon color and label color for each tab individually.
{
horizontal: number,
vertical: number
}See: Apple documentation
Type: React.Element<NativeTabsTriggerTabBarProps>
The component used to customize the style of the tab bar, when given trigger is selected.
Prefer this to global changes of tab bar styles, directly in the page.
Note: You can use the alias
NativeTabs.Trigger.TabBarfor this component.
Example
<NativeTabs backgroundColor="black" > <NativeTabs.Trigger name="page"> <NativeTabs.Trigger.TabBar backgroundColor="white" /> <Label>Page</Label> </NativeTabs.Trigger> </NativeTabs>
ColorValueThe background color of the tab bar, when the tab is selected
ColorValueThe background color of every badge in the tab bar.
stringThe blur effect applied to the tab bar, when the tab is selected
Acceptable values are: 'none' | 'systemDefault' | 'extraLight' | 'light' | 'dark' | 'regular' | 'prominent' | 'systemUltraThinMaterial' | 'systemThinMaterial' | 'systemMaterial' | 'systemThickMaterial' | 'systemChromeMaterial' | 'systemUltraThinMaterialLight' | 'systemThinMaterialLight' | 'systemMaterialLight' | 'systemThickMaterialLight' | 'systemChromeMaterialLight' | 'systemUltraThinMaterialDark' | 'systemThinMaterialDark' | 'systemMaterialDark' | 'systemThickMaterialDark' | 'systemChromeMaterialDark'
booleanWhen set to true, the tab bar will not become transparent when scrolled to the edge.
NativeTabsLabelStyleThe style of the every tab label in the tab bar.
ColorValueThe color of the shadow when the tab is selected.
See: Apple documentation
Type: React.Element<NativeTabTriggerProps>
The component used to customize the native tab options both in the _layout file and from the tab screen.
When used in the _layout file, you need to provide a name prop.
When used in the tab screen, the name prop takes no effect.
Example
// In _layout file import { NativeTabs } from 'expo-router/unstable-native-tabs'; export default function Layout() { return ( <NativeTabs> <NativeTabs.Trigger name="home" /> <NativeTabs.Trigger name="settings" /> </NativeTabs> ); }
Example
// In a tab screen import { NativeTabs } from 'expo-router/unstable-native-tabs'; export default function HomeScreen() { return ( <View> <NativeTabs.Trigger> <Label>Home</Label> </NativeTabs.Trigger> <Text>This is home screen!</Text> </View> ); }
Note: You can use the alias
NativeTabs.Triggerfor this component.
ReactNodeThe children of the trigger.
Use Icon, Label, and Badge components to customize the tab.
boolean • Default: falseIf true, the tab will not pop stack to the root when selected again.
boolean • Default: falseIf true, the tab will not scroll to the top when selected again.
stringThe name of the route.
This is required when used inside a Layout component.
When used in a route it has no effect.
NativeTabOptionsThe options for the trigger.
Use Icon, Label, and Badge components as children to customize the tab, rather then raw options.
stringSystem-provided tab bar item with predefined icon and title
Uses Apple's built-in tab bar items (e.g., bookmarks, contacts, downloads) with
standard iOS styling and localized titles. Custom icon or selectedIcon
properties will override the system icon, but the system-defined title cannot
be customized.
Acceptable values are: 'search' | 'history' | 'bookmarks' | 'contacts' | 'downloads' | 'favorites' | 'featured' | 'more' | 'mostRecent' | 'mostViewed' | 'recents' | 'topRated'
Type: React.Element<VectorIconProps<NameT>>
Helper component which can be used to load vector icons for NativeTabs.
Example
import { NativeTabs, VectorIcon } from 'expo-router'; import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons'; export default Layout(){ return ( <NativeTabs> <NativeTabs.Trigger name="index"> <Icon src={<VectorIcon family={MaterialCommunityIcons} name="home" />} /> </NativeTabs.Trigger> </NativeTabs> ); }
{
getImageSource: (name: NameT, size: number, color: ColorValue) => Promise<null | ImageSourcePropType>
}The family of the vector icon.
Example
import MaterialCommunityIcons from '@expo/vector-icons/MaterialCommunityIcons';
Interfaces
| Property | Type | Description |
|---|---|---|
| androidSrc(optional) | ReactElement | ImageSourcePropType | {
default: ReactElement<unknown, string | JSXElementConstructor<any>> | ImageSourcePropType | undefined,
selected: ReactElement<unknown, string | JSXElementConstructor<any>> | ImageSourcePropType
} | Only for: Android The image source to use as an icon on Android. The value can be provided in two ways:
Example
Example
|
| drawable(optional) | undefined | - |
| sf(optional) | SFSymbols6_0 | {
default: SFSymbols6_0 | undefined,
selected: SFSymbols6_0
} | Only for: iOS The name of the SF Symbol to use as an icon on iOS. The value can be provided in two ways:
Example
Example
|
| src(optional) | undefined | - |
| Property | Type | Description |
|---|---|---|
| androidSrc(optional) | undefined | - |
| drawable(optional) | string | Only for: Android The name of the drawable resource to use as an icon. |
| sf(optional) | SFSymbols6_0 | {
default: SFSymbols6_0 | undefined,
selected: SFSymbols6_0
} | Only for: iOS The name of the SF Symbol to use as an icon. The value can be provided in two ways:
Example
Example
|
| src(optional) | undefined | - |
Extends: DefaultRouterOptions
| Property | Type | Description |
|---|---|---|
| backgroundColor(optional) | ColorValue | The color of the background when the tab is selected. |
| badgeBackgroundColor(optional) | ColorValue | The color of all the badges when the tab is selected. |
| badgeTextColor(optional) | ColorValue | Only for: Android Web The color of the badge text. |
| badgeValue(optional) | string | Only for: Android iOS Specifies content of tab bar item badge. On Android, the value is interpreted in the following order:
On iOS, badge is displayed as regular string. |
| blurEffect(optional) | 'none' | 'systemDefault' | 'extraLight' | 'light' | 'dark' | 'regular' | 'prominent' | 'systemUltraThinMaterial' | 'systemThinMaterial' | 'systemMaterial' | 'systemThickMaterial' | 'systemChromeMaterial' | 'systemUltraThinMaterialLight' | 'systemThinMaterialLight' | 'systemMaterialLight' | 'systemThickMaterialLight' | 'systemChromeMaterialLight' | 'systemUltraThinMaterialDark' | 'systemThinMaterialDark' | 'systemMaterialDark' | 'systemThickMaterialDark' | 'systemChromeMaterialDark' | Only for: iOS The blur effect to apply when the tab is selected. |
| disableTransparentOnScrollEdge(optional) | boolean | Only for: iOS When set to |
| icon(optional) | SymbolOrImageSource | Only for: Android iOS The icon to display in the tab bar. |
| iconColor(optional) | ColorValue | The color of the icon when the tab is selected. On iOS 26+ you can change the icon color in the scroll edge state. |
| indicatorColor(optional) | ColorValue | Only for: Android Web The color of the tab indicator. |
| labelStyle(optional) | NativeTabsLabelStyle | The style of all the tab labels, when the tab is selected |
| role(optional) | 'search' | 'history' | 'bookmarks' | 'contacts' | 'downloads' | 'favorites' | 'featured' | 'more' | 'mostRecent' | 'mostViewed' | 'recents' | 'topRated' | Only for: iOS System-provided tab bar item with predefined icon and title Uses Apple's built-in tab bar items (e.g., bookmarks, contacts, downloads) with
standard iOS styling and localized titles. If you override the |
| selectedBadgeBackgroundColor(optional) | ColorValue | The color of the badge when the tab is selected. |
| selectedIcon(optional) | SymbolOrImageSource | Only for: iOS The icon to display when the tab is selected. |
| selectedIconColor(optional) | ColorValue | The color of the icon when the tab is selected. |
| selectedLabelStyle(optional) | NativeTabsLabelStyle | The style of the tab label when the tab is selected. |
| selectedTitlePositionAdjustment(optional) | {
horizontal: number,
vertical: number
} | Only for: iOS The position adjustment for the label when the tab is selected. |
| shadowColor(optional) | ColorValue | |
| title(optional) | string | Only for: Android iOS Title of the tab screen, displayed in the tab bar item. |
| titlePositionAdjustment(optional) | {
horizontal: number,
vertical: number
} | Only for: iOS The position adjustment for all the labels when the tab is selected. |
| Property | Type | Description |
|---|---|---|
| color(optional) | ColorValue | Only for: -Android Web |
| fontSize(optional) | number | Only for: -Android Web |
| iconColor(optional) | ColorValue | Only for: -Android |
| indicatorColor(optional) | ColorValue | Only for: -Android Web |
| Property | Type | Description |
|---|---|---|
| color(optional) | ColorValue | The color of the tab label. |
| fontFamily(optional) | string | The font family of the tab label. |
| fontSize(optional) | number | The font size of the tab label. |
| fontStyle(optional) | 'italic' | 'normal' | The font style of the tab label. |
| fontWeight(optional) | NumericFontWeight | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900' | The font weight of the tab label. |
| Property | Type | Description |
|---|---|---|
| androidSrc(optional) | undefined | - |
| drawable(optional) | undefined | - |
| sf(optional) | undefined | - |
| src(optional) | ReactElement | ImageSourcePropType | {
default: ReactElement<unknown, string | JSXElementConstructor<any>> | ImageSourcePropType | undefined,
selected: ReactElement<unknown, string | JSXElementConstructor<any>> | ImageSourcePropType
} | Only for: Android iOS The image source to use as an icon. The value can be provided in two ways:
Example
Example
|
Types
Type: object shaped as below:
| Property | Type | Description |
|---|---|---|
| drawable(optional) | string | Only for: Android The name of the drawable resource to use as an icon. |
| sf(optional) | SFSymbol | Only for: iOS The name of the SF Symbol to use as an icon. |
Or object shaped as below:
| Property | Type | Description |
|---|---|---|
| src(optional) | ImageSourcePropType | Promise<ImageSourcePropType | null> | The image source to use as an icon. |