ScrollView

用于可滚动内容的 SwiftUI ScrollView 组件。

iOS
tvOS
Bundled version:
~55.0.2

Expo UI ScrollView 与官方 SwiftUI ScrollView API 相匹配,并为其子元素提供可滚动的容器。

🌐 Expo UI ScrollView matches the official SwiftUI ScrollView API and provides a scrollable container for its children.

安装

🌐 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 vertical scroll view

一个简单的垂直可滚动文本项列表。

🌐 A simple vertically scrollable list of text items.

ScrollViewVerticalExample.tsx
import { Host, ScrollView, VStack, Text } from '@expo/ui/swift-ui'; import { padding } from '@expo/ui/swift-ui/modifiers'; export default function ScrollViewVerticalExample() { return ( <Host style={{ flex: 1 }}> <ScrollView> <VStack spacing={8}> {Array.from({ length: 30 }, (_, i) => ( <Text key={i} modifiers={[padding({ horizontal: 16 })]}> {`Item ${i + 1}`} </Text> ))} </VStack> </ScrollView> </Host> ); }

水平滚动视图

🌐 Horizontal scroll view

使用 axes 属性来水平滚动。

🌐 Use the axes prop to scroll horizontally.

ScrollViewHorizontalExample.tsx
import { Host, ScrollView, HStack, RoundedRectangle } from '@expo/ui/swift-ui'; import { frame, foregroundStyle } from '@expo/ui/swift-ui/modifiers'; export default function ScrollViewHorizontalExample() { return ( <Host style={{ flex: 1 }}> <ScrollView axes="horizontal"> <HStack spacing={8}> {Array.from({ length: 20 }, (_, i) => ( <RoundedRectangle key={i} cornerRadius={12} modifiers={[ frame({ width: 100, height: 100 }), foregroundStyle(`hsl(${i * 18}, 70%, 50%)`), ]} /> ))} </HStack> </ScrollView> </Host> ); }

隐藏的滚动指示器

🌐 Hidden scroll indicators

showsIndicators 设置为 false 以隐藏滚动条。

🌐 Set showsIndicators to false to hide the scroll bars.

ScrollViewHiddenIndicatorsExample.tsx
import { Host, ScrollView, VStack, Text } from '@expo/ui/swift-ui'; export default function ScrollViewHiddenIndicatorsExample() { return ( <Host style={{ flex: 1 }}> <ScrollView showsIndicators={false}> <VStack spacing={8}> {Array.from({ length: 30 }, (_, i) => ( <Text key={i}>{`Item ${i + 1}`}</Text> ))} </VStack> </ScrollView> </Host> ); }

应用接口

🌐 API

import { ScrollView } from '@expo/ui/swift-ui';

Component

ScrollView

iOS
tvOS

Type: React.Element<ScrollViewProps>

ScrollViewProps

axes

iOS
tvOS
Optional • Literal type: string • Default: 'vertical'

The scrollable axes.

Acceptable values are: 'vertical' | 'horizontal' | 'both'

children

iOS
tvOS
Type: React.ReactNode

showsIndicators

iOS
tvOS
Optional • Type: boolean • Default: true

Whether to show scroll indicators.