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

Adding capability to set final offset after progressive list view updates #685

Merged
merged 8 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
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