This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 55).
徽标
一个用于显示状态指示和计数的 Jetpack Compose 徽标组件。
For the complete documentation index, see llms.txt. Use this Use this file to discover all available pages.
Expo UI Badge 与官方 Jetpack Compose Badge API 保持一致。它会渲染为一个小的彩色指示点,或者显示内容,例如计数数字。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
指示点
没有子元素的 badge 会渲染为一个小圆点指示器。
import { Host, Badge } from '@expo/ui/jetpack-compose'; export default function BadgeDot() { return ( <Host matchContents> <Badge /> </Host> ); }
带计数的 badge
传入一个 Text 子元素以显示数字或标签。
import { Host, Badge, Text } from '@expo/ui/jetpack-compose'; export default function BadgeCount() { return ( <Host matchContents> <Badge containerColor="#EF5350" contentColor="#FFFFFF"> <Text>3</Text> </Badge> </Host> ); }
API
import { Badge } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<BadgeProps>
A badge component matching Compose's Badge.
Renders as a small colored indicator dot, or with content (e.g., a count).
React.ReactNodeOptional content inside the badge (e.g., a Text with a count).
When omitted, renders as a small indicator dot.
For correct M3 sizing (16dp circle for single digits), use
Text with style={{ typography: 'labelSmall' }} as the child.
ColorValue • Default: BadgeDefaults.containerColorBackground color of the badge.
ColorValue • Default: BadgeDefaults.contentColorContent color inside the badge (text/icon tint).