VirtualizedList + getItemLayout only renders initialNumToRender items
See original GitHub issueIs this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
react-native -v
: 0.47.2node -v
: v6.10.3npm -v
: 3.10.10yarn --version
: n/a
Then, specify:
- Target Platform: iOS
- Development Operating System: macOS
- Build tools: Xcode
Steps to Reproduce
(Write your steps here:)
- Create a component with a
FlatList
w/tgetItemLayout
, i.e.
<FlatList
ref={ref => { const anyRef: any = ref; this._flatList = anyRef }}
data={data}
renderItem={this._renderItem}
onViewableItemsChanged={this._onViewableItemsChanged}
getItemLayout={this._getItemLayout}
initialNumToRender={10}
/>
I am using the standard getItemLayout
:
getItemLayout={(data, index) => (
{length: ITEM_HEIGHT, offset: ITEM_HEIGHT * index, index}
)}
- Provide a data source that has more than
initialNumToRender
items - Render and scroll to bottom
Expected Behavior
(Write what you thought would happen.)
All items are rendered.
Actual Behavior
Only initialNumToRender
items are rendered.
(Write what happened. Add screenshots!)
Reproducible Demo
The bug is in VirtualizedList:
const onLayout =
getItemLayout && !parentProps.debug && !fillRateHelper.enabled()
? undefined
: this.props.onLayout;
The fix is:
const onLayout = this.props.onLayout;
You need onLayout
because somebody needs to call _onCellLayout(e, key, ii)
.
(Paste the link to an example project and exact instructions to reproduce the issue.)
Issue Analytics
- State:
- Created 6 years ago
- Reactions:21
- Comments:17 (4 by maintainers)
Top Results From Across the Web
VirtualizedList - React Native
This disables the "scroll to top" optimization that keeps the first initialNumToRender items always rendered and immediately renders the items ...
Read more >VirtualizedList: You have a large list that is slow to update ...
In this case only 8 items, and it doesn't seem like they are retendered but somehow the warning keep showing up. I also...
Read more >8 ways to optimize React native FlatList performance
Use getItemLayout to optimize flatlist react native ... For example initialNumToRender to render less number of items so that first render ...
Read more >Display a List Using the FlatList Component in React Native
React Native provides a FlatList component to create a list. FlatList only renders the list items that can be displayed on the screen....
Read more >react native flatlist infinite loop - You.com | The AI Search ...
I thought the FlatList would only re-render when the data or extraData props ... VirtualizedList + getItemLayout only renders initialNumToRender items#5652.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After working with
getItemLayout
plus my proposed fix for a few weeks I have come to the conclusion thatgetItemLayout
cannot be used in production code.Here are my recommendations:
getItemLayout
. It’s not working correctly. I would classify the quality of the code asexperimental
at best.scrollToIndex
,scrollToItem
, andscrollToEnd
, because they requiregetItemLayout
. Instead usescrollToOffset
, which comes with fewer bugs.getItemLayout
. Something along the lines of theremoveClippedSubviews
warning:Good luck, I am closing this issue.
Why is this issue closed? If
getItemLayout
is not working correctly the issue should stay open.