This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 56).
间隔器
一个用于灵活间距的 SwiftUI Spacer 组件。
iOS
tvOS
Included in Expo Go
For the complete documentation index, see llms.txt. Use this file to discover all available pages.
有关跨平台使用,请参阅通用的Spacer——它会根据平台渲染相应的原生组件。
Expo UI Spacer 与官方 SwiftUI Spacer API 一致,并会扩展以填充栈中可用的空间。

安装
Terminal
- npx expo install @expo/uiIf you are installing this in an existing React Native app, make sure to install expo in your project.
用法
HStack 中的基础 Spacer
使用 Spacer 将内容推到水平栈的两端。
SpacerHStackExample.tsx
import { Host, HStack, Text, Spacer } from '@expo/ui/swift-ui'; export default function SpacerHStackExample() { return ( <Host style={{ flex: 1 }}> <HStack> <Text>左侧</Text> <Spacer /> <Text>右侧</Text> </HStack> </Host> ); }
VStack 中的基础 Spacer
使用 Spacer 将内容推到垂直栈的两端。
SpacerVStackExample.tsx
import { Host, VStack, Text, Spacer } from '@expo/ui/swift-ui'; export default function SpacerVStackExample() { return ( <Host style={{ flex: 1 }}> <VStack> <Text>顶部</Text> <Spacer /> <Text>底部</Text> </VStack> </Host> ); }
API
import { Spacer } from '@expo/ui/swift-ui';
Component
Type: React.Element<SpacerProps>