This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
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 运行时中执行。请将写入操作包裹在react-native-worklets中的scheduleOnUI里,或者从'worklet'函数内部调用它们。来自 JS 运行时的写入会触发 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+).