This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
ScrollView
一个用于可滚动内容的 SwiftUI ScrollView 组件。
有关跨平台用法,请参阅通用
ScrollView——它会根据平台渲染相应的原生组件。
Expo UI ScrollView 与官方 SwiftUI ScrollView API 相匹配,并提供可滚动的容器来容纳其子元素。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基本垂直滚动视图
一个简单的垂直滚动文本项列表。
水平滚动视图
使用 axes 属性进行水平滚动。
隐藏滚动指示器
将 showsIndicators 设为 false 以隐藏滚动条。
共享滚动位置
需要 iOS 17 或更高版本。在较早版本中,此修饰符不执行任何操作。
从 JavaScript 跟踪前导滚动目标 ID,并通过写入状态滚动到目标。使用 id 修饰符标记每个滚动目标,将内容容器包裹在 scrollTargetLayout 中,并将 scrollPosition 修饰符应用于 ScrollView。当前导目标发生变化时,可选的 onChange 回调会在 JS 线程上触发。
scrollPosition 修饰符也适用于其他可滚动容器,例如 LazyVStack 和 LazyHStack。
对
state.value的写入必须在 UI runtime 上运行。请使用react-native-worklets中的scheduleOnUI包裹写入,或在'worklet'函数内部调用。来自 JS runtime 的写入会触发 Main Thread Checker;这是 Xcode 的运行时工具,用于标记从后台线程发起的 UIKit 调用。
未裁剪的滚动内容
需要 iOS 17 或更高版本。在较早版本中,此修饰符不执行任何操作。
滚动视图会将内容裁剪到自身边界,因此超出边界绘制的内容(例如阴影或放大后超出边缘的卡片)会被截断。应用 scrollClipDisabled 修饰符可使这些内容保持可见。
API
import { ScrollView } from '@expo/ui/swift-ui';
Component
Type: React.Element<ScrollViewProps>
SwiftUI ScrollView wrapper. To control scroll position, pair this with the
scrollPosition(state, { onChange }) modifier and a useNativeState-backed
id. Write state.value = targetId for an instant scroll, or wrap the write
in withAnimation(...) from @expo/ui/swift-ui for an animated one.
string • Default: 'vertical'The scrollable axes. Pass 'both' to enable 2D (horizontal + vertical) scrolling.
Acceptable values are: 'horizontal' | 'vertical' | 'both'
ReactNodeboolean • Default: trueWhether to show scroll indicators. For richer visibility control (e.g. 'never')
or per-axis control, use the scrollIndicators(...) modifier instead.
Types
Snapshot of a ScrollView's scroll geometry, emitted by the
useScrollGeometryChange(...) and onScrollPhaseChange(...) modifiers
(iOS 18+).