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).
LazyColumn
一个用于显示可滚动列表的 Jetpack Compose LazyColumn 组件。
Expo UI LazyColumn 与官方 Jetpack Compose LazyColumn API一致,并显示垂直滚动列表。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础懒加载列
LazyColumn 的每个子项都是一行。使用 verticalArrangement 属性设置行间距,使用 contentPadding 属性为列表内容添加内边距。
大型列表
使用 LazyColumn.Items 从数组渲染行。将项目作为 data 传入,使用 keyExtractor 为每个项目提供唯一键,并传入一个返回项目行的 children 函数。LazyColumn.Items 只渲染可见区域附近的行,并在滚动时复用它们。
渲染行时请遵循以下规则:
- 将
children函数定义在组件外部,或使用useCallback包装它。否则,每次组件渲染时,可见区域附近的行都会再次渲染。 - 复用的行会保留它之前显示的项目的本地状态(
useState)。当项目变化时重置状态,或将状态保留在行视图之外。 - 尚未准备好的行会显示填充行高的空占位符。将
estimatedItemSize设置为接近行高的值,单位为与密度无关的像素(dp)。 - 使用
overscanCount在可见行的上方和下方预先准备更多行。 - 要更新行,请传入新的
data数组。不要原地修改数组。 - 设置
recycling={false}可预先渲染所有行。
API
import { LazyColumn } from '@expo/ui/jetpack-compose';
Components
Type: React.Element<LazyItemsProps<T>>
A block of recycled rows inside LazyColumn or LazyRow, mirroring the Compose
items(count, key) builder. Only a small pool of rows around the visible range is mounted,
so large data sets stay cheap. Rows that are not ready yet show a placeholder of
estimatedItemSize, or of the size last measured for that item.
Mount it as a direct child of LazyColumn or LazyRow.
(info: {
index: number,
item: T
}) => ReactElementRenders an item. Wrap it in useCallback, or every item re-renders on each parent render.
Recycled views are reused for other items, so their local state (useState) carries over.
Reset it when the item changes, or keep the state outside the view.
number • Default: 64Placeholder size in dp along the scroll axis, until an item is measured. Must be positive.
Ignored when recycling is false.
(item: T, index: number) => stringReturns a stable, unique string key, also used as the lazy list item key.
number • Default: 10Extra items to prepare on each side of the visible items. Must be a non-negative integer.
Ignored when recycling is false.
Type: React.Element<LazyColumnProps>
A lazy column component that efficiently displays a vertically scrolling list.
stringThe horizontal alignment of items.
Acceptable values are: 'center' | 'start' | 'end'