Skip to content

Commit 3346ac7

Browse files
markvfacebook-github-bot
authored andcommitted
Don't scroll to initial item if ContentOffset is provided
Summary: The initialScrollIndex in VirtualizedList contains a performance optimization to start rendering the list at the index provided. ContentOffset does not contain this optimization and there is currently no way to specify the first item in the list to start rendering without contentOffset being ignored. This change makes it so that if both initialScrollIndex and ContentOffset are provided, the list will start rendering at the initialScrollIndex but ContentOffset will still be used to set the scroll position. initialScrollIndex functionality will remain the same if ContentOffset is not provided. Changelog: [Changed] VirtualizedList will use contentOffset for scroll position instead of initialScrollIndex if both are provided Reviewed By: sahrens Differential Revision: D21980172 fbshipit-source-id: 36d2d2bc360845ef02329d2b95a2cf14b91c2b0b
1 parent 952c03b commit 3346ac7

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

Libraries/Lists/VirtualizedList.js

+6-4
Original file line numberDiff line numberDiff line change
@@ -1491,10 +1491,12 @@ class VirtualizedList extends React.PureComponent<Props, State> {
14911491
this.props.initialScrollIndex > 0 &&
14921492
!this._hasDoneInitialScroll
14931493
) {
1494-
this.scrollToIndex({
1495-
animated: false,
1496-
index: this.props.initialScrollIndex,
1497-
});
1494+
if (this.props.contentOffset == null) {
1495+
this.scrollToIndex({
1496+
animated: false,
1497+
index: this.props.initialScrollIndex,
1498+
});
1499+
}
14981500
this._hasDoneInitialScroll = true;
14991501
}
15001502
if (this.props.onContentSizeChange) {

0 commit comments

Comments
 (0)