跳到主要内容

TabBar 底部 tab 栏

固定底部主导航 · 50px 高 · 各 tab icon + 文字 垂直居中。

导航默认采用 surface="glass" 系统材质;贴边实色导航可显式选择 solid。安全区、外边距和定位由宿主负责。

代码演示​

当前页面
首页

视觉规范​

来源:src/components/ui/TabBar/styles.ts、TabBar.tsx。

元素规则
高度50px(fixed.tabbarH,物理常量不缩放)
背景默认 glass 为胶囊玻璃表面;solid 使用主题 c.surface
顶部边线仅 solid 使用 hairline c.outline;glass 不绘制顶部边线
Tab 项flex: 1,垂直居中 icon + 文字
Iconr(22),未选中使用 c.foregroundMuted,选中使用 c.primary
文字10px(type.nano)/ 500,与 icon 同色
Badgec.error 底数字徽章(number | string),叠在 icon 右上
安全区实际 bottom inset 不计入 50px;宿主可用 <SafeAreaView edges={['bottom']}> 包裹

用法​

import {
HomeOutlined,
LocationOutlined,
SparkOutlined,
UserOutlined,
} from '@unif/react-native-icons';
import { TabBar } from '@unif/react-native-design';

<TabBar
active="home"
onChange={setActive}
items={[
{ id: 'home', icon: HomeOutlined, label: '首页' },
{ id: 'visits', icon: LocationOutlined, label: '拜访', badge: 3 },
{ id: 'agent', icon: SparkOutlined, label: 'AI' },
{ id: 'me', icon: UserOutlined, label: '我的' },
]}
/>;

API​

来源:src/components/ui/TabBar/types.ts、TabBar.tsx。

TabBarProps:

参数类型默认值说明
activestring—当前激活 tab 的 id(必填)
onChange(id: string) => void—切换回调,回传点中 tab 的 id(必填)
itemsTabBarItem[]—tab 列表(必填)
surface'solid' | 'glass''glass'系统玻璃或主题实色表面
styleStyleProp<ViewStyle>—根容器的布局与外观样式
testIDstring?—容器 testID;item testID 自动派生为 ${testID}-${id}

TabBarItem:

字段类型默认值说明
idstring—唯一标识,用作 key 与选中判定
iconComponentType<IconProps>—图标组件(见 图标)
labelstring—tab 文字(同时作 accessibilityLabel)
badgenumber | string—图标右上角数字角标(用 string 才能写 '99+')
testIDstring?—单 tab testID(默认 ${barTestID}-${id})

无障碍(a11y)​

来源:src/components/ui/TabBar/TabBar.tsx、types.ts。

  • 默认 accessibilityRole:外层容器为 'tablist',每个 tab 的 <Pressable> 为 'tab'。
  • a11y 名称:没有角标时使用必填的 item.label;badge != null 时组合为 ${item.label},${item.badge}条未读,包括数值 0。
  • 状态语义:accessibilityState={{ selected: on }}——selected 由 item.id === active 派生。无 disabled 语义(TabBarItem 无 disabled 字段)。
import { HomeOutlined, LocationOutlined } from '@unif/react-native-icons';
// 每个 tab 自动 role=tab、label=item.label、selected 由 active 决定
<TabBar
active={active}
onChange={setActive}
items={[
{ id: 'home', icon: HomeOutlined, label: '首页' },
{ id: 'visits', icon: LocationOutlined, label: '拜访', badge: 3 },
]}
/>;

使用注意​

  • ❌ 不要做 5 个以上 tab——超过就用左侧 Drawer
  • ❌ 不要在 active 状态用其他颜色——必须主橙
  • ❌ 不要在 TabBar 里加按钮("发布"等)——用单独的 FAB 或 NavBar 右槽