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).
LazyHStack
A SwiftUI LazyHStack component for lazy horizontal layouts.
Expo UI LazyHStack matches the official SwiftUI LazyHStack API and arranges its children horizontally.
Installation
If you are installing this in an existing React Native app, make sure to install expo in your project.
Usage
Basic lazy horizontal stack
Put LazyHStack inside a ScrollView with axes="horizontal". Each child of LazyHStack is one item. Use the spacing and alignment props to space and align the items.
Large lists
Use LazyHStack.ForEach to render items from an array. Pass the items as data, a unique key for each item with keyExtractor, and a children function that returns the view for an item. LazyHStack.ForEach renders only the items near the visible area and reuses them while you scroll.
Follow these rules when you render items:
- Define the
childrenfunction outside the component, or wrap it inuseCallback. Otherwise, the items near the visible area render again each time the component renders. - A reused view keeps the local state (
useState) of the item it showed before. Reset the state when the item changes, or keep the state outside the view. - An item that is not ready yet shows an empty placeholder. Set
estimatedItemSizeclose to the width of your items, in points. - Use
overscanCountto prepare more items before and after the visible items. - To update the items, pass a new
dataarray. Do not change the array in place. - Set
recycling={false}to render every item up front.
API
import { LazyHStack } from '@expo/ui/swift-ui';
Components
Type: React.Element<LazyHStackForEachProps<T>>
A block of recycled items inside LazyHStack. Only a small pool of items around the visible
range is mounted. Items 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 LazyHStack.
(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 points along the stack axis, until an item 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 items to prepare on each side of the visible items. Must be a non-negative integer.
Ignored when recycling is false.
Type: React.Element<LazyHStackProps>
stringThe vertical alignment of children within the stack.
Acceptable values are: 'center' | 'top' | 'bottom' | 'firstTextBaseline' | 'lastTextBaseline'
ReactNode