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

Remove the initial empty render of the scrollview if a scrollviewsize is passed #450

Merged
merged 18 commits into from
May 4, 2020
Merged
Changes from 4 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
42 changes: 34 additions & 8 deletions src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ export interface RecyclerListViewProps {
onVisibleIndicesChanged?: TOnItemStatusChanged;
renderFooter?: () => JSX.Element | JSX.Element[] | null;
externalScrollView?: { new(props: ScrollViewDefaultProps): BaseScrollView };
scrollViewSize?: Dimension;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

call out edge cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in readme

initialOffset?: number;
initialRenderIndex?: number;
scrollThrottle?: number;
Expand Down Expand Up @@ -152,6 +153,8 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
private _scrollComponent: BaseScrollComponent | null = null;

private _defaultItemAnimator: ItemAnimator = new DefaultItemAnimator();
private _isSizeChangedCalledOnce: boolean = false;
private _hasMounted: boolean = false;

constructor(props: P, context?: any) {
super(props, context);
Expand All @@ -161,10 +164,18 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
return this.props.dataProvider.getStableId(index);
}, !props.disableRecycling);

this.state = {
internalSnapshot: {},
renderStack: {},
} as S;
if (props.scrollViewSize) {
this._layout.height = props.scrollViewSize.height;
this._layout.width = props.scrollViewSize.width;
this._initComplete = true;
this._initTrackers();
this._processOnEndReached();
} else {
this.state = {
internalSnapshot: {},
renderStack: {},
} as S;
}
}

public componentWillReceivePropsCompat(newProps: RecyclerListViewProps): void {
Expand Down Expand Up @@ -201,6 +212,10 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
}
}

public componentDidMount(): void {
this._hasMounted = true;
}

public componentWillUnmount(): void {
if (this.props.contextProvider) {
const uniqueKey = this.props.contextProvider.getUniqueKey();
Expand Down Expand Up @@ -440,17 +455,28 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
if ((hasHeightChanged && hasWidthChanged) ||
(hasHeightChanged && this.props.isHorizontal) ||
(hasWidthChanged && !this.props.isHorizontal)) {
this._checkAndChangeLayouts(this.props, true);
const forceFullRender = this._isSizeChangedCalledOnce ? true : false;
this._checkAndChangeLayouts(this.props, forceFullRender);
} else {
this._refreshViewability();
}
}
if (!this._isSizeChangedCalledOnce) {
this._isSizeChangedCalledOnce = true;
}
}

private _renderStackWhenReady = (stack: RenderStack): void => {
this.setState(() => {
return { renderStack: stack };
});
if (!this._hasMounted) {
this.state = {
internalSnapshot: {},
renderStack: stack,
} as S;
} else {
this.setState(() => {
return { renderStack: stack };
});
}
}

private _initTrackers(): void {
Expand Down