Skip to content

Commit

Permalink
🐛 (VirtualizedList) fix VirtualizedList with initialScrollIndex not r…
Browse files Browse the repository at this point in the history
…endering all items when da…

Use this._hasDoneInitialScroll instead of this._scrollMetrics.offset to determine if the initial
scroll is done. The offset can sometimes be 0 even after the scrollToIndex method is called to
scroll to the initialScrollIndex: for example when the content does not fill the list.
  • Loading branch information
Antoine Doubovetzky committed Apr 20, 2022
1 parent 2265f04 commit 2335afb
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Libraries/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1754,7 +1754,7 @@ class VirtualizedList extends React.PureComponent<Props, State> {
// we'll wipe out the initialNumToRender rendered elements starting at initialScrollIndex.
// So let's wait until we've scrolled the view to the right place. And until then,
// we will trust the initialScrollIndex suggestion.
if (!this.props.initialScrollIndex || this._scrollMetrics.offset) {
if (!this.props.initialScrollIndex || this._hasDoneInitialScroll) {
newState = computeWindowedRenderLimits(
this.props.data,
this.props.getItemCount,
Expand Down
134 changes: 116 additions & 18 deletions Libraries/Lists/__tests__/__snapshots__/VirtualizedList-test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2293,12 +2293,12 @@ exports[`does not adjust render area with non-zero initialScrollIndex until scro
>
<View>
<View
style={
Object {
"height": 10,
}
}
/>
style={null}
>
<MockCellItem
value={0}
/>
</View>
<View
style={null}
>
Expand Down Expand Up @@ -2335,12 +2335,103 @@ exports[`does not adjust render area with non-zero initialScrollIndex until scro
/>
</View>
<View
style={
Object {
"height": 140,
}
}
/>
style={null}
>
<MockCellItem
value={6}
/>
</View>
<View
style={null}
>
<MockCellItem
value={7}
/>
</View>
<View
style={null}
>
<MockCellItem
value={8}
/>
</View>
<View
style={null}
>
<MockCellItem
value={9}
/>
</View>
<View
style={null}
>
<MockCellItem
value={10}
/>
</View>
<View
style={null}
>
<MockCellItem
value={11}
/>
</View>
<View
style={null}
>
<MockCellItem
value={12}
/>
</View>
<View
style={null}
>
<MockCellItem
value={13}
/>
</View>
<View
style={null}
>
<MockCellItem
value={14}
/>
</View>
<View
style={null}
>
<MockCellItem
value={15}
/>
</View>
<View
style={null}
>
<MockCellItem
value={16}
/>
</View>
<View
style={null}
>
<MockCellItem
value={17}
/>
</View>
<View
style={null}
>
<MockCellItem
value={18}
/>
</View>
<View
style={null}
>
<MockCellItem
value={19}
/>
</View>
</View>
</RCTScrollView>
`;
Expand Down Expand Up @@ -3302,12 +3393,19 @@ exports[`renders new items when data is updated with non-zero initialScrollIndex
/>
</View>
<View
style={
Object {
"height": 20,
}
}
/>
style={null}
>
<MockCellItem
value={2}
/>
</View>
<View
style={null}
>
<MockCellItem
value={3}
/>
</View>
</View>
</RCTScrollView>
`;
Expand Down

0 comments on commit 2335afb

Please sign in to comment.