This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
懒惰垂直堆叠
用于懒惰垂直布局的 SwiftUI LazyVStack 组件。
Expo UI 的 LazyVStack 与官方 SwiftUI LazyVStack API 一致,并将其子元素垂直排列。
🌐 Expo UI LazyVStack matches the official SwiftUI LazyVStack API and arranges its children vertically.
安装
🌐 Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
🌐 Usage
基本懒惰垂直堆栈
🌐 Basic lazy vertical stack
把 LazyVStack 放进 ScrollView 里。LazyVStack 的每个子元素都是一行。使用 spacing 和 alignment 属性来调整行间距和对齐方式。
🌐 Put LazyVStack inside a ScrollView. Each child of LazyVStack is one row. Use the spacing and alignment props to space and align the rows.
大型列表
🌐 Large lists
使用 LazyVStack.ForEach 来渲染数组中的行。把项目作为 data 传入,每个项目用 keyExtractor 提供唯一的键,并提供一个 children 函数来返回某个项目的行。LazyVStack.ForEach 只渲染可见区域附近的行,并在滚动时重复使用它们。
🌐 Use LazyVStack.ForEach to render rows from an array. Pass the items as data, a unique key for each item with keyExtractor, and a children function that returns the row for an item. LazyVStack.ForEach renders only the rows near the visible area and reuses them while you scroll.
渲染行时遵守这些规则:
🌐 Follow these rules when you render rows:
- 在组件外定义
children函数,或者把它包在useCallback里。否则,每次组件渲染时,可见区域附近的行都会重新渲染。 - 一个重复使用的行会保留它之前显示的项目的本地状态(
useState)。当项目变化时重置状态,或者把状态保存在行外。 - 一个还没准备好的行会显示一个空占位符。将
estimatedItemSize设置为接近你行的高度,单位为点。 - 使用
overscanCount在可见行的上方和下方准备更多行。 - 要更新行,请传入一个新的
data数组。不要在原地修改数组。 - 把
recycling={false}设置成提前渲染每一行。
应用接口
🌐 API
import { LazyVStack } from '@expo/ui/swift-ui';
No API data file found, sorry!