Skip to content

Commit

Permalink
Added prop to suppress bounded size exception (#709)
Browse files Browse the repository at this point in the history
* Fix no op set state

* Added prop to suppress bounded size exception

Co-authored-by: Talha Naqvi <talha.naqvi@shopify.com>
  • Loading branch information
naqvitalha and naqvitalha authored Apr 8, 2022
1 parent 90457e0 commit 423335f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ export interface RecyclerListViewProps {
applyWindowCorrection?: (offsetX: number, offsetY: number, windowCorrection: WindowCorrection) => void;
onItemLayout?: (index: number) => void;
windowCorrectionConfig?: { value?: WindowCorrection, applyToInitialOffset?: boolean, applyToItemScroll?: boolean };

//This can lead to inconsistent behavior. Use with caution.
//If set to true, recyclerlistview will not measure itself if scrollview mounts with zero height or width.
//If there are no following events with right dimensions nothing will be rendered.
suppressBoundedSizeException?: boolean;
}

export interface RecyclerListViewState {
Expand Down Expand Up @@ -557,16 +562,20 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}

private _onSizeChanged = (layout: Dimension): void => {
if (layout.height === 0 || layout.width === 0) {
if (!this.props.suppressBoundedSizeException) {
throw new CustomError(RecyclerListViewExceptions.layoutException);
} else {
return;
}
}
if (!this.props.canChangeSize && this.props.layoutSize) {
return;
}
const hasHeightChanged = this._layout.height !== layout.height;
const hasWidthChanged = this._layout.width !== layout.width;
this._layout.height = layout.height;
this._layout.width = layout.width;
if (layout.height === 0 || layout.width === 0) {
throw new CustomError(RecyclerListViewExceptions.layoutException);
}
if (!this._initComplete) {
this._initComplete = true;
this._initTrackers(this.props);
Expand Down

0 comments on commit 423335f

Please sign in to comment.