Skip to content

Commit

Permalink
Bugfix(layoutSize) fix item not render after initial data size is emp…
Browse files Browse the repository at this point in the history
…ty (#781)

* Bugfix(layoutSize) fix item not render after initial data size is empty

if layoutSize is provided, items doesn't render if the initial data size is empty.

add new function to componentCompact to allow extended component to had access to the _hasRenderOnce

only assign the state is the component never get render before

* bugfix(layout):fix layout issue where layout manager keep previous total hight
  • Loading branch information
shawnchendev authored Jun 10, 2024
1 parent afd0a8b commit f2bdac4
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
"react-native": ">= 0.30.0"
},
"devDependencies": {
"@types/lodash.debounce": "4.0.3",
"@types/lodash.debounce": "4.0.8",
"@types/prop-types": "15.5.2",
"@types/react-native": "0.49.5",
"@types/react": "16.4.7",
"@types/resize-observer-browser": "^0.1.7",
"@types/react-native": "0.49.5",
"@types/resize-observer-browser": "0.1.7",
"file-directives": "1.4.6",
"tslint": "5.11.0",
"typescript": "3.3.1"
"typescript": "4.9.5"
}
}
8 changes: 7 additions & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,13 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}

private _initStateIfRequired(stack?: RenderStack): boolean {
if (!this.state) {
/**
* this is to ensure that if the component does not has state and not render before
* we still initialize the state like how we do in constructor.
* else return false to let the caller to call setState
* so the component can re-render to the correct stack
*/
if (!this.state && !this.getHasRenderedOnce()) {
this.state = {
internalSnapshot: {},
renderStack: stack,
Expand Down
12 changes: 12 additions & 0 deletions src/core/layoutmanager/LayoutManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ export class WrapGridLayoutManager extends LayoutManager {
public getContentDimension(): Dimension {
return { height: this._totalHeight, width: this._totalWidth };
}
/**
* when remove layout is called, it will remove the layout from the layouts array
* and if the layouts array is empty, it will reset the total height and total width to 0
* @param index
*/
public removeLayout(index: number): void {
super.removeLayout(index);
if (this._layouts.length === 0) {
this._totalHeight = 0;
this._totalWidth = 0;
}
}

public getLayouts(): Layout[] {
return this._layouts;
Expand Down
8 changes: 8 additions & 0 deletions src/utils/ComponentCompat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@ export abstract class ComponentCompat<T1 = {}, T2 = {}, SS = any> extends React.
return true;
}

/**
* allow the extended component to access _hasRenderedOnce flag
* to ensure that the component has rendered at least once
* @returns _hasRenderedOnce
*/
public getHasRenderedOnce(): boolean {
return this._hasRenderedOnce;
}
//setState inside will not update the existing cycle, not a true replacement for componentWillReceiveProps
public componentWillReceivePropsCompat(newProps: T1): void {
//no op
Expand Down

0 comments on commit f2bdac4

Please sign in to comment.