@shopify/flash-list 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/AnimatedFlashList.js +4 -6
- package/dist/AnimatedFlashList.js.map +1 -1
- package/dist/FlashList.js +1 -5
- package/dist/FlashList.js.map +1 -1
- package/dist/FlashListProps.d.ts +9 -1
- package/dist/FlashListProps.d.ts.map +1 -1
- package/dist/FlashListProps.js +1 -4
- package/dist/FlashListProps.js.map +1 -1
- package/dist/FlashListRef.js +1 -2
- package/dist/benchmark/AutoScrollHelper.js +22 -30
- package/dist/benchmark/AutoScrollHelper.js.map +1 -1
- package/dist/benchmark/JSFPSMonitor.js +27 -33
- package/dist/benchmark/JSFPSMonitor.js.map +1 -1
- package/dist/benchmark/roundToDecimalPlaces.js +2 -5
- package/dist/benchmark/roundToDecimalPlaces.js.map +1 -1
- package/dist/benchmark/useBenchmark.d.ts +9 -1
- package/dist/benchmark/useBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useBenchmark.js +86 -95
- package/dist/benchmark/useBenchmark.js.map +1 -1
- package/dist/benchmark/useDataMultiplier.js +6 -10
- package/dist/benchmark/useDataMultiplier.js.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts +4 -1
- package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
- package/dist/benchmark/useFlatListBenchmark.js +73 -81
- package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
- package/dist/errors/ErrorMessages.js +1 -4
- package/dist/errors/ErrorMessages.js.map +1 -1
- package/dist/errors/WarningMessages.d.ts +1 -0
- package/dist/errors/WarningMessages.d.ts.map +1 -1
- package/dist/errors/WarningMessages.js +2 -4
- package/dist/errors/WarningMessages.js.map +1 -1
- package/dist/index.js +17 -35
- package/dist/index.js.map +1 -1
- package/dist/isNewArch.js +6 -9
- package/dist/isNewArch.js.map +1 -1
- package/dist/native/config/PlatformHelper.android.js +2 -5
- package/dist/native/config/PlatformHelper.android.js.map +1 -1
- package/dist/native/config/PlatformHelper.ios.js +2 -5
- package/dist/native/config/PlatformHelper.ios.js.map +1 -1
- package/dist/native/config/PlatformHelper.js +2 -5
- package/dist/native/config/PlatformHelper.js.map +1 -1
- package/dist/native/config/PlatformHelper.web.js +2 -5
- package/dist/native/config/PlatformHelper.web.js.map +1 -1
- package/dist/recyclerview/LayoutCommitObserver.js +20 -24
- package/dist/recyclerview/LayoutCommitObserver.js.map +1 -1
- package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerView.js +117 -107
- package/dist/recyclerview/RecyclerView.js.map +1 -1
- package/dist/recyclerview/RecyclerViewContextProvider.js +7 -12
- package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.d.ts +2 -0
- package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
- package/dist/recyclerview/RecyclerViewManager.js +146 -164
- package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/RecyclerViewProps.js +1 -2
- package/dist/recyclerview/RenderStackManager.js +97 -188
- package/dist/recyclerview/RenderStackManager.js.map +1 -1
- package/dist/recyclerview/ViewHolder.js +16 -20
- package/dist/recyclerview/ViewHolder.js.map +1 -1
- package/dist/recyclerview/ViewHolderCollection.js +26 -30
- package/dist/recyclerview/ViewHolderCollection.js.map +1 -1
- package/dist/recyclerview/components/CompatScroller.js +6 -7
- package/dist/recyclerview/components/CompatScroller.js.map +1 -1
- package/dist/recyclerview/components/CompatView.js +6 -7
- package/dist/recyclerview/components/CompatView.js.map +1 -1
- package/dist/recyclerview/components/ScrollAnchor.js +10 -15
- package/dist/recyclerview/components/ScrollAnchor.js.map +1 -1
- package/dist/recyclerview/components/StickyHeaders.js +34 -40
- package/dist/recyclerview/components/StickyHeaders.js.map +1 -1
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js +39 -66
- package/dist/recyclerview/helpers/ConsecutiveNumbers.js.map +1 -1
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js +57 -63
- package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -1
- package/dist/recyclerview/helpers/RenderTimeTracker.js +19 -24
- package/dist/recyclerview/helpers/RenderTimeTracker.js.map +1 -1
- package/dist/recyclerview/helpers/VelocityTracker.js +16 -22
- package/dist/recyclerview/helpers/VelocityTracker.js.map +1 -1
- package/dist/recyclerview/hooks/useBoundDetection.js +37 -40
- package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -1
- package/dist/recyclerview/hooks/useLayoutState.js +9 -15
- package/dist/recyclerview/hooks/useLayoutState.js.map +1 -1
- package/dist/recyclerview/hooks/useMappingHelper.js +6 -10
- package/dist/recyclerview/hooks/useMappingHelper.js.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useOnLoad.js +17 -22
- package/dist/recyclerview/hooks/useOnLoad.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewController.js +169 -188
- package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclerViewManager.js +12 -17
- package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -1
- package/dist/recyclerview/hooks/useRecyclingState.js +10 -14
- package/dist/recyclerview/hooks/useRecyclingState.js.map +1 -1
- package/dist/recyclerview/hooks/useSecondaryProps.js +24 -30
- package/dist/recyclerview/hooks/useSecondaryProps.js.map +1 -1
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js +17 -22
- package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js.map +1 -1
- package/dist/recyclerview/hooks/useUnmountFlag.js +5 -9
- package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -1
- package/dist/recyclerview/layout-managers/GridLayoutManager.js +61 -80
- package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LayoutManager.js +83 -123
- package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js +51 -91
- package/dist/recyclerview/layout-managers/LinearLayoutManager.js.map +1 -1
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +77 -96
- package/dist/recyclerview/layout-managers/MasonryLayoutManager.js.map +1 -1
- package/dist/recyclerview/utils/adjustOffsetForRTL.js +1 -4
- package/dist/recyclerview/utils/adjustOffsetForRTL.js.map +1 -1
- package/dist/recyclerview/utils/componentUtils.js +4 -9
- package/dist/recyclerview/utils/componentUtils.js.map +1 -1
- package/dist/recyclerview/utils/findVisibleIndex.js +9 -13
- package/dist/recyclerview/utils/findVisibleIndex.js.map +1 -1
- package/dist/recyclerview/utils/measureLayout.js +12 -20
- package/dist/recyclerview/utils/measureLayout.js.map +1 -1
- package/dist/recyclerview/utils/measureLayout.web.js +15 -23
- package/dist/recyclerview/utils/measureLayout.web.js.map +1 -1
- package/dist/recyclerview/viewability/ViewToken.js +1 -2
- package/dist/recyclerview/viewability/ViewabilityHelper.js +34 -41
- package/dist/recyclerview/viewability/ViewabilityHelper.js.map +1 -1
- package/dist/recyclerview/viewability/ViewabilityManager.js +48 -61
- package/dist/recyclerview/viewability/ViewabilityManager.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/AverageWindow.js +28 -39
- package/dist/utils/AverageWindow.js.map +1 -1
- package/package.json +4 -6
- package/src/FlashListProps.ts +8 -1
- package/src/benchmark/useBenchmark.ts +47 -4
- package/src/benchmark/useFlatListBenchmark.ts +38 -5
- package/src/errors/WarningMessages.ts +2 -0
- package/src/recyclerview/RecyclerView.tsx +18 -5
- package/src/recyclerview/RecyclerViewManager.ts +12 -0
- package/src/recyclerview/hooks/useOnLoad.ts +1 -0
- package/src/recyclerview/hooks/useRecyclerViewController.tsx +7 -4
- package/dist/__tests__/AverageWindow.test.d.ts +0 -2
- package/dist/__tests__/AverageWindow.test.d.ts.map +0 -1
- package/dist/__tests__/AverageWindow.test.js +0 -104
- package/dist/__tests__/AverageWindow.test.js.map +0 -1
- package/dist/__tests__/ConsecutiveNumbers.test.d.ts +0 -2
- package/dist/__tests__/ConsecutiveNumbers.test.d.ts.map +0 -1
- package/dist/__tests__/ConsecutiveNumbers.test.js +0 -224
- package/dist/__tests__/ConsecutiveNumbers.test.js.map +0 -1
- package/dist/__tests__/GridLayoutManager.test.d.ts +0 -2
- package/dist/__tests__/GridLayoutManager.test.d.ts.map +0 -1
- package/dist/__tests__/GridLayoutManager.test.js +0 -69
- package/dist/__tests__/GridLayoutManager.test.js.map +0 -1
- package/dist/__tests__/LayoutCommitObserver.test.d.ts +0 -2
- package/dist/__tests__/LayoutCommitObserver.test.d.ts.map +0 -1
- package/dist/__tests__/LayoutCommitObserver.test.js +0 -37
- package/dist/__tests__/LayoutCommitObserver.test.js.map +0 -1
- package/dist/__tests__/LinearLayoutManager.test.d.ts +0 -2
- package/dist/__tests__/LinearLayoutManager.test.d.ts.map +0 -1
- package/dist/__tests__/LinearLayoutManager.test.js +0 -140
- package/dist/__tests__/LinearLayoutManager.test.js.map +0 -1
- package/dist/__tests__/MasonryLayoutManager.test.d.ts +0 -2
- package/dist/__tests__/MasonryLayoutManager.test.d.ts.map +0 -1
- package/dist/__tests__/MasonryLayoutManager.test.js +0 -148
- package/dist/__tests__/MasonryLayoutManager.test.js.map +0 -1
- package/dist/__tests__/RecyclerView.test.d.ts +0 -2
- package/dist/__tests__/RecyclerView.test.d.ts.map +0 -1
- package/dist/__tests__/RecyclerView.test.js +0 -103
- package/dist/__tests__/RecyclerView.test.js.map +0 -1
- package/dist/__tests__/RenderStackManager.test.d.ts +0 -2
- package/dist/__tests__/RenderStackManager.test.d.ts.map +0 -1
- package/dist/__tests__/RenderStackManager.test.js +0 -485
- package/dist/__tests__/RenderStackManager.test.js.map +0 -1
- package/dist/__tests__/ViewabilityHelper.test.d.ts +0 -2
- package/dist/__tests__/ViewabilityHelper.test.d.ts.map +0 -1
- package/dist/__tests__/ViewabilityHelper.test.js +0 -186
- package/dist/__tests__/ViewabilityHelper.test.js.map +0 -1
- package/dist/__tests__/findVisibleIndex.test.d.ts +0 -2
- package/dist/__tests__/findVisibleIndex.test.d.ts.map +0 -1
- package/dist/__tests__/findVisibleIndex.test.js +0 -259
- package/dist/__tests__/findVisibleIndex.test.js.map +0 -1
- package/dist/__tests__/helpers/createLayoutManager.d.ts +0 -34
- package/dist/__tests__/helpers/createLayoutManager.d.ts.map +0 -1
- package/dist/__tests__/helpers/createLayoutManager.js +0 -110
- package/dist/__tests__/helpers/createLayoutManager.js.map +0 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts +0 -2
- package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts.map +0 -1
- package/dist/__tests__/useUnmountAwareCallbacks.test.js +0 -185
- package/dist/__tests__/useUnmountAwareCallbacks.test.js.map +0 -1
- package/src/__tests__/AverageWindow.test.ts +0 -128
- package/src/__tests__/ConsecutiveNumbers.test.ts +0 -232
- package/src/__tests__/GridLayoutManager.test.ts +0 -113
- package/src/__tests__/LayoutCommitObserver.test.tsx +0 -63
- package/src/__tests__/LinearLayoutManager.test.ts +0 -227
- package/src/__tests__/MasonryLayoutManager.test.ts +0 -202
- package/src/__tests__/RecyclerView.test.tsx +0 -144
- package/src/__tests__/RenderStackManager.test.ts +0 -574
- package/src/__tests__/ViewabilityHelper.test.ts +0 -282
- package/src/__tests__/findVisibleIndex.test.ts +0 -369
- package/src/__tests__/helpers/createLayoutManager.ts +0 -141
- package/src/__tests__/useUnmountAwareCallbacks.test.tsx +0 -285
|
@@ -1,15 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var PlatformHelper_1 = require("../../native/config/PlatformHelper");
|
|
6
|
-
var ConsecutiveNumbers_1 = require("./ConsecutiveNumbers");
|
|
7
|
-
var RVEngagedIndicesTrackerImpl = /** @class */ (function () {
|
|
8
|
-
function RVEngagedIndicesTrackerImpl() {
|
|
1
|
+
import { PlatformConfig } from "../../native/config/PlatformHelper";
|
|
2
|
+
import { ConsecutiveNumbers } from "./ConsecutiveNumbers";
|
|
3
|
+
export class RVEngagedIndicesTrackerImpl {
|
|
4
|
+
constructor() {
|
|
9
5
|
// Current scroll position of the list
|
|
10
6
|
this.scrollOffset = 0;
|
|
11
7
|
// Distance to pre-render items before and after the visible viewport (in pixels)
|
|
12
|
-
this.drawDistance =
|
|
8
|
+
this.drawDistance = PlatformConfig.defaultDrawDistance;
|
|
13
9
|
// Whether to use offset projection to predict the next scroll offset
|
|
14
10
|
this.enableOffsetProjection = true;
|
|
15
11
|
// Average render time of the list
|
|
@@ -17,7 +13,7 @@ var RVEngagedIndicesTrackerImpl = /** @class */ (function () {
|
|
|
17
13
|
// Internal override to disable offset projection
|
|
18
14
|
this.forceDisableOffsetProjection = false;
|
|
19
15
|
// Currently rendered item indices (including buffer items)
|
|
20
|
-
this.engagedIndices =
|
|
16
|
+
this.engagedIndices = ConsecutiveNumbers.EMPTY;
|
|
21
17
|
// Buffer distribution multipliers for scroll direction optimization
|
|
22
18
|
this.smallMultiplier = 0.3; // Used for buffer in the opposite direction of scroll
|
|
23
19
|
this.largeMultiplier = 0.7; // Used for buffer in the direction of scroll
|
|
@@ -33,59 +29,59 @@ var RVEngagedIndicesTrackerImpl = /** @class */ (function () {
|
|
|
33
29
|
* 3. Adjusts buffer sizes at list boundaries
|
|
34
30
|
* 4. Returns new indices that need to be rendered
|
|
35
31
|
*/
|
|
36
|
-
|
|
32
|
+
updateScrollOffset(offset, velocity, layoutManager) {
|
|
37
33
|
// Update current scroll position
|
|
38
34
|
this.scrollOffset = offset;
|
|
39
35
|
// STEP 1: Determine the currently visible viewport
|
|
40
|
-
|
|
41
|
-
|
|
36
|
+
const windowSize = layoutManager.getWindowsSize();
|
|
37
|
+
const isHorizontal = layoutManager.isHorizontal();
|
|
42
38
|
// Update velocity history
|
|
43
39
|
if (velocity) {
|
|
44
40
|
this.updateVelocityHistory(isHorizontal ? velocity.x : velocity.y);
|
|
45
41
|
}
|
|
46
42
|
// Determine scroll direction to optimize buffer distribution
|
|
47
|
-
|
|
48
|
-
|
|
43
|
+
const isScrollingBackward = this.isScrollingBackward();
|
|
44
|
+
const viewportStart = this.enableOffsetProjection && !this.forceDisableOffsetProjection
|
|
49
45
|
? this.getProjectedScrollOffset(offset, this.averageRenderTime)
|
|
50
46
|
: offset;
|
|
51
47
|
// console.log("timeMs", this.averageRenderTime, offset, viewportStart);
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const viewportSize = isHorizontal ? windowSize.width : windowSize.height;
|
|
49
|
+
const viewportEnd = viewportStart + viewportSize;
|
|
54
50
|
// STEP 2: Determine buffer size and distribution
|
|
55
51
|
// The total extra space where items will be pre-rendered
|
|
56
|
-
|
|
52
|
+
const totalBuffer = this.drawDistance * 2;
|
|
57
53
|
// Distribute more buffer in the direction of scrolling
|
|
58
54
|
// When scrolling forward: more buffer after viewport
|
|
59
55
|
// When scrolling backward: more buffer before viewport
|
|
60
|
-
|
|
56
|
+
const beforeRatio = isScrollingBackward
|
|
61
57
|
? this.largeMultiplier
|
|
62
58
|
: this.smallMultiplier;
|
|
63
|
-
|
|
59
|
+
const afterRatio = isScrollingBackward
|
|
64
60
|
? this.smallMultiplier
|
|
65
61
|
: this.largeMultiplier;
|
|
66
|
-
|
|
67
|
-
|
|
62
|
+
const bufferBefore = Math.ceil(totalBuffer * beforeRatio);
|
|
63
|
+
const bufferAfter = Math.ceil(totalBuffer * afterRatio);
|
|
68
64
|
// STEP 3: Calculate the extended viewport (visible area + buffers)
|
|
69
65
|
// The start position with buffer (never less than 0)
|
|
70
|
-
|
|
66
|
+
let extendedStart = Math.max(0, viewportStart - bufferBefore);
|
|
71
67
|
// If we couldn't apply full buffer at start, calculate how much was unused
|
|
72
|
-
|
|
68
|
+
const unusedStartBuffer = Math.max(0, bufferBefore - viewportStart);
|
|
73
69
|
// Add any unused start buffer to the end buffer
|
|
74
|
-
|
|
70
|
+
let extendedEnd = viewportEnd + bufferAfter + unusedStartBuffer;
|
|
75
71
|
// STEP 4: Handle end boundary adjustments
|
|
76
72
|
// Get the total content size to check for end boundary
|
|
77
|
-
|
|
78
|
-
|
|
73
|
+
const layoutSize = layoutManager.getLayoutSize();
|
|
74
|
+
const maxPosition = isHorizontal ? layoutSize.width : layoutSize.height;
|
|
79
75
|
// If we hit the end boundary, redistribute unused buffer to the start
|
|
80
76
|
if (extendedEnd > maxPosition) {
|
|
81
77
|
// Calculate unused end buffer and apply it to the start if possible
|
|
82
|
-
|
|
78
|
+
const unusedEndBuffer = extendedEnd - maxPosition;
|
|
83
79
|
extendedEnd = maxPosition;
|
|
84
80
|
// Try to extend start position further with the unused end buffer
|
|
85
81
|
extendedStart = Math.max(0, extendedStart - unusedEndBuffer);
|
|
86
82
|
}
|
|
87
83
|
// STEP 5: Get and return the new engaged indices
|
|
88
|
-
|
|
84
|
+
const newEngagedIndices = layoutManager.getVisibleLayouts(extendedStart, extendedEnd);
|
|
89
85
|
// console.log(
|
|
90
86
|
// "newEngagedIndices",
|
|
91
87
|
// newEngagedIndices,
|
|
@@ -93,31 +89,31 @@ var RVEngagedIndicesTrackerImpl = /** @class */ (function () {
|
|
|
93
89
|
// viewportStart
|
|
94
90
|
// );
|
|
95
91
|
// Only return new indices if they've changed
|
|
96
|
-
|
|
92
|
+
const oldEngagedIndices = this.engagedIndices;
|
|
97
93
|
this.engagedIndices = newEngagedIndices;
|
|
98
94
|
return newEngagedIndices.equals(oldEngagedIndices)
|
|
99
95
|
? undefined
|
|
100
96
|
: newEngagedIndices;
|
|
101
|
-
}
|
|
97
|
+
}
|
|
102
98
|
/**
|
|
103
99
|
* Updates the velocity history with a new velocity value.
|
|
104
100
|
* @param velocity - Current scroll velocity component (x or y)
|
|
105
101
|
*/
|
|
106
|
-
|
|
102
|
+
updateVelocityHistory(velocity) {
|
|
107
103
|
this.velocityHistory[this.velocityIndex] = velocity;
|
|
108
104
|
this.velocityIndex = (this.velocityIndex + 1) % this.velocityHistory.length;
|
|
109
|
-
}
|
|
105
|
+
}
|
|
110
106
|
/**
|
|
111
107
|
* Determines scroll direction by analyzing recent velocity history.
|
|
112
108
|
* Uses a majority voting system on the last 5 velocity values.
|
|
113
109
|
* @returns true if scrolling backward (negative direction), false otherwise
|
|
114
110
|
*/
|
|
115
|
-
|
|
111
|
+
isScrollingBackward() {
|
|
116
112
|
// should decide based on whether we have more positive or negative values, use for loop
|
|
117
|
-
|
|
118
|
-
|
|
113
|
+
let positiveCount = 0;
|
|
114
|
+
let negativeCount = 0;
|
|
119
115
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
120
|
-
for (
|
|
116
|
+
for (let i = 0; i < this.velocityHistory.length; i++) {
|
|
121
117
|
if (this.velocityHistory[i] > 0) {
|
|
122
118
|
positiveCount++;
|
|
123
119
|
}
|
|
@@ -126,61 +122,61 @@ var RVEngagedIndicesTrackerImpl = /** @class */ (function () {
|
|
|
126
122
|
}
|
|
127
123
|
}
|
|
128
124
|
return positiveCount < negativeCount;
|
|
129
|
-
}
|
|
125
|
+
}
|
|
130
126
|
/**
|
|
131
127
|
* Calculates the median velocity based on velocity history
|
|
132
128
|
* Medina works better agains outliers
|
|
133
129
|
* @returns Median velocity over the recent history
|
|
134
130
|
*/
|
|
135
|
-
|
|
131
|
+
getMedianVelocity() {
|
|
136
132
|
// Make a copy of velocity history and sort it
|
|
137
|
-
|
|
138
|
-
|
|
133
|
+
const sortedVelocities = [...this.velocityHistory].sort((valueA, valueB) => valueA - valueB);
|
|
134
|
+
const length = sortedVelocities.length;
|
|
139
135
|
// If length is odd, return the middle element
|
|
140
136
|
if (length % 2 === 1) {
|
|
141
137
|
return sortedVelocities[Math.floor(length / 2)];
|
|
142
138
|
}
|
|
143
139
|
// If length is even, return the average of the two middle elements
|
|
144
|
-
|
|
140
|
+
const midIndex = length / 2;
|
|
145
141
|
return (sortedVelocities[midIndex - 1] + sortedVelocities[midIndex]) / 2;
|
|
146
|
-
}
|
|
142
|
+
}
|
|
147
143
|
/**
|
|
148
144
|
* Projects the next scroll offset based on median velocity
|
|
149
145
|
* @param timeMs Time in milliseconds to predict ahead
|
|
150
146
|
* @returns Projected scroll offset
|
|
151
147
|
*/
|
|
152
|
-
|
|
153
|
-
|
|
148
|
+
getProjectedScrollOffset(offset, timeMs) {
|
|
149
|
+
const medianVelocity = this.getMedianVelocity();
|
|
154
150
|
// Convert time from ms to seconds for velocity calculation
|
|
155
151
|
// Predict next position: current position + (velocity * time)
|
|
156
152
|
return offset + medianVelocity * timeMs;
|
|
157
|
-
}
|
|
153
|
+
}
|
|
158
154
|
/**
|
|
159
155
|
* Calculates which items are currently visible in the viewport.
|
|
160
156
|
* Unlike getEngagedIndices, this doesn't include buffer items.
|
|
161
157
|
* @param layoutManager - Layout manager to fetch item positions
|
|
162
158
|
* @returns Indices of items currently visible in the viewport
|
|
163
159
|
*/
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
160
|
+
computeVisibleIndices(layoutManager) {
|
|
161
|
+
const windowSize = layoutManager.getWindowsSize();
|
|
162
|
+
const isHorizontal = layoutManager.isHorizontal();
|
|
167
163
|
// Calculate viewport boundaries
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
164
|
+
const viewportStart = this.scrollOffset;
|
|
165
|
+
const viewportSize = isHorizontal ? windowSize.width : windowSize.height;
|
|
166
|
+
const viewportEnd = viewportStart + viewportSize;
|
|
171
167
|
// Get indices of items currently visible in the viewport
|
|
172
|
-
|
|
168
|
+
const newVisibleIndices = layoutManager.getVisibleLayouts(viewportStart, viewportEnd);
|
|
173
169
|
return newVisibleIndices;
|
|
174
|
-
}
|
|
170
|
+
}
|
|
175
171
|
/**
|
|
176
172
|
* Returns the currently engaged (rendered) indices.
|
|
177
173
|
* This includes both visible items and buffer items.
|
|
178
174
|
* @returns The last computed set of engaged indices
|
|
179
175
|
*/
|
|
180
|
-
|
|
176
|
+
getEngagedIndices() {
|
|
181
177
|
return this.engagedIndices;
|
|
182
|
-
}
|
|
183
|
-
|
|
178
|
+
}
|
|
179
|
+
setScrollDirection(scrollDirection) {
|
|
184
180
|
if (scrollDirection === "forward") {
|
|
185
181
|
this.velocityHistory = [0, 0, 0, 0.1, 0.1];
|
|
186
182
|
this.velocityIndex = 0;
|
|
@@ -189,20 +185,18 @@ var RVEngagedIndicesTrackerImpl = /** @class */ (function () {
|
|
|
189
185
|
this.velocityHistory = [0, 0, 0, -0.1, -0.1];
|
|
190
186
|
this.velocityIndex = 0;
|
|
191
187
|
}
|
|
192
|
-
}
|
|
188
|
+
}
|
|
193
189
|
/**
|
|
194
190
|
* Resets the velocity history based on the current scroll direction.
|
|
195
191
|
* This ensures that the velocity history is always in sync with the current scroll direction.
|
|
196
192
|
*/
|
|
197
|
-
|
|
193
|
+
resetVelocityHistory() {
|
|
198
194
|
if (this.isScrollingBackward()) {
|
|
199
195
|
this.setScrollDirection("backward");
|
|
200
196
|
}
|
|
201
197
|
else {
|
|
202
198
|
this.setScrollDirection("forward");
|
|
203
199
|
}
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
}());
|
|
207
|
-
exports.RVEngagedIndicesTrackerImpl = RVEngagedIndicesTrackerImpl;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
208
202
|
//# sourceMappingURL=EngagedIndicesTracker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EngagedIndicesTracker.js","sourceRoot":"","sources":["../../../src/recyclerview/helpers/EngagedIndicesTracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"EngagedIndicesTracker.js","sourceRoot":"","sources":["../../../src/recyclerview/helpers/EngagedIndicesTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAGpE,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAwD1D,MAAM,OAAO,2BAA2B;IAAxC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AC;QACxC,MAAM,YAAY,GAAG,YAAY,CAAC,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC;QACzE,MAAM,WAAW,GAAG,aAAa,GAAG,YAAY,CAAC;QAEjD,yDAAyD;QACzD,MAAM,iBAAiB,GAAG,aAAa,CAAC,iBAAiB,CACvD,aAAa,EACb,WAAW,CACZ,CAAC;QACF,OAAO,iBAAiB,CAAC;IAC3B,CAAC;IAED;;;;OAIG;IACH,iBAAiB;QACf,OAAO,IAAI,CAAC,cAAc,CAAC;IAC7B,CAAC;IAED,kBAAkB,CAAC,eAAuC;QACxD,IAAI,eAAe,KAAK,SAAS,EAAE,CAAC;YAClC,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;YAC3C,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACzB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,eAAe,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;YAC7C,IAAI,CAAC,aAAa,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;;OAGG;IACH,oBAAoB;QAClB,IAAI,IAAI,CAAC,mBAAmB,EAAE,EAAE,CAAC;YAC/B,IAAI,CAAC,kBAAkB,CAAC,UAAU,CAAC,CAAC;QACtC,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,CAAC;QACrC,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,49 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var RenderTimeTracker = /** @class */ (function () {
|
|
7
|
-
function RenderTimeTracker() {
|
|
8
|
-
this.renderTimeAvgWindow = new AverageWindow_1.AverageWindow(5);
|
|
1
|
+
import { PlatformConfig } from "../../native/config/PlatformHelper";
|
|
2
|
+
import { AverageWindow } from "../../utils/AverageWindow";
|
|
3
|
+
export class RenderTimeTracker {
|
|
4
|
+
constructor() {
|
|
5
|
+
this.renderTimeAvgWindow = new AverageWindow(5);
|
|
9
6
|
this.lastTimerStartedAt = -1;
|
|
10
7
|
this.maxRenderTime = 32; // TODO: Improve this even more
|
|
11
8
|
this.defaultRenderTime = 16;
|
|
12
9
|
this.rendersWithoutCommit = 0;
|
|
13
10
|
this.maxRendersWithoutCommit = 40;
|
|
14
11
|
}
|
|
15
|
-
|
|
12
|
+
startTracking() {
|
|
16
13
|
this.rendersWithoutCommit++;
|
|
17
|
-
if (!
|
|
14
|
+
if (!PlatformConfig.trackAverageRenderTimeForOffsetProjection) {
|
|
18
15
|
return;
|
|
19
16
|
}
|
|
20
17
|
if (this.lastTimerStartedAt === -1) {
|
|
21
18
|
this.lastTimerStartedAt = Date.now();
|
|
22
19
|
}
|
|
23
|
-
}
|
|
24
|
-
|
|
20
|
+
}
|
|
21
|
+
markRenderComplete() {
|
|
25
22
|
this.rendersWithoutCommit = 0;
|
|
26
|
-
if (!
|
|
23
|
+
if (!PlatformConfig.trackAverageRenderTimeForOffsetProjection) {
|
|
27
24
|
return;
|
|
28
25
|
}
|
|
29
26
|
if (this.lastTimerStartedAt !== -1) {
|
|
30
27
|
this.renderTimeAvgWindow.addValue(Date.now() - this.lastTimerStartedAt);
|
|
31
28
|
this.lastTimerStartedAt = -1;
|
|
32
29
|
}
|
|
33
|
-
}
|
|
34
|
-
|
|
30
|
+
}
|
|
31
|
+
hasExceededMaxRendersWithoutCommit() {
|
|
35
32
|
return this.rendersWithoutCommit >= this.maxRendersWithoutCommit;
|
|
36
|
-
}
|
|
37
|
-
|
|
33
|
+
}
|
|
34
|
+
getRawValue() {
|
|
38
35
|
return this.renderTimeAvgWindow.currentValue;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
if (!
|
|
36
|
+
}
|
|
37
|
+
getAverageRenderTime() {
|
|
38
|
+
if (!PlatformConfig.trackAverageRenderTimeForOffsetProjection) {
|
|
42
39
|
return this.defaultRenderTime;
|
|
43
40
|
}
|
|
44
41
|
return Math.min(this.maxRenderTime, Math.max(Math.round(this.renderTimeAvgWindow.currentValue), 16));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
}());
|
|
48
|
-
exports.RenderTimeTracker = RenderTimeTracker;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
49
44
|
//# sourceMappingURL=RenderTimeTracker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderTimeTracker.js","sourceRoot":"","sources":["../../../src/recyclerview/helpers/RenderTimeTracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RenderTimeTracker.js","sourceRoot":"","sources":["../../../src/recyclerview/helpers/RenderTimeTracker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,OAAO,iBAAiB;IAA9B;QACU,wBAAmB,GAAG,IAAI,aAAa,CAAC,CAAC,CAAC,CAAC;QAC3C,uBAAkB,GAAG,CAAC,CAAC,CAAC;QACxB,kBAAa,GAAG,EAAE,CAAC,CAAC,+BAA+B;QACnD,sBAAiB,GAAG,EAAE,CAAC;QACvB,yBAAoB,GAAG,CAAC,CAAC;QACzB,4BAAuB,GAAG,EAAE,CAAC;IAwCvC,CAAC;IAtCC,aAAa;QACX,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC5B,IAAI,CAAC,cAAc,CAAC,yCAAyC,EAAE,CAAC;YAC9D,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,kBAAkB,KAAK,CAAC,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,kBAAkB,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACvC,CAAC;IACH,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,oBAAoB,GAAG,CAAC,CAAC;QAC9B,IAAI,CAAC,cAAc,CAAC,yCAAyC,EAAE,CAAC;YAC9D,OAAO;QACT,CAAC;QACD,IAAI,IAAI,CAAC,kBAAkB,KAAK,CAAC,CAAC,EAAE,CAAC;YACnC,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,IAAI,CAAC,kBAAkB,CAAC,CAAC;YACxE,IAAI,CAAC,kBAAkB,GAAG,CAAC,CAAC,CAAC;QAC/B,CAAC;IACH,CAAC;IAED,kCAAkC;QAChC,OAAO,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,uBAAuB,CAAC;IACnE,CAAC;IAED,WAAW;QACT,OAAO,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC;IAC/C,CAAC;IAED,oBAAoB;QAClB,IAAI,CAAC,cAAc,CAAC,yCAAyC,EAAE,CAAC;YAC9D,OAAO,IAAI,CAAC,iBAAiB,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CACb,IAAI,CAAC,aAAa,EAClB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,mBAAmB,CAAC,YAAY,CAAC,EAAE,EAAE,CAAC,CAChE,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.VelocityTracker = void 0;
|
|
4
1
|
/**
|
|
5
2
|
* Tracks and calculates velocity for scroll/drag movements
|
|
6
3
|
* Used to determine momentum scrolling behavior
|
|
7
4
|
*/
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
export class VelocityTracker {
|
|
6
|
+
constructor() {
|
|
10
7
|
/** Timestamp of the last velocity update */
|
|
11
8
|
this.lastUpdateTime = Date.now();
|
|
12
9
|
/** Current velocity vector with x and y components */
|
|
@@ -22,15 +19,14 @@ var VelocityTracker = /** @class */ (function () {
|
|
|
22
19
|
* @param isRTL Whether layout direction is right-to-left
|
|
23
20
|
* @param callback Function to call with velocity updates and momentum end signal
|
|
24
21
|
*/
|
|
25
|
-
|
|
26
|
-
var _this = this;
|
|
22
|
+
computeVelocity(newOffset, oldOffset, isHorizontal, callback) {
|
|
27
23
|
// Clear any pending momentum end timeout
|
|
28
24
|
this.cleanUp();
|
|
29
25
|
// Calculate time since last update
|
|
30
|
-
|
|
31
|
-
|
|
26
|
+
const currentTime = Date.now();
|
|
27
|
+
const timeSinceLastUpdate = Math.max(1, currentTime - this.lastUpdateTime);
|
|
32
28
|
// Calculate velocity as distance/time
|
|
33
|
-
|
|
29
|
+
const newVelocity = (newOffset - oldOffset) / timeSinceLastUpdate;
|
|
34
30
|
// console.log(
|
|
35
31
|
// "newVelocity",
|
|
36
32
|
// newOffset,
|
|
@@ -47,24 +43,22 @@ var VelocityTracker = /** @class */ (function () {
|
|
|
47
43
|
// Trigger callback with current velocity
|
|
48
44
|
callback(this.velocity, false);
|
|
49
45
|
// Set timeout to signal momentum end after 100ms of no updates
|
|
50
|
-
this.timeoutId = setTimeout(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
callback(
|
|
46
|
+
this.timeoutId = setTimeout(() => {
|
|
47
|
+
this.cleanUp();
|
|
48
|
+
this.lastUpdateTime = Date.now();
|
|
49
|
+
this.velocity.x = 0;
|
|
50
|
+
this.velocity.y = 0;
|
|
51
|
+
callback(this.velocity, true);
|
|
56
52
|
}, 100);
|
|
57
|
-
}
|
|
53
|
+
}
|
|
58
54
|
/**
|
|
59
55
|
* Cleans up resources by clearing any pending timeout
|
|
60
56
|
*/
|
|
61
|
-
|
|
57
|
+
cleanUp() {
|
|
62
58
|
if (this.timeoutId !== null) {
|
|
63
59
|
clearTimeout(this.timeoutId);
|
|
64
60
|
this.timeoutId = null;
|
|
65
61
|
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}());
|
|
69
|
-
exports.VelocityTracker = VelocityTracker;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
70
64
|
//# sourceMappingURL=VelocityTracker.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VelocityTracker.js","sourceRoot":"","sources":["../../../src/recyclerview/helpers/VelocityTracker.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"VelocityTracker.js","sourceRoot":"","sources":["../../../src/recyclerview/helpers/VelocityTracker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,MAAM,OAAO,eAAe;IAA5B;QACE,4CAA4C;QACpC,mBAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QACpC,sDAAsD;QAC9C,aAAQ,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC;QAElC,4CAA4C;QACpC,cAAS,GAA0B,IAAI,CAAC;IAiElD,CAAC;IA/DC;;;;;;;OAOG;IACH,eAAe,CACb,SAAiB,EACjB,SAAiB,EACjB,YAAqB,EACrB,QAGS;QAET,yCAAyC;QACzC,IAAI,CAAC,OAAO,EAAE,CAAC;QACf,mCAAmC;QACnC,MAAM,WAAW,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAC/B,MAAM,mBAAmB,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC,cAAc,CAAC,CAAC;QAE3E,sCAAsC;QACtC,MAAM,WAAW,GAAG,CAAC,SAAS,GAAG,SAAS,CAAC,GAAG,mBAAmB,CAAC;QAElE,eAAe;QACf,mBAAmB;QACnB,eAAe;QACf,eAAe;QACf,iBAAiB;QACjB,yBAAyB;QACzB,yBAAyB;QACzB,gBAAgB;QAChB,KAAK;QACL,IAAI,CAAC,cAAc,GAAG,WAAW,CAAC;QAElC,qCAAqC;QACrC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;QACjD,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC;QAEjD,yCAAyC;QACzC,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;QAE/B,+DAA+D;QAC/D,IAAI,CAAC,SAAS,GAAG,UAAU,CAAC,GAAG,EAAE;YAC/B,IAAI,CAAC,OAAO,EAAE,CAAC;YACf,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACjC,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;YACpB,IAAI,CAAC,QAAQ,CAAC,CAAC,GAAG,CAAC,CAAC;YACpB,QAAQ,CAAC,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAChC,CAAC,EAAE,GAAG,CAAC,CAAC;IACV,CAAC;IAED;;OAEG;IACH,OAAO;QACL,IAAI,IAAI,CAAC,SAAS,KAAK,IAAI,EAAE,CAAC;YAC5B,YAAY,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;YAC7B,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QACxB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.useBoundDetection = useBoundDetection;
|
|
4
|
-
var react_1 = require("react");
|
|
5
|
-
var useUnmountAwareCallbacks_1 = require("./useUnmountAwareCallbacks");
|
|
1
|
+
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
2
|
+
import { useUnmountAwareAnimationFrame } from "./useUnmountAwareCallbacks";
|
|
6
3
|
/**
|
|
7
4
|
* Hook to detect when the scroll position reaches near the start or end of the list
|
|
8
5
|
* and trigger the appropriate callbacks. This hook is responsible for:
|
|
@@ -14,55 +11,55 @@ var useUnmountAwareCallbacks_1 = require("./useUnmountAwareCallbacks");
|
|
|
14
11
|
* @param props - The RecyclerViewProps containing configuration and callbacks
|
|
15
12
|
* @param scrollViewRef - Reference to the scrollable container component
|
|
16
13
|
*/
|
|
17
|
-
function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
14
|
+
export function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
18
15
|
// Track whether we've already triggered the end reached callback to prevent duplicate calls
|
|
19
|
-
|
|
16
|
+
const pendingEndReached = useRef(false);
|
|
20
17
|
// Track whether we've already triggered the start reached callback to prevent duplicate calls
|
|
21
|
-
|
|
18
|
+
const pendingStartReached = useRef(false);
|
|
22
19
|
// Track whether we should auto-scroll to bottom when new content is added
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
const pendingAutoscrollToBottom = useRef(false);
|
|
21
|
+
const lastCheckBoundsTime = useRef(Date.now());
|
|
22
|
+
const { data } = recyclerViewManager.props;
|
|
23
|
+
const { requestAnimationFrame } = useUnmountAwareAnimationFrame();
|
|
24
|
+
const windowHeight = recyclerViewManager.hasLayout()
|
|
28
25
|
? recyclerViewManager.getWindowSize().height
|
|
29
26
|
: 0;
|
|
30
|
-
|
|
27
|
+
const contentHeight = recyclerViewManager.hasLayout()
|
|
31
28
|
? recyclerViewManager.getChildContainerDimensions().height
|
|
32
29
|
: 0;
|
|
33
|
-
|
|
30
|
+
const windowWidth = recyclerViewManager.hasLayout()
|
|
34
31
|
? recyclerViewManager.getWindowSize().width
|
|
35
32
|
: 0;
|
|
36
|
-
|
|
33
|
+
const contentWidth = recyclerViewManager.hasLayout()
|
|
37
34
|
? recyclerViewManager.getChildContainerDimensions().width
|
|
38
35
|
: 0;
|
|
39
36
|
/**
|
|
40
37
|
* Checks if the scroll position is near the start or end of the list
|
|
41
38
|
* and triggers appropriate callbacks if configured.
|
|
42
39
|
*/
|
|
43
|
-
|
|
40
|
+
const checkBounds = useCallback(() => {
|
|
44
41
|
var _a;
|
|
45
42
|
lastCheckBoundsTime.current = Date.now();
|
|
46
|
-
|
|
43
|
+
const { onEndReached, onStartReached, maintainVisibleContentPosition, horizontal, onEndReachedThreshold: onEndReachedThresholdProp, onStartReachedThreshold: onStartReachedThresholdProp, } = recyclerViewManager.props;
|
|
47
44
|
// Skip all calculations if neither callback is provided and autoscroll is disabled
|
|
48
|
-
|
|
45
|
+
const autoscrollToBottomThreshold = (_a = maintainVisibleContentPosition === null || maintainVisibleContentPosition === void 0 ? void 0 : maintainVisibleContentPosition.autoscrollToBottomThreshold) !== null && _a !== void 0 ? _a : -1;
|
|
49
46
|
if (!onEndReached && !onStartReached && autoscrollToBottomThreshold < 0) {
|
|
50
47
|
return;
|
|
51
48
|
}
|
|
52
49
|
if (recyclerViewManager.getIsFirstLayoutComplete()) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
50
|
+
const lastScrollOffset = recyclerViewManager.getAbsoluteLastScrollOffset();
|
|
51
|
+
const contentSize = recyclerViewManager.getChildContainerDimensions();
|
|
52
|
+
const windowSize = recyclerViewManager.getWindowSize();
|
|
53
|
+
const isHorizontal = horizontal === true;
|
|
57
54
|
// Calculate dimensions based on scroll direction
|
|
58
|
-
|
|
59
|
-
|
|
55
|
+
const visibleLength = isHorizontal ? windowSize.width : windowSize.height;
|
|
56
|
+
const contentLength = (isHorizontal ? contentSize.width : contentSize.height) +
|
|
60
57
|
recyclerViewManager.firstItemOffset;
|
|
61
58
|
// Check if we're near the end of the list
|
|
62
59
|
if (onEndReached) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
60
|
+
const onEndReachedThreshold = onEndReachedThresholdProp !== null && onEndReachedThresholdProp !== void 0 ? onEndReachedThresholdProp : 0.5;
|
|
61
|
+
const endThresholdDistance = onEndReachedThreshold * visibleLength;
|
|
62
|
+
const isNearEnd = Math.ceil(lastScrollOffset + visibleLength) >=
|
|
66
63
|
contentLength - endThresholdDistance;
|
|
67
64
|
if (isNearEnd && !pendingEndReached.current) {
|
|
68
65
|
pendingEndReached.current = true;
|
|
@@ -72,9 +69,9 @@ function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
|
72
69
|
}
|
|
73
70
|
// Check if we're near the start of the list
|
|
74
71
|
if (onStartReached) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
72
|
+
const onStartReachedThreshold = onStartReachedThresholdProp !== null && onStartReachedThresholdProp !== void 0 ? onStartReachedThresholdProp : 0.2;
|
|
73
|
+
const startThresholdDistance = onStartReachedThreshold * visibleLength;
|
|
74
|
+
const isNearStart = lastScrollOffset <= startThresholdDistance;
|
|
78
75
|
if (isNearStart && !pendingStartReached.current) {
|
|
79
76
|
pendingStartReached.current = true;
|
|
80
77
|
onStartReached();
|
|
@@ -83,8 +80,8 @@ function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
|
83
80
|
}
|
|
84
81
|
// Handle auto-scrolling to bottom for vertical lists
|
|
85
82
|
if (!isHorizontal && autoscrollToBottomThreshold >= 0) {
|
|
86
|
-
|
|
87
|
-
|
|
83
|
+
const autoscrollToBottomThresholdDistance = autoscrollToBottomThreshold * visibleLength;
|
|
84
|
+
const isNearBottom = Math.ceil(lastScrollOffset + visibleLength) >=
|
|
88
85
|
contentLength - autoscrollToBottomThresholdDistance;
|
|
89
86
|
if (isNearBottom) {
|
|
90
87
|
pendingAutoscrollToBottom.current = true;
|
|
@@ -95,12 +92,12 @@ function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
|
95
92
|
}
|
|
96
93
|
}
|
|
97
94
|
}, [recyclerViewManager]);
|
|
98
|
-
|
|
95
|
+
const runAutoScrollToBottomCheck = useCallback(() => {
|
|
99
96
|
if (pendingAutoscrollToBottom.current) {
|
|
100
97
|
pendingAutoscrollToBottom.current = false;
|
|
101
|
-
requestAnimationFrame(
|
|
98
|
+
requestAnimationFrame(() => {
|
|
102
99
|
var _a, _b, _c;
|
|
103
|
-
|
|
100
|
+
const shouldAnimate = (_b = (_a = recyclerViewManager.props.maintainVisibleContentPosition) === null || _a === void 0 ? void 0 : _a.animateAutoScrollToBottom) !== null && _b !== void 0 ? _b : true;
|
|
104
101
|
(_c = scrollViewRef.current) === null || _c === void 0 ? void 0 : _c.scrollToEnd({
|
|
105
102
|
animated: shouldAnimate,
|
|
106
103
|
});
|
|
@@ -108,17 +105,17 @@ function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
|
108
105
|
}
|
|
109
106
|
}, [requestAnimationFrame, scrollViewRef, recyclerViewManager]);
|
|
110
107
|
// Reset end reached state when data changes
|
|
111
|
-
|
|
108
|
+
useMemo(() => {
|
|
112
109
|
pendingEndReached.current = false;
|
|
113
110
|
// needs to run only when data changes
|
|
114
111
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
115
112
|
}, [data]);
|
|
116
113
|
// Auto-scroll to bottom when new content is added and we're near the bottom
|
|
117
|
-
|
|
114
|
+
useEffect(() => {
|
|
118
115
|
runAutoScrollToBottomCheck();
|
|
119
116
|
}, [data, runAutoScrollToBottomCheck, windowHeight, windowWidth]);
|
|
120
117
|
// Since content changes frequently, we try and avoid doing the auto scroll during active scrolls
|
|
121
|
-
|
|
118
|
+
useEffect(() => {
|
|
122
119
|
if (Date.now() - lastCheckBoundsTime.current >= 100) {
|
|
123
120
|
runAutoScrollToBottomCheck();
|
|
124
121
|
}
|
|
@@ -129,7 +126,7 @@ function useBoundDetection(recyclerViewManager, scrollViewRef) {
|
|
|
129
126
|
runAutoScrollToBottomCheck,
|
|
130
127
|
]);
|
|
131
128
|
return {
|
|
132
|
-
checkBounds
|
|
129
|
+
checkBounds,
|
|
133
130
|
};
|
|
134
131
|
}
|
|
135
132
|
//# sourceMappingURL=useBoundDetection.js.map
|