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

Making RLV render stack wait for pending offset #604

Merged
merged 6 commits into from
Apr 14, 2021
Merged
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
29 changes: 21 additions & 8 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
};
private _layout: Dimension = { height: 0, width: 0 };
private _pendingScrollToOffset: Point | null = null;
private _pendingRenderStack?: RenderStack;
private _tempDim: Dimension = { height: 0, width: 0 };
private _initialOffset = 0;
private _cachedLayouts?: Layout[];
Expand Down Expand Up @@ -392,15 +393,21 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends

private _processInitialOffset(): void {
if (this._pendingScrollToOffset) {
const offset = this._pendingScrollToOffset;
this._pendingScrollToOffset = null;
if (this.props.isHorizontal) {
offset.y = 0;
} else {
offset.x = 0;
}
setTimeout(() => {
this.scrollToOffset(offset.x, offset.y, false);
if (this._pendingScrollToOffset) {
const offset = this._pendingScrollToOffset;
this._pendingScrollToOffset = null;
if (this.props.isHorizontal) {
offset.y = 0;
} else {
offset.x = 0;
}
this.scrollToOffset(offset.x, offset.y, false);
if (this._pendingRenderStack) {
this._renderStackWhenReady(this._pendingRenderStack);
this._pendingRenderStack = undefined;
}
}
}, 0);
}
}
Expand Down Expand Up @@ -524,6 +531,12 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}

private _renderStackWhenReady = (stack: RenderStack): void => {
// TODO: Flickers can further be reduced by setting _pendingScrollToOffset in constructor
// rather than in _onSizeChanged -> _initTrackers
if (this._pendingScrollToOffset) {
this._pendingRenderStack = stack;
return;
}
if (!this._initStateIfRequired(stack)) {
this.setState(() => {
return { renderStack: stack };
Expand Down