Skip to content

Commit

Permalink
Making RLV render stack wait for pending offset (Flipkart#604)
Browse files Browse the repository at this point in the history
* Making RLV render stack wait for pending offset.

* Adding new flag for pending scroll complete.

* Storing a pending stack to be rendered after any pending scroll is completed.

* Adding TODO.

* Removing object assign.

* Removing pending scroll complete flag.
  • Loading branch information
ananyachandra14 authored Apr 14, 2021
1 parent 782e6eb commit c1a2fb2
Showing 1 changed file with 21 additions and 8 deletions.
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

0 comments on commit c1a2fb2

Please sign in to comment.