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).
列表
用于显示可滚动项目列表的 SwiftUI List 组件。
有关跨平台用法,请参阅通用的
List— 它会为每个平台渲染相应的原生组件。
Expo UI List 与官方 SwiftUI List API 保持一致,并支持通过 listStyle 修饰符、各种行/分区修饰符,以及选择、重新排序和编辑功能进行样式设置。
List目前还不会延迟渲染各行:React 会预先创建每一行,因此大型列表在挂载时可能会很慢。我们正在改进这一点。对于大型列表,我们推荐使用 FlashList 或 Legend List。


安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
基础列表
带标签和图标的列表
列表样式
使用 listStyle 修饰符来更改列表的外观。
注意:
inset、insetGrouped和sidebar样式在 tvOS 上不可用。
选择和编辑模式
使用带有 onDelete 和 onMove 属性的 List.ForEach 复合组件,可启用列表项的选择、删除和重新排序。
- 使用
environment修饰符启用编辑模式 - 使用
keyExtractor属性标识项目 - 使用
selection属性控制选中的项目 - 使用
moveDisabled和deleteDisabled修饰符禁用单个项目上的这些操作
下拉刷新
使用 refreshable 修饰符启用下拉刷新功能。
行样式
使用 listRowBackground、listRowSeparator、listRowSeparatorTint 和 listRowInsets 修饰符自定义单独的行。将 alignmentGuide 与 listRowSeparatorLeading 对齐指南搭配使用,可设置行分隔线的起始位置。
键盘收起行为
使用 scrollDismissesKeyboard 修饰符来控制滚动时如何收起键盘。
标题突出程度
使用 headerProminence 修饰符来调整分区标题的视觉突出程度。
API
import { List } from '@expo/ui/swift-ui';
Components
Type: React.Element<ListProps>
A list component that renders its children using a native SwiftUI List.
Type: React.Element<ListForEachElementsProps | ListForEachProps<ItemT>>
A group of rows inside List, with optional deletion and reordering.
Pass data with keyExtractor, and render each row from a children function.
Recycles rows unless recycling is false.
(info: {
index: number,
item: ItemT
}) => ReactElementRenders a row. When recycling is true, wrap it in useCallback, or every row
re-renders on each parent render.
Recycled rows are reused for other items, so their local state (useState) carries over.
Reset it when the item changes, or keep the state outside the row.
number • Default: 64Placeholder height in points, excluding List insets, until a row is measured.
Must be positive. Measurements reset when data or width changes.
Ignored when recycling is false.
(item: ItemT, index: number) => stringReturns a stable, unique string key, also used for List selection.
(indices: number[]) => voidCalled with deleted indices from this group's data array.
(sourceIndices: number[], destination: number) => voidCalled with the source indices and the destination index. The destination index counts
positions before the moved items are removed, so it can equal data.length.
number • Default: 10Extra rows to prepare on each side of the visible rows. Must be a non-negative integer.
Ignored when recycling is false.
boolean • Default: trueRenders only the rows near the visible range and reuses them while scrolling. Set to false to
render every row at once. Set it once; changing it remounts the rows.