This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
文本
用于显示样式化文本内容的组件。
用于显示文本的组件。默认会适配平台配色方案(浅色/深色),并通过 textStyle 提供一组聚焦的排版配置项。
安装
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基本文本
import { Host, Text } from '@expo/ui'; export default function TextExample() { return ( <Host matchContents> <Text>你好,世界!</Text> </Host> ); }
带样式的文本
对排版相关属性(字体大小、字重、对齐方式)使用 textStyle。
import { Host, Text } from '@expo/ui'; export default function StyledTextExample() { return ( <Host matchContents> <Text textStyle={{ fontSize: 24, fontWeight: '700', textAlign: 'center' }}>标题</Text> </Host> ); }
截断长文本
使用 numberOfLines 来限制长文本,并在末尾显示省略号。
import { Host, Text } from '@expo/ui'; export default function TruncatedTextExample() { return ( <Host style={{ flex: 1 }}> <Text numberOfLines={1}> 一行非常长的文本,在单行放不下时会被截断。 </Text> </Host> ); }
API
import { Text } from '@expo/ui';
Component
Type: React.Element<TextProps>
A component for displaying styled text content.
Props for the Text component.
booleanWhether the component is disabled. Disabled components do not respond to user interaction.
ModifierConfig[]Platform-specific modifier escape hatch. Pass an array of modifier configs
from @expo/ui/swift-ui/modifiers or @expo/ui/jetpack-compose/modifiers.
A modifier supplied here replaces any modifier of the same type that the
component derives from style or other props.
numberMaximum number of lines to display. Text is truncated with an ellipsis when exceeded.
() => voidCalled when the component appears on screen.
() => voidCalled when the component is removed from screen.
Pick<ViewStyle, 'padding' | 'paddingHorizontal' | 'paddingVertical' | 'paddingTop' | 'paddingBottom' | 'paddingLeft' | 'paddingRight' | 'backgroundColor' | 'borderRadius' | 'borderWidth' | 'borderColor' | 'opacity' | 'width' | 'height'>Platform-agnostic style properties. These are translated to SwiftUI modifiers on iOS and Jetpack Compose modifiers on Android.
stringIdentifier used to locate the component in end-to-end tests.
{
color: string,
fontFamily: string,
fontSize: number,
fontWeight: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900',
letterSpacing: number,
lineHeight: number,
textAlign: 'center' | 'left' | 'right'
}Text-specific styling (font, color, alignment).