Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache ScrollView content length before calling scrollToIndex #38736

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 26 additions & 12 deletions packages/virtualized-lists/Lists/VirtualizedList.js
Original file line number Diff line number Diff line change
Expand Up @@ -1608,9 +1608,32 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}

_onContentSizeChange = (width: number, height: number) => {
this._listMetrics.notifyListContentLayout({
layout: {width, height},
orientation: this._orientation(),
});

this._maybeScrollToInitialScrollIndex(width, height);

if (this.props.onContentSizeChange) {
this.props.onContentSizeChange(width, height);
}
this._scheduleCellsToRenderUpdate();
this._maybeCallOnEdgeReached();
};

/**
* Scroll to a specified `initialScrollIndex` prop after the ScrollView
* content has been laid out, if it is still valid. Only a single scroll is
* triggered throughout the lifetime of the list.
*/
_maybeScrollToInitialScrollIndex(
contentWidth: number,
contentHeight: number,
) {
if (
width > 0 &&
height > 0 &&
contentWidth > 0 &&
contentHeight > 0 &&
this.props.initialScrollIndex != null &&
this.props.initialScrollIndex > 0 &&
!this._hasTriggeredInitialScrollToIndex
Expand All @@ -1630,16 +1653,7 @@ class VirtualizedList extends StateSafePureComponent<Props, State> {
}
this._hasTriggeredInitialScrollToIndex = true;
}
if (this.props.onContentSizeChange) {
this.props.onContentSizeChange(width, height);
}
this._listMetrics.notifyListContentLayout({
layout: {width, height},
orientation: this._orientation(),
});
this._scheduleCellsToRenderUpdate();
this._maybeCallOnEdgeReached();
};
}

/* Translates metrics from a scroll event in a parent VirtualizedList into
* coordinates relative to the child list.
Expand Down