Skip to content

Commit

Permalink
Adding capability to set final offset after progressive list view upd…
Browse files Browse the repository at this point in the history
…ates (#685)

* Item container support added

* Added description for renderItemContainer

* version bump

* fixed bug where layout size was ignored on first load by scroll component callback

* adding final update function to progressive list view

* version bump

Co-authored-by: Talha Naqvi <talha.naqvi@shopify.com>
  • Loading branch information
naqvitalha and naqvitalha authored Jan 27, 2022
1 parent 269ac85 commit 0008f6c
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
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.2",
"version": "3.1.0-beta.3",
"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
20 changes: 20 additions & 0 deletions src/core/ProgressiveListView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,19 @@ import RecyclerListView, { RecyclerListViewProps, RecyclerListViewState } from "
export interface ProgressiveListViewProps extends RecyclerListViewProps {
maxRenderAhead?: number;
renderAheadStep?: number;

/**
* A smaller final value can help in building up recycler pool in advance. This is only used if there is a valid updated cycle.
* e.g, if maxRenderAhead is 0 then there will be no cycle and final value will be unused
*/
finalRenderAheadOffset?: number;
}
/**
* This will incremently update renderAhread distance and render the page progressively.
* renderAheadOffset = initial value which will be incremented
* renderAheadStep = amount of increment made on each frame
* maxRenderAhead = maximum value for render ahead at the end of update cycle
* finalRenderAheadOffset = value to set after whole update cycle is completed. If undefined, final offset value will be equal to maxRenderAhead
*/
export default class ProgressiveListView extends RecyclerListView<ProgressiveListViewProps, RecyclerListViewState> {
public static defaultProps = {
Expand Down Expand Up @@ -43,11 +53,21 @@ export default class ProgressiveListView extends RecyclerListView<ProgressiveLis
if (currentRenderAheadOffset < maxContentSize && currentRenderAheadOffset < this.props.maxRenderAhead) {
const newRenderAheadOffset = currentRenderAheadOffset + this.props.renderAheadStep;
this.updateRenderAheadProgessively(newRenderAheadOffset);
} else {
this.performFinalUpdate();
}
}
}
}

private performFinalUpdate(): void {
requestAnimationFrame(() => {
if (this.props.finalRenderAheadOffset !== undefined) {
this.updateRenderAheadOffset(this.props.finalRenderAheadOffset);
}
});
}

private cancelRenderAheadUpdate(): void {
if (this.renderAheadUdpateCallbackId) {
cancelAnimationFrame(this.renderAheadUdpateCallbackId);
Expand Down

0 comments on commit 0008f6c

Please sign in to comment.