Skip to content

Add experimental grid layout to VirtualizedList (#59038) - #59038

Open
ramya-2196 wants to merge 1 commit into
react:mainfrom
ramya-2196:export-D124984957
Open

ramya-2196 wants to merge 1 commit into
react:mainfrom
ramya-2196:export-D124984957

Conversation

@ramya-2196

@ramya-2196 ramya-2196 commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Summary:

FlatList builds multi-column lists by grouping items into one row cell per row and keying each row by the keys of its items. Adding or removing an item shifts every later item into a different row, so every later row gets a new key and React remounts all of its items: they lose their state and replay their entry animations (#45895).

This adds experimental_numColumns to VirtualizedList so the list can lay out the grid itself instead. Every item is rendered as its own cell, a direct child of the list keyed by keyExtractor, so an item keeps its identity when it moves to another row:

  • The content container wraps cells into rows (flexDirection: 'row', flexWrap: 'wrap'). Each cell is 100% / numColumns wide and uses a row direction, so an item with flex: 1 fills its column the way it fills its share of a FlatList row today. The header, footer, empty component and spacers are full width.
  • Render windows are widened to whole rows (expandCellsToWholeRows) wherever the render mask is built, so rendered cells and spacers always cover complete rows.
  • ListMetricsAggregator estimates unmeasured cells by row, since cells in a row share their row's offset and length.
  • Viewability is reported per item without any change, because every item is its own cell.
  • getItemLayout receives item indices and returns the offset and length of the item's row.
  • On Android, inverted lists are flipped on both axes, so rows are reversed in the content container to keep items in reading order.

Horizontal lists, ItemSeparatorComponent and stickyHeaderIndices are not supported with experimental_numColumns yet and throw. FlatList does not use the prop yet; that follows in the next diff behind a feature flag.

Changelog:
[General][Added] - Add experimental experimental_numColumns prop to VirtualizedList to lay out items in a grid with one cell per item

Differential Revision: D124984957

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Oct 13, 2026
@meta-codesync

meta-codesync Bot commented Oct 13, 2026

Copy link
Copy Markdown

@ramya-2196 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D124984957.

Summary:

`FlatList` builds multi-column lists by grouping items into one row cell per row and keying each row by the keys of its items. Adding or removing an item shifts every later item into a different row, so every later row gets a new key and React remounts all of its items: they lose their state and replay their entry animations (react#45895).

This adds `experimental_numColumns` to `VirtualizedList` so the list can lay out the grid itself instead. Every item is rendered as its own cell, a direct child of the list keyed by `keyExtractor`, so an item keeps its identity when it moves to another row:

- The content container wraps cells into rows (`flexDirection: 'row'`, `flexWrap: 'wrap'`). Each cell is `100% / numColumns` wide and uses a row direction, so an item with `flex: 1` fills its column the way it fills its share of a `FlatList` row today. The header, footer, empty component and spacers are full width.
- Render windows are widened to whole rows (`expandCellsToWholeRows`) wherever the render mask is built, so rendered cells and spacers always cover complete rows.
- `ListMetricsAggregator` estimates unmeasured cells by row, since cells in a row share their row's offset and length.
- Viewability is reported per item without any change, because every item is its own cell.
- `getItemLayout` receives item indices and returns the offset and length of the item's row.
- On Android, inverted lists are flipped on both axes, so rows are reversed in the content container to keep items in reading order.

Horizontal lists, `ItemSeparatorComponent` and `stickyHeaderIndices` are not supported with `experimental_numColumns` yet and throw. `FlatList` does not use the prop yet; that follows in the next diff behind a feature flag.

Changelog:
[General][Added] - Add experimental `experimental_numColumns` prop to `VirtualizedList` to lay out items in a grid with one cell per item

Differential Revision: D124984957
@meta-codesync meta-codesync Bot changed the title Add experimental grid layout to VirtualizedList Add experimental grid layout to VirtualizedList (#59038) Oct 13, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. meta-exported p: Facebook Partner: Facebook Partner

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant