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

一个布局间隔器,用于在 RowColumn 内的兄弟元素之间产生空白空间。使用 size 可以创建固定间距,或使用 flexible 来填充剩余的主轴空间。

🌐 A layout spacer that produces empty space between siblings inside a Row or Column. Use size for a fixed gap, or flexible to fill the remaining main-axis space.

安装

🌐 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

固定尺寸间隔

🌐 Fixed-size spacer

FixedSpacerExample.tsx
import { Host, Column, Text, Spacer } from '@expo/ui'; export default function FixedSpacerExample() { return ( <Host matchContents> <Column> <Text>Top</Text> <Spacer size={32} /> <Text>Bottom</Text> </Column> </Host> ); }

弹性垫片

🌐 Flexible spacer

一个灵活的间隔器填充父元素主轴上剩余的空间,将周围的内容推向相反的两端。

🌐 A flexible spacer fills the remaining space along its parent's main axis, pushing the surrounding content to opposite ends.

FlexibleSpacerExample.tsx
import { Host, Row, Text, Spacer } from '@expo/ui'; export default function FlexibleSpacerExample() { return ( <Host style={{ flex: 1 }}> <Row> <Text>Leading</Text> <Spacer flexible /> <Text>Trailing</Text> </Row> </Host> ); }

应用接口

🌐 API

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

Component

Spacer

Type: React.Element<SpacerProps>

A layout spacer that produces empty space between siblings in a Row or Column.

Props for the Spacer component.

A Spacer produces empty space between siblings in a Row or Column. Use size for a fixed amount of space, or flexible to fill the remaining space along the parent's main axis.

SpacerProps

disabled

Only for:
Android
iOS
Web

Optional • Type: boolean

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

flexible

Optional • Type: boolean • Default: false

When true, the spacer expands to fill the available space along the parent's main axis, pushing sibling content to the opposite end.

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.

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.

size

Optional • Type: number

Fixed size in density-independent pixels. Interpreted as width in a horizontal container and as height in a vertical container.

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.