跳到主要内容

VersionPill 版本号药丸

About / Splash / 调试面板等显版本号的小药丸。左侧状态点 + 版本号 + 可选 build 后缀,圆角胶囊。

代码演示

下方渲染的就是 src/components/business/VersionPill/VersionPill.tsx 本体。

基础 · 仅版本号
带 build 号
可见 status 文案

用法

import { VersionPill } from '@unif/react-native-design';

{
/* About 屏底 */
}
<VersionPill version="0.2.0" />;

{
/* 内测版本醒目 */
}
<VersionPill
version="2.8.0-beta"
status={{ label: '内测' }}
build="20260525"
/>;

API

来源:src/components/business/VersionPill/types.tsVersionPill.tsx

参数类型默认值说明
versionstring版本号字串('2.8.0',必填)
buildstring?build 号;为空时省略分点与 build 字
statusVersionStatus?{ label: '正常', color: c.success }可见状态文案与状态点颜色;空白 label 回退“状态未知”并在 effect 诊断,省略 color 时使用 c.foregroundMuted
styleStyleProp<ViewStyle>?容器附加样式覆盖

视觉规范(Tokens)

来源:src/components/business/VersionPill/styles.ts

元素规则
胶囊c.surface 底 + hairline c.outline 边,圆角 radius.pill(999),横向 padding 11 / 纵向 5
状态点5×5 圆点(radius.pill),色由 resolved status 决定
状态文字type.microPlus + c.foregroundMuted,始终在状态点旁可见
版本文字type.microPlus(11.5)+ c.foregroundMuted + tabular-nums(等宽数字)
分隔点·type.microPlus + opacity 0.5
build 文字type.micro(11)+ c.foregroundMuted + 等宽字体(fontMono

无障碍(a11y)

来源:src/components/business/VersionPill/VersionPill.tsxtypes.ts

VersionPill 是纯展示徽章,外层本地 <View accessible> 合并名称,例如“版本 2.0.0,build 12,测试中”;没有 build 时对应片段整体省略。空白 status label 会显示并朗读“状态未知”,保留 caller 的合法颜色策略,同时在 effect 诊断。状态点、可见文字、版本和 build 子节点均隐藏为单一焦点。

使用注意

  • 不要硬编码 version —— 走 @/config/brandAPP_VERSION(package.json 派生),build 走 react-native-device-info getBuildNumber()
  • 不要只用颜色表达状态;status.label 必须给出可见且可朗读的状态语义。需要自定义点颜色时从 useColors() 取角色 token,例如 { label: '已废', color: colors.error }