Reference version

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

Spacer

一个布局占位符,用于在兄弟元素之间产生空白。

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

一个布局间隔组件,用于在 RowColumn 内的兄弟元素之间创建空白空间。使用 size 设置固定间隙,或使用 flexible 填充剩余的主轴空间。

安装

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.

用法

固定大小间隔

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

可伸缩间隔

可伸缩间隔会沿其父级的主轴填充剩余空间,将周围内容推到两端。

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

API

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

Component

Spacer

Android
iOS
Web

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

Android
iOS
Web
Optional • Type: boolean

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

flexible

Android
iOS
Web
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

Android
iOS
Web
Optional • Type: boolean

Whether the component is hidden.

modifiers

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.

onAppear

Android
iOS
Web
Optional • Type: () => void

Called when the component appears on screen.

onDisappear

Android
iOS
Web
Optional • Type: () => void

Called when the component is removed from screen.

onPress

Android
iOS
Web
Optional • Type: () => void

Called when the component is pressed.

size

Android
iOS
Web
Optional • Type: number

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

style

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

Android
iOS
Web
Optional • Type: string

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