Skip to content

Commit

Permalink
feat: adjust recycle strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
ryuever committed Jul 5, 2023
1 parent 4977583 commit 2b0f0dc
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 28 deletions.
78 changes: 51 additions & 27 deletions packages/data-model/src/ListDimensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1252,43 +1252,67 @@ class ListDimensions<ItemT extends {} = {}> extends BaseDimensions {
// );

if (this._getItemLayout || this._approximateMode) {
// if velocity greater than 4, the below on high priority. then start position
// forward 4,
if (velocity > 4) {
if (Math.abs(velocity) <= 1) {
this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex + 4,
maxCount: visibleEndIndex - visibleStartIndex + 1,
startIndex: visibleStartIndex - 1,
maxCount: visibleEndIndex - visibleStartIndex + 1 + 2,
step: 1,
});
// if velocity less than -4, the above on high priority. then start position
// forward 4,
} else if (velocity < -4) {
} else if (velocity > 0) {
this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex - 4,
maxCount: visibleEndIndex - visibleStartIndex + 1,
startIndex: visibleStartIndex,
maxCount:
visibleEndIndex - visibleStartIndex + 1 + this.recycleBufferedCount,
step: 1,
});
} else {
// if velocity less than 1, scroll will stop soon, so add 1 element
// on heading and trailing as buffer
if (Math.abs(velocity) <= 1) {
this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex - 1,
maxCount: visibleEndIndex - visibleStartIndex + 3,
step: 1,
});
} else {
this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex,
maxCount: visibleEndIndex - visibleStartIndex + 1,
step: 1,
});
}
this.updateIndices(targetIndices, {
safeRange,
startIndex: visibleStartIndex - 2,
maxCount:
visibleEndIndex - visibleStartIndex + 1 + this.recycleBufferedCount,
step: 1,
});
}
// if velocity greater than 4, the below on high priority. then start position
// forward 4,
// if (velocity > 4) {
// this.updateIndices(targetIndices, {
// safeRange,
// startIndex: visibleStartIndex + 4,
// maxCount: visibleEndIndex - visibleStartIndex + 1,
// step: 1,
// });
// // if velocity less than -4, the above on high priority. then start position
// // forward 4,
// } else if (velocity < -4) {
// this.updateIndices(targetIndices, {
// safeRange,
// startIndex: visibleStartIndex - 4,
// maxCount: visibleEndIndex - visibleStartIndex + 1,
// step: 1,
// });
// } else {
// // if velocity less than 1, scroll will stop soon, so add 1 element
// // on heading and trailing as buffer
// if (Math.abs(velocity) <= 1) {
// this.updateIndices(targetIndices, {
// safeRange,
// startIndex: visibleStartIndex - 1,
// maxCount: visibleEndIndex - visibleStartIndex + 3,
// step: 1,
// });
// } else {
// this.updateIndices(targetIndices, {
// safeRange,
// startIndex: visibleStartIndex,
// maxCount: visibleEndIndex - visibleStartIndex + 1,
// step: 1,
// });
// }
// }
} else {
this.updateIndices(targetIndices, {
safeRange,
Expand Down
2 changes: 1 addition & 1 deletion packages/data-model/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const INTERVAL_TREE_INITIAL_SIZE = 16;
export const ON_END_REACHED_TIMEOUT_THRESHOLD = 200;
export const ON_END_REACHED_HANDLER_TIMEOUT_THRESHOLD = 2000;
export const DISPATCH_METRICS_THRESHOLD = 16;
export const RECYCLE_BUFFERED_COUNT = 4;
export const RECYCLE_BUFFERED_COUNT = 3;
export const LENGTH_PRECISION = 4;
export const DEFAULT_ITEM_APPROXIMATE_LENGTH = 80;

Expand Down

0 comments on commit 2b0f0dc

Please sign in to comment.