This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
LazyVStack
A SwiftUI LazyVStack component for lazy vertical layouts.
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
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
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:
- Define the
childrenfunction outside the component, or wrap it inuseCallback. Otherwise, the rows near the visible area render again each time the component renders. - A reused row keeps the local state (
useState) of the item it showed before. Reset the state when the item changes, or keep the state outside the row. - A row that is not ready yet shows an empty placeholder. Set
estimatedItemSizeclose to the height of your rows, in points. - Use
overscanCountto prepare more rows above and below the visible rows. - To update the rows, pass a new
dataarray. Do not change the array in place. - Set
recycling={false}to render every row up front.
API
import { LazyVStack } from '@expo/ui/swift-ui';
Components
Type: React.Element<LazyVStackForEachProps<T>>
A block of recycled rows inside LazyVStack. Only a small pool of rows around the visible
range is mounted. Rows that are not ready yet show a placeholder of estimatedItemSize, or of
the size last measured for that row.
Mount it as a direct child of LazyVStack.
(info: {
index: number,
item: T
}) => ReactElementRenders a row. 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 size in points along the stack axis, until a row is measured. Must be positive.
Ignored when recycling is false.
(item: T, index: number) => stringReturns a stable, unique string key for each item.
number • Default: 10Extra rows to prepare on each side of the visible rows. Must be a non-negative integer.
Ignored when recycling is false.
Type: React.Element<LazyVStackProps>
stringThe horizontal alignment of children within the stack.
Acceptable values are: 'center' | 'leading' | 'trailing'
ReactNode