Repository navigation
Add experimental grid layout to VirtualizedList (#59038) - #59038
Open
ramya-2196 wants to merge 1 commit into
Open
ramya-2196 wants to merge 1 commit into
ramya-2196 wants to merge 1 commit into
Conversation
|
@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
ramya-2196
force-pushed
the
export-D124984957
branch
from
October 13, 2026 14:12
b10aeff to
bd37d26
Compare
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
FlatListbuilds 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_numColumnstoVirtualizedListso the list can lay out the grid itself instead. Every item is rendered as its own cell, a direct child of the list keyed bykeyExtractor, so an item keeps its identity when it moves to another row:flexDirection: 'row',flexWrap: 'wrap'). Each cell is100% / numColumnswide and uses a row direction, so an item withflex: 1fills its column the way it fills its share of aFlatListrow today. The header, footer, empty component and spacers are full width.expandCellsToWholeRows) wherever the render mask is built, so rendered cells and spacers always cover complete rows.ListMetricsAggregatorestimates unmeasured cells by row, since cells in a row share their row's offset and length.getItemLayoutreceives item indices and returns the offset and length of the item's row.Horizontal lists,
ItemSeparatorComponentandstickyHeaderIndicesare not supported withexperimental_numColumnsyet and throw.FlatListdoes not use the prop yet; that follows in the next diff behind a feature flag.Changelog:
[General][Added] - Add experimental
experimental_numColumnsprop toVirtualizedListto lay out items in a grid with one cell per itemDifferential Revision: D124984957