Skip to content

Commit

Permalink
- [Flipkart#731] Only call _forceSizeUpdate when non-deterministic re…
Browse files Browse the repository at this point in the history
…ndering is used. Otherwise a layout cycle occurs.

- Add extra check before calling overrideLayout in RecyclerListView
  • Loading branch information
kevin-kp committed Jul 29, 2022
1 parent 0ef9c42 commit 47fb3cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,8 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}, dim, index);
}

if (layoutManager.overrideLayout(index, dim)) {
// Add extra protection for overrideLayout as it can only be called when non-deterministic rendering is used.
if (this.props.forceNonDeterministicRendering && layoutManager.overrideLayout(index, dim)) {
if (this._relayoutReqIndex === -1) {
this._relayoutReqIndex = index;
} else {
Expand Down
17 changes: 13 additions & 4 deletions src/platform/reactnative/viewrenderer/ViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@ export default class ViewRenderer extends BaseViewRenderer<any> {
if (this.props.layoutProvider && this._layoutManagerRef) {
if (this.props.layoutProvider.getLayoutManager() !== this._layoutManagerRef) {
this._layoutManagerRef = this.props.layoutProvider.getLayoutManager();
const oldDim = {...this._dim};
setTimeout(() => {
this._forceSizeUpdate(oldDim);
}, 32);
this._scheduleForceSizeUpdateTimer();
}
}
}
Expand Down Expand Up @@ -93,6 +90,18 @@ export default class ViewRenderer extends BaseViewRenderer<any> {
this.props.onItemLayout(this.props.index);
}
}

private _scheduleForceSizeUpdateTimer = () => {
// forceSizeUpdate calls onSizeChanged which can only be called when non-deterministic rendering is used.
if (!this.props.forceNonDeterministicRendering) {
return;
}
const oldDim = {...this._dim};
setTimeout(() => {
this._forceSizeUpdate(oldDim);
}, 32);
}

private _forceSizeUpdate = (dim: Dimension): void => {
if (dim.width === this._dim.width && dim.height === this._dim.height) {
if (this.isRendererMounted && this.props.onSizeChanged) {
Expand Down

0 comments on commit 47fb3cc

Please sign in to comment.