This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.

文本

用于显示样式化文本内容的组件。

Android
iOS
Web
Included in Expo Go
Recommended version:
~57.0.3

一个用于显示文本的组件。默认情况下会适应平台的配色方案(浅色/深色),并通过 textStyle 提供一组聚焦的排版控制参数。

🌐 A component for displaying text. Adapts to the platform color scheme (light/dark) by default and exposes a focused subset of typography knobs through textStyle.

安装

🌐 Installation

Terminal
npx expo install @expo/ui

If you are installing this in an existing React Native app, make sure to install expo in your project.

用法

🌐 Usage

基础文本

🌐 Basic text

TextExample.tsx
import { Host, Text } from '@expo/ui'; export default function TextExample() { return ( <Host matchContents> <Text>Hello, world!</Text> </Host> ); }

样式化文本

🌐 Styled text

使用 textStyle 处理排版特定属性(字体大小、字重、对齐)。

🌐 Use textStyle for typography-specific properties (font size, weight, alignment).

StyledTextExample.tsx
import { Host, Text } from '@expo/ui'; export default function StyledTextExample() { return ( <Host matchContents> <Text textStyle={{ fontSize: 24, fontWeight: '700', textAlign: 'center' }}>Headline</Text> </Host> ); }

截断长文本

🌐 Truncating long text

使用 numberOfLines 来将长文本限制为末尾带省略号的形式。

🌐 Use numberOfLines to clamp long text with a trailing ellipsis.

TruncatedTextExample.tsx
import { Host, Text } from '@expo/ui'; export default function TruncatedTextExample() { return ( <Host style={{ flex: 1 }}> <Text numberOfLines={1}> A very long line of text that will be truncated when it does not fit on a single line. </Text> </Host> ); }

应用接口

🌐 API

import { Text } from '@expo/ui';

Component

Text

Type: React.Element<TextProps>

A component for displaying styled text content.

Props for the Text component.

TextProps

children

Optional • Type: string

The text content to display.

disabled

Only for:
Android
iOS
Web

Optional • Type: boolean

Whether the component is disabled. Disabled components do not respond to user interaction.

hidden

Only for:
Android
iOS
Web

Optional • Type: boolean

Whether the component is hidden.

modifiers

Only for:
Android
iOS

Optional • Type: 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.

numberOfLines

Optional • Type: number

Maximum number of lines to display. Text is truncated with an ellipsis when exceeded.

onAppear

Only for:
Android
iOS
Web

Optional • Type: () => void

Called when the component appears on screen.

onDisappear

Only for:
Android
iOS
Web

Optional • Type: () => void

Called when the component is removed from screen.

onPress

Only for:
Android
iOS
Web

Optional • Type: () => void

Called when the component is pressed.

style

Only for:
Android
iOS
Web

Optional • Type: 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.

testID

Only for:
Android
iOS
Web

Optional • Type: string

Identifier used to locate the component in end-to-end tests.

textStyle

Optional • Type: { 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).