This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
文本
用于显示样式化文本的 Jetpack Compose Text 组件。
信息 有关跨平台使用,请参阅通用
Text—— 它会根据平台呈现相应的原生组件。
Expo UI 文本与官方 Jetpack Compose 文本样式 API 匹配,并使用 Material 3 排版样式、自定义字体和文本格式选项显示文本。
🌐 Expo UI Text matches the official Jetpack Compose Text styling API and displays text with Material 3 typography styles, custom fonts, and text formatting options.


安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
基础文本
🌐 Basic text
排版样式
🌐 Typography styles
将 style 属性与 typography 一起使用以应用 Material 3 排版预设。
🌐 Use the style prop with typography to apply Material 3 typography presets.
具有最大行数和溢出的文本
🌐 Text with maxLines and overflow
使用 maxLines 和 overflow 控制文本截断。
🌐 Control text truncation with maxLines and overflow.
样式化文本
🌐 Styled text
应用自定义文本样式,包括字体粗细、样式、大小和装饰。
🌐 Apply custom text styles including font weight, style, size, and decoration.
嵌套文本
🌐 Nested text
嵌套 <Text> 组件以对句子的部分应用行内样式。子 span 会继承父元素的样式。例如,一个加粗的父元素包含一个斜体的子元素时,子元素会同时呈现加粗和斜体。
🌐 Nest <Text> components to apply inline styles to parts of a sentence. Child spans inherit styles from their parent. For example, a bold parent with an italic child renders the child as bold and italic.
自定义字体
🌐 Custom fonts
通过将字体系列名称传递给 style.fontFamily 来使用通过 expo-font 加载的字体。
🌐 Use fonts loaded via expo-font by passing the font family name to style.fontFamily.
应用接口
🌐 API
import { Text } from '@expo/ui/jetpack-compose';
Component
Type: React.Element<TextProps>
Renders a Text component using Jetpack Compose.
ReactNodeThe text content to display. Can be a string, number, or nested Text components
for inline styled spans.
numberAn optional maximum number of lines for the text to span, wrapping if necessary. If the text exceeds the given number of lines, it will be truncated according to overflow.
numberThe minimum height in terms of minimum number of visible lines.
booleanWhether the text should break at soft line breaks. If false, the glyphs in the text will be positioned as if there was unlimited horizontal space.
TextStyleStyle configuration for the text. Corresponds to Jetpack Compose's TextStyle parameter.
Types
Literal type: string
Text alignment options.
Acceptable values are: 'left' | 'right' | 'center' | 'justify' | 'start' | 'end'
Literal type: string
Text decoration options.
Acceptable values are: 'none' | 'underline' | 'lineThrough'
Literal type: string
Font family for text styling. Built-in system families: 'default', 'sansSerif', 'serif', 'monospace', 'cursive'. Custom font families loaded via expo-font can be referenced by name (for example, 'Inter-Bold').
Acceptable values are: 'default' | 'sansSerif' | 'serif' | 'monospace' | 'cursive'
Literal type: string
Font style options for text styling.
Acceptable values are: 'normal' | 'italic'
Literal type: string
Font weight options for text styling.
Acceptable values are: 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900'
Literal type: string
Line break strategy options.
- 'simple': Basic line breaking.
- 'heading': Optimized for short text like headings.
- 'paragraph': Produces more balanced line lengths for body text.
Acceptable values are: 'simple' | 'heading' | 'paragraph'
Literal type: string
Text overflow behavior options.
- 'clip': Clips the overflowing text to fit its container
- 'ellipsis': Uses an ellipsis to indicate that the text has overflowed
- 'visible': Renders overflow text outside its container
Acceptable values are: 'clip' | 'ellipsis' | 'visible'
Shared span-level style properties used by both TextStyle and TextSpanRecord.
Adding a property here ensures it's available on both parent text and nested spans.
Text style properties that can be applied to text.
Corresponds to Jetpack Compose's TextStyle.
Type: TextSpanStyleBase extended by:
Literal type: string
Material 3 Typography scale styles. Corresponds to MaterialTheme.typography in Jetpack Compose.
Acceptable values are: 'displayLarge' | 'displayMedium' | 'displaySmall' | 'headlineLarge' | 'headlineMedium' | 'headlineSmall' | 'titleLarge' | 'titleMedium' | 'titleSmall' | 'bodyLarge' | 'bodyMedium' | 'bodySmall' | 'labelLarge' | 'labelMedium' | 'labelSmall'