Skip to content

Commit

Permalink
Plv render after first draw (#688)
Browse files Browse the repository at this point in the history
* PLV now render after first onLayout

* ..

Co-authored-by: Talha Naqvi <talha.naqvi@shopify.com>
  • Loading branch information
naqvitalha and naqvitalha authored Mar 8, 2022
1 parent 0008f6c commit 33bc8f5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "recyclerlistview",
"version": "3.1.0-beta.3",
"version": "3.1.0-beta.4",
"description": "The listview that you need and deserve. It was built for performance, uses cell recycling to achieve smooth scrolling.",
"main": "dist/reactnative/index.js",
"types": "dist/reactnative/index.d.ts",
Expand Down
17 changes: 14 additions & 3 deletions src/core/ProgressiveListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,23 @@ export default class ProgressiveListView extends RecyclerListView<ProgressiveLis
renderAheadOffset: 0,
};
private renderAheadUdpateCallbackId?: number;
private isFirstLayoutComplete: boolean = false;

public componentDidMount(): void {
if (super.componentDidMount) {
super.componentDidMount();
super.componentDidMount();
if (!this.props.forceNonDeterministicRendering) {
this.updateRenderAheadProgessively(this.getCurrentRenderAheadOffset());
}
this.updateRenderAheadProgessively(this.getCurrentRenderAheadOffset());
}

protected onItemLayout(index: number): void {
if (!this.isFirstLayoutComplete) {
this.isFirstLayoutComplete = true;
if (this.props.forceNonDeterministicRendering) {
this.updateRenderAheadProgessively(this.getCurrentRenderAheadOffset());
}
}
super.onItemLayout(index);
}

private updateRenderAheadProgessively(newVal: number): void {
Expand Down
12 changes: 11 additions & 1 deletion src/core/RecyclerListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,15 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
protected getVirtualRenderer(): VirtualRenderer {
return this._virtualRenderer;
}
protected onItemLayout(index: number): void {
if (this.props.onItemLayout) {
this.props.onItemLayout(index);
}
}

private _onItemLayout = (index: number) => {
this.onItemLayout(index);
}

private _processInitialOffset(): void {
if (this._pendingScrollToOffset) {
Expand Down Expand Up @@ -630,7 +639,7 @@ export default class RecyclerListView<P extends RecyclerListViewProps, S extends
extendedState={this.props.extendedState}
internalSnapshot={this.state.internalSnapshot}
renderItemContainer={this.props.renderItemContainer}
onItemLayout={this.props.onItemLayout}/>
onItemLayout={this._onItemLayout}/>
);
}
return null;
Expand Down Expand Up @@ -829,5 +838,6 @@ RecyclerListView.propTypes = {
// This can be used to hook an itemLayoutListener to listen to which item at what index is layout.
// To get the layout params of the item, you can use the ref to call method getLayout(index), e.x. : `this._recyclerRef.getLayout(index)`
// but there is a catch here, since there might be a pending relayout due to which the queried layout might not be precise.
// Caution: RLV only listens to layout changes if forceNonDeterministicRendering is true
onItemLayout: PropTypes.func,
};

0 comments on commit 33bc8f5

Please sign in to comment.