You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit e27fb65
Browse filesBrowse the repository at this point in the historyBrowse files
Render multi-column FlatList as a grid behind a feature flag
Summary:
With `numColumns > 1`, `FlatList` groups items into one `VirtualizedList` cell per row and keys each row by the keys of its items. Adding or removing an item moves every later item into a different row, so React remounts the items of every later row and they lose their state (#45895).
Behind the new JS-only feature flag `enableFlatListGridLayout`, `FlatList` instead passes items straight through and lets `VirtualizedList` lay them out with `experimental_numColumns`. Each item is its own cell keyed by `keyExtractor`, so no item remounts when another item is added or removed, including items that move to another row, and `onViewableItemsChanged` keeps reporting the right items.
Existing behaviour is kept:
- `getItemLayout`, `initialScrollIndex`, `scrollToIndex` and `maintainVisibleContentPosition.minIndexForVisible` still take row indices; `FlatList` converts them to and from the item indices of the grid.
- Lists that use `columnWrapperStyle`, `ItemSeparatorComponent`, `CellRendererComponent` or `stickyHeaderIndices` keep row cells, as these depend on one cell per row. So does Windows, whose `VirtualizedList` fork does not support grids.
- One visible difference: an item alone in a partially filled last row keeps its column width instead of being stretched across the whole row by `flex: 1`.
Changelog:
[General][Added] - Add `enableFlatListGridLayout` feature flag to render multi-column `FlatList` as a grid of item cells, so items no longer remount when other items are added or removed
Differential Revision: D124984958
0 commit comments