@shopify/flash-list 2.0.4-alpha.1 → 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.js +1 -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 +109 -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.js +138 -167
- 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.js +16 -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/recyclerview/RecyclerView.tsx +7 -5
- 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__/RecyclerViewManager.test.d.ts +0 -2
- package/dist/__tests__/RecyclerViewManager.test.d.ts.map +0 -1
- package/dist/__tests__/RecyclerViewManager.test.js +0 -56
- package/dist/__tests__/RecyclerViewManager.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__/RecyclerViewManager.test.ts +0 -74
- 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,18 +1,13 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.RenderStackManager = void 0;
|
|
4
|
-
var tslib_1 = require("tslib");
|
|
5
1
|
/**
|
|
6
2
|
* Manages the recycling of rendered items in a virtualized list.
|
|
7
3
|
* This class handles tracking, recycling, and reusing item keys to optimize
|
|
8
4
|
* rendering performance by minimizing creation/destruction of components.
|
|
9
5
|
*/
|
|
10
|
-
|
|
6
|
+
export class RenderStackManager {
|
|
11
7
|
/**
|
|
12
8
|
* @param maxItemsInRecyclePool - Maximum number of items that can be in the recycle pool
|
|
13
9
|
*/
|
|
14
|
-
|
|
15
|
-
if (maxItemsInRecyclePool === void 0) { maxItemsInRecyclePool = Number.MAX_SAFE_INTEGER; }
|
|
10
|
+
constructor(maxItemsInRecyclePool = Number.MAX_SAFE_INTEGER) {
|
|
16
11
|
this.disableRecycling = false;
|
|
17
12
|
this.maxItemsInRecyclePool = maxItemsInRecyclePool;
|
|
18
13
|
this.recycleKeyPools = new Map();
|
|
@@ -34,186 +29,113 @@ var RenderStackManager = /** @class */ (function () {
|
|
|
34
29
|
* @param engagedIndices - Collection of indices that are currently visible or engaged
|
|
35
30
|
* @param dataLength - Total length of the data set
|
|
36
31
|
*/
|
|
37
|
-
|
|
38
|
-
var e_1, _a, e_2, _b, e_3, _c, e_4, _d, e_5, _e;
|
|
39
|
-
var _this = this;
|
|
32
|
+
sync(getStableId, getItemType, engagedIndices, dataLength) {
|
|
40
33
|
this.clearRecyclePool();
|
|
41
34
|
this.unProcessedIndices.clear();
|
|
42
35
|
// Recycle keys for items that are no longer valid or visible
|
|
43
|
-
this.keyMap.forEach(
|
|
44
|
-
|
|
36
|
+
this.keyMap.forEach((keyInfo, key) => {
|
|
37
|
+
const { index, stableId, itemType } = keyInfo;
|
|
45
38
|
if (index >= dataLength) {
|
|
46
|
-
|
|
39
|
+
this.recycleKey(key);
|
|
47
40
|
return;
|
|
48
41
|
}
|
|
49
|
-
if (!
|
|
50
|
-
|
|
42
|
+
if (!this.disableRecycling) {
|
|
43
|
+
this.unProcessedIndices.add(index);
|
|
51
44
|
}
|
|
52
45
|
if (!engagedIndices.includes(index)) {
|
|
53
|
-
|
|
46
|
+
this.recycleKey(key);
|
|
54
47
|
return;
|
|
55
48
|
}
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
const newStableId = getStableId(index);
|
|
50
|
+
const newItemType = getItemType(index);
|
|
58
51
|
if (stableId !== newStableId || itemType !== newItemType) {
|
|
59
|
-
|
|
52
|
+
this.recycleKey(key);
|
|
60
53
|
}
|
|
61
54
|
});
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
if (this.hasOptimizedKey(getStableId(index))) {
|
|
67
|
-
this.syncItem(index, getItemType(index), getStableId(index));
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
72
|
-
finally {
|
|
73
|
-
try {
|
|
74
|
-
if (engagedIndices_1_1 && !engagedIndices_1_1.done && (_a = engagedIndices_1.return)) _a.call(engagedIndices_1);
|
|
75
|
-
}
|
|
76
|
-
finally { if (e_1) throw e_1.error; }
|
|
77
|
-
}
|
|
78
|
-
try {
|
|
79
|
-
// Second pass: process remaining items that need new keys
|
|
80
|
-
for (var engagedIndices_2 = tslib_1.__values(engagedIndices), engagedIndices_2_1 = engagedIndices_2.next(); !engagedIndices_2_1.done; engagedIndices_2_1 = engagedIndices_2.next()) {
|
|
81
|
-
var index = engagedIndices_2_1.value;
|
|
82
|
-
if (!this.hasOptimizedKey(getStableId(index))) {
|
|
83
|
-
this.syncItem(index, getItemType(index), getStableId(index));
|
|
84
|
-
}
|
|
55
|
+
// First pass: process items that already have optimized keys
|
|
56
|
+
for (const index of engagedIndices) {
|
|
57
|
+
if (this.hasOptimizedKey(getStableId(index))) {
|
|
58
|
+
this.syncItem(index, getItemType(index), getStableId(index));
|
|
85
59
|
}
|
|
86
60
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
61
|
+
// Second pass: process remaining items that need new keys
|
|
62
|
+
for (const index of engagedIndices) {
|
|
63
|
+
if (!this.hasOptimizedKey(getStableId(index))) {
|
|
64
|
+
this.syncItem(index, getItemType(index), getStableId(index));
|
|
91
65
|
}
|
|
92
|
-
finally { if (e_2) throw e_2.error; }
|
|
93
66
|
}
|
|
94
67
|
// create indices that are not in the engagedIndices and less than dataLength
|
|
95
68
|
// select only indices that are not in the engagedIndices
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (index < dataLength && !engagedIndices.includes(index)) {
|
|
102
|
-
validIndicesInPool.push(index);
|
|
103
|
-
}
|
|
69
|
+
const validIndicesInPool = [];
|
|
70
|
+
for (const keyInfo of this.keyMap.values()) {
|
|
71
|
+
const index = keyInfo.index;
|
|
72
|
+
if (index < dataLength && !engagedIndices.includes(index)) {
|
|
73
|
+
validIndicesInPool.push(index);
|
|
104
74
|
}
|
|
105
75
|
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
}
|
|
111
|
-
finally { if (e_3) throw e_3.error; }
|
|
112
|
-
}
|
|
113
|
-
try {
|
|
114
|
-
// First pass: process items that already have optimized keys
|
|
115
|
-
for (var validIndicesInPool_1 = tslib_1.__values(validIndicesInPool), validIndicesInPool_1_1 = validIndicesInPool_1.next(); !validIndicesInPool_1_1.done; validIndicesInPool_1_1 = validIndicesInPool_1.next()) {
|
|
116
|
-
var index = validIndicesInPool_1_1.value;
|
|
117
|
-
if (this.hasOptimizedKey(getStableId(index))) {
|
|
118
|
-
this.syncItem(index, getItemType(index), getStableId(index));
|
|
119
|
-
}
|
|
76
|
+
// First pass: process items that already have optimized keys
|
|
77
|
+
for (const index of validIndicesInPool) {
|
|
78
|
+
if (this.hasOptimizedKey(getStableId(index))) {
|
|
79
|
+
this.syncItem(index, getItemType(index), getStableId(index));
|
|
120
80
|
}
|
|
121
81
|
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
if (validIndicesInPool_1_1 && !validIndicesInPool_1_1.done && (_d = validIndicesInPool_1.return)) _d.call(validIndicesInPool_1);
|
|
82
|
+
for (const index of validIndicesInPool) {
|
|
83
|
+
if (!this.hasOptimizedKey(getStableId(index))) {
|
|
84
|
+
this.syncItem(index, getItemType(index), getStableId(index));
|
|
126
85
|
}
|
|
127
|
-
finally { if (e_4) throw e_4.error; }
|
|
128
|
-
}
|
|
129
|
-
try {
|
|
130
|
-
for (var validIndicesInPool_2 = tslib_1.__values(validIndicesInPool), validIndicesInPool_2_1 = validIndicesInPool_2.next(); !validIndicesInPool_2_1.done; validIndicesInPool_2_1 = validIndicesInPool_2.next()) {
|
|
131
|
-
var index = validIndicesInPool_2_1.value;
|
|
132
|
-
if (!this.hasOptimizedKey(getStableId(index))) {
|
|
133
|
-
this.syncItem(index, getItemType(index), getStableId(index));
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
138
|
-
finally {
|
|
139
|
-
try {
|
|
140
|
-
if (validIndicesInPool_2_1 && !validIndicesInPool_2_1.done && (_e = validIndicesInPool_2.return)) _e.call(validIndicesInPool_2);
|
|
141
|
-
}
|
|
142
|
-
finally { if (e_5) throw e_5.error; }
|
|
143
86
|
}
|
|
144
87
|
// Clean up stale items and manage the recycle pool size
|
|
145
88
|
this.cleanup(getStableId, getItemType, engagedIndices, dataLength);
|
|
146
|
-
}
|
|
89
|
+
}
|
|
147
90
|
/**
|
|
148
91
|
* Checks if a stable ID already has an assigned key
|
|
149
92
|
*/
|
|
150
|
-
|
|
93
|
+
hasOptimizedKey(stableId) {
|
|
151
94
|
return this.stableIdMap.has(stableId);
|
|
152
|
-
}
|
|
95
|
+
}
|
|
153
96
|
/**
|
|
154
97
|
* Cleans up stale keys and manages the recycle pool size.
|
|
155
98
|
* This ensures we don't maintain references to items that are no longer in the dataset,
|
|
156
99
|
* and limits the number of recycled items to avoid excessive memory usage.
|
|
157
100
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
if (
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
if (
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
if (itemType === nextItemType) {
|
|
175
|
-
this.syncItem(nextIndex, nextItemType, nextStableId);
|
|
176
|
-
shouldDeleteKey = false;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
if (shouldDeleteKey) {
|
|
180
|
-
this.deleteKeyFromRecyclePool(itemType, key);
|
|
181
|
-
this.stableIdMap.delete(stableId);
|
|
182
|
-
itemsToDelete.push(key);
|
|
101
|
+
cleanup(getStableId, getItemType, engagedIndices, dataLength) {
|
|
102
|
+
const itemsToDelete = new Array();
|
|
103
|
+
// Remove items that are no longer in the dataset
|
|
104
|
+
for (const [key, keyInfo] of this.keyMap.entries()) {
|
|
105
|
+
const { index, itemType, stableId } = keyInfo;
|
|
106
|
+
const indexOutOfBounds = index >= dataLength;
|
|
107
|
+
const hasStableIdChanged = !indexOutOfBounds && getStableId(index) !== stableId;
|
|
108
|
+
if (indexOutOfBounds || hasStableIdChanged) {
|
|
109
|
+
const nextIndex = this.unProcessedIndices.values().next().value;
|
|
110
|
+
let shouldDeleteKey = true;
|
|
111
|
+
if (nextIndex !== undefined) {
|
|
112
|
+
const nextItemType = getItemType(nextIndex);
|
|
113
|
+
const nextStableId = getStableId(nextIndex);
|
|
114
|
+
if (itemType === nextItemType) {
|
|
115
|
+
this.syncItem(nextIndex, nextItemType, nextStableId);
|
|
116
|
+
shouldDeleteKey = false;
|
|
183
117
|
}
|
|
184
118
|
}
|
|
119
|
+
if (shouldDeleteKey) {
|
|
120
|
+
this.deleteKeyFromRecyclePool(itemType, key);
|
|
121
|
+
this.stableIdMap.delete(stableId);
|
|
122
|
+
itemsToDelete.push(key);
|
|
123
|
+
}
|
|
185
124
|
}
|
|
186
125
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
try {
|
|
190
|
-
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
191
|
-
}
|
|
192
|
-
finally { if (e_6) throw e_6.error; }
|
|
193
|
-
}
|
|
194
|
-
try {
|
|
195
|
-
for (var itemsToDelete_1 = tslib_1.__values(itemsToDelete), itemsToDelete_1_1 = itemsToDelete_1.next(); !itemsToDelete_1_1.done; itemsToDelete_1_1 = itemsToDelete_1.next()) {
|
|
196
|
-
var key = itemsToDelete_1_1.value;
|
|
197
|
-
this.keyMap.delete(key);
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
catch (e_7_1) { e_7 = { error: e_7_1 }; }
|
|
201
|
-
finally {
|
|
202
|
-
try {
|
|
203
|
-
if (itemsToDelete_1_1 && !itemsToDelete_1_1.done && (_b = itemsToDelete_1.return)) _b.call(itemsToDelete_1);
|
|
204
|
-
}
|
|
205
|
-
finally { if (e_7) throw e_7.error; }
|
|
126
|
+
for (const key of itemsToDelete) {
|
|
127
|
+
this.keyMap.delete(key);
|
|
206
128
|
}
|
|
207
129
|
// Limit the size of the recycle pool
|
|
208
|
-
|
|
130
|
+
const itemsRenderedForRecycling = this.keyMap.size - engagedIndices.length;
|
|
209
131
|
if (itemsRenderedForRecycling > this.maxItemsInRecyclePool) {
|
|
210
|
-
|
|
211
|
-
|
|
132
|
+
const deleteCount = itemsRenderedForRecycling - this.maxItemsInRecyclePool;
|
|
133
|
+
let deleted = 0;
|
|
212
134
|
// Use a for loop so we can break early once we've deleted enough items
|
|
213
|
-
|
|
214
|
-
for (
|
|
215
|
-
|
|
216
|
-
|
|
135
|
+
const entries = Array.from(this.keyMap.entries()).reverse();
|
|
136
|
+
for (let i = 0; i < entries.length && deleted < deleteCount; i++) {
|
|
137
|
+
const [key, keyInfo] = entries[i];
|
|
138
|
+
const { index, itemType, stableId } = keyInfo;
|
|
217
139
|
if (!engagedIndices.includes(index)) {
|
|
218
140
|
this.deleteKeyFromRecyclePool(itemType, key);
|
|
219
141
|
this.stableIdMap.delete(stableId);
|
|
@@ -222,42 +144,42 @@ var RenderStackManager = /** @class */ (function () {
|
|
|
222
144
|
}
|
|
223
145
|
}
|
|
224
146
|
}
|
|
225
|
-
}
|
|
147
|
+
}
|
|
226
148
|
/**
|
|
227
149
|
* Places a key back into its type-specific recycle pool for future reuse
|
|
228
150
|
*/
|
|
229
|
-
|
|
151
|
+
recycleKey(key) {
|
|
230
152
|
if (this.disableRecycling) {
|
|
231
153
|
return;
|
|
232
154
|
}
|
|
233
|
-
|
|
155
|
+
const keyInfo = this.keyMap.get(key);
|
|
234
156
|
if (!keyInfo) {
|
|
235
157
|
return;
|
|
236
158
|
}
|
|
237
|
-
|
|
159
|
+
const { itemType } = keyInfo;
|
|
238
160
|
// Add key back to its type's pool
|
|
239
|
-
|
|
161
|
+
const pool = this.getRecyclePoolForType(itemType);
|
|
240
162
|
pool.add(key);
|
|
241
|
-
}
|
|
163
|
+
}
|
|
242
164
|
/**
|
|
243
165
|
* Returns the current render stack containing all active keys and their metadata
|
|
244
166
|
*/
|
|
245
|
-
|
|
167
|
+
getRenderStack() {
|
|
246
168
|
return this.keyMap;
|
|
247
|
-
}
|
|
169
|
+
}
|
|
248
170
|
/**
|
|
249
171
|
* Syncs an individual item by assigning it an appropriate key.
|
|
250
172
|
* Will use an existing key if available, or generate a new one.
|
|
251
173
|
*
|
|
252
174
|
* @returns The key assigned to the item
|
|
253
175
|
*/
|
|
254
|
-
|
|
176
|
+
syncItem(index, itemType, stableId) {
|
|
255
177
|
// Try to reuse an existing key, or get one from the recycle pool, or generate a new one
|
|
256
|
-
|
|
178
|
+
const newKey = this.stableIdMap.get(stableId) ||
|
|
257
179
|
this.getKeyFromRecyclePool(itemType) ||
|
|
258
180
|
this.generateKey();
|
|
259
181
|
this.unProcessedIndices.delete(index);
|
|
260
|
-
|
|
182
|
+
const keyInfo = this.keyMap.get(newKey);
|
|
261
183
|
if (keyInfo) {
|
|
262
184
|
// Update an existing key's metadata
|
|
263
185
|
this.deleteKeyFromRecyclePool(itemType, newKey);
|
|
@@ -270,74 +192,61 @@ var RenderStackManager = /** @class */ (function () {
|
|
|
270
192
|
else {
|
|
271
193
|
// Create a new entry in the key map
|
|
272
194
|
this.keyMap.set(newKey, {
|
|
273
|
-
itemType
|
|
274
|
-
index
|
|
275
|
-
stableId
|
|
195
|
+
itemType,
|
|
196
|
+
index,
|
|
197
|
+
stableId,
|
|
276
198
|
});
|
|
277
199
|
}
|
|
278
200
|
this.stableIdMap.set(stableId, newKey);
|
|
279
201
|
return newKey;
|
|
280
|
-
}
|
|
202
|
+
}
|
|
281
203
|
/**
|
|
282
204
|
* Clears all recycled keys from the pool, effectively resetting the recycling system.
|
|
283
205
|
* This operation does not affect currently active keys.
|
|
284
206
|
*/
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
for (var _b = tslib_1.__values(this.recycleKeyPools.values()), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
290
|
-
var pool = _c.value;
|
|
291
|
-
pool.clear();
|
|
292
|
-
}
|
|
207
|
+
clearRecyclePool() {
|
|
208
|
+
// iterate over all pools and clear them
|
|
209
|
+
for (const pool of this.recycleKeyPools.values()) {
|
|
210
|
+
pool.clear();
|
|
293
211
|
}
|
|
294
|
-
|
|
295
|
-
finally {
|
|
296
|
-
try {
|
|
297
|
-
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
298
|
-
}
|
|
299
|
-
finally { if (e_8) throw e_8.error; }
|
|
300
|
-
}
|
|
301
|
-
};
|
|
212
|
+
}
|
|
302
213
|
/**
|
|
303
214
|
* Generates a unique sequential key using an internal counter.
|
|
304
215
|
* @returns A unique key as a string
|
|
305
216
|
*/
|
|
306
|
-
|
|
217
|
+
generateKey() {
|
|
307
218
|
return (this.keyCounter++).toString();
|
|
308
|
-
}
|
|
219
|
+
}
|
|
309
220
|
/**
|
|
310
221
|
* Removes a specific key from its type's recycle pool
|
|
311
222
|
*/
|
|
312
|
-
|
|
223
|
+
deleteKeyFromRecyclePool(itemType, key) {
|
|
313
224
|
var _a;
|
|
314
225
|
(_a = this.recycleKeyPools.get(itemType)) === null || _a === void 0 ? void 0 : _a.delete(key);
|
|
315
|
-
}
|
|
226
|
+
}
|
|
316
227
|
/**
|
|
317
228
|
* Gets or creates a recycle pool for a specific item type
|
|
318
229
|
*/
|
|
319
|
-
|
|
320
|
-
|
|
230
|
+
getRecyclePoolForType(itemType) {
|
|
231
|
+
let pool = this.recycleKeyPools.get(itemType);
|
|
321
232
|
if (!pool) {
|
|
322
233
|
pool = new Set();
|
|
323
234
|
this.recycleKeyPools.set(itemType, pool);
|
|
324
235
|
}
|
|
325
236
|
return pool;
|
|
326
|
-
}
|
|
237
|
+
}
|
|
327
238
|
/**
|
|
328
239
|
* Retrieves and removes a key from the type's recycle pool
|
|
329
240
|
* @returns A recycled key or undefined if none available
|
|
330
241
|
*/
|
|
331
|
-
|
|
332
|
-
|
|
242
|
+
getKeyFromRecyclePool(itemType) {
|
|
243
|
+
const pool = this.getRecyclePoolForType(itemType);
|
|
333
244
|
if (pool.size > 0) {
|
|
334
|
-
|
|
245
|
+
const key = pool.values().next().value;
|
|
335
246
|
pool.delete(key);
|
|
336
247
|
return key;
|
|
337
248
|
}
|
|
338
249
|
return undefined;
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
}());
|
|
342
|
-
exports.RenderStackManager = RenderStackManager;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
343
252
|
//# sourceMappingURL=RenderStackManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RenderStackManager.js","sourceRoot":"","sources":["../../src/recyclerview/RenderStackManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RenderStackManager.js","sourceRoot":"","sources":["../../src/recyclerview/RenderStackManager.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,MAAM,OAAO,kBAAkB;IAuB7B;;OAEG;IACH,YAAY,wBAAgC,MAAM,CAAC,gBAAgB;QAzB5D,qBAAgB,GAAG,KAAK,CAAC;QA0B9B,IAAI,CAAC,qBAAqB,GAAG,qBAAqB,CAAC;QACnD,IAAI,CAAC,eAAe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AC,CAAC;QAC9C,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,IAAI,GAAG,IAAI,GAAG,EAAE,CAAC;YACjB,IAAI,CAAC,eAAe,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;OAGG;IACK,qBAAqB,CAAC,QAAgB;QAC5C,MAAM,IAAI,GAAG,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;QAClD,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC;YAClB,MAAM,GAAG,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjB,OAAO,GAAG,CAAC;QACb,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -1,45 +1,41 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
/**
|
|
3
2
|
* ViewHolder is a core component in FlashList that manages individual item rendering and layout.
|
|
4
3
|
* It handles the rendering of list items, separators, and manages layout updates for each item.
|
|
5
4
|
* The component is memoized to prevent unnecessary re-renders and includes layout comparison logic.
|
|
6
5
|
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var tslib_1 = require("tslib");
|
|
10
|
-
var react_1 = tslib_1.__importStar(require("react"));
|
|
11
|
-
var CompatView_1 = require("./components/CompatView");
|
|
6
|
+
import React, { useCallback, useLayoutEffect, useMemo, useRef, } from "react";
|
|
7
|
+
import { CompatView } from "./components/CompatView";
|
|
12
8
|
/**
|
|
13
9
|
* Internal ViewHolder component that handles the actual rendering of list items
|
|
14
10
|
* @template TItem - The type of item being rendered in the list
|
|
15
11
|
*/
|
|
16
|
-
|
|
12
|
+
const ViewHolderInternal = (props) => {
|
|
17
13
|
// create ref for View
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
14
|
+
const viewRef = useRef(null);
|
|
15
|
+
const { index, refHolder, layout, onSizeChanged, renderItem, extraData, item, target, CellRendererComponent, ItemSeparatorComponent, trailingItem, horizontal, } = props;
|
|
16
|
+
useLayoutEffect(() => {
|
|
21
17
|
refHolder.set(index, viewRef);
|
|
22
|
-
return
|
|
18
|
+
return () => {
|
|
23
19
|
if (refHolder.get(index) === viewRef) {
|
|
24
20
|
refHolder.delete(index);
|
|
25
21
|
}
|
|
26
22
|
};
|
|
27
23
|
}, [index, refHolder]);
|
|
28
|
-
|
|
24
|
+
const onLayout = useCallback((event) => {
|
|
29
25
|
onSizeChanged === null || onSizeChanged === void 0 ? void 0 : onSizeChanged(index, event.nativeEvent.layout);
|
|
30
26
|
}, [index, onSizeChanged]);
|
|
31
|
-
|
|
32
|
-
return ItemSeparatorComponent && trailingItem !== undefined ? (
|
|
27
|
+
const separator = useMemo(() => {
|
|
28
|
+
return ItemSeparatorComponent && trailingItem !== undefined ? (React.createElement(ItemSeparatorComponent, { leadingItem: item, trailingItem: trailingItem })) : null;
|
|
33
29
|
}, [ItemSeparatorComponent, item, trailingItem]);
|
|
34
30
|
// console.log("ViewHolder re-render", index);
|
|
35
|
-
|
|
31
|
+
const children = useMemo(() => {
|
|
36
32
|
var _a;
|
|
37
|
-
return (_a = renderItem === null || renderItem === void 0 ? void 0 : renderItem({ item
|
|
33
|
+
return (_a = renderItem === null || renderItem === void 0 ? void 0 : renderItem({ item, index, extraData, target })) !== null && _a !== void 0 ? _a : null;
|
|
38
34
|
// TODO: Test more thoroughly
|
|
39
35
|
// We don't really to re-render the children when the index changes
|
|
40
36
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
41
37
|
}, [item, extraData, target, renderItem]);
|
|
42
|
-
|
|
38
|
+
const style = {
|
|
43
39
|
flexDirection: horizontal ? "row" : "column",
|
|
44
40
|
position: target === "StickyHeader" ? "relative" : "absolute",
|
|
45
41
|
width: layout.enforcedWidth ? layout.width : undefined,
|
|
@@ -52,8 +48,8 @@ var ViewHolderInternal = function (props) {
|
|
|
52
48
|
top: layout.y,
|
|
53
49
|
};
|
|
54
50
|
// TODO: Fix this type issue
|
|
55
|
-
|
|
56
|
-
return (
|
|
51
|
+
const CompatContainer = (CellRendererComponent !== null && CellRendererComponent !== void 0 ? CellRendererComponent : CompatView);
|
|
52
|
+
return (React.createElement(CompatContainer, { ref: viewRef, onLayout: onLayout, style: style, index: index },
|
|
57
53
|
children,
|
|
58
54
|
separator));
|
|
59
55
|
};
|
|
@@ -61,7 +57,7 @@ var ViewHolderInternal = function (props) {
|
|
|
61
57
|
* Memoized ViewHolder component that prevents unnecessary re-renders by comparing props
|
|
62
58
|
* @template TItem - The type of item being rendered in the list
|
|
63
59
|
*/
|
|
64
|
-
|
|
60
|
+
export const ViewHolder = React.memo(ViewHolderInternal, (prevProps, nextProps) => {
|
|
65
61
|
// compare all props and spread layout
|
|
66
62
|
return (prevProps.index === nextProps.index &&
|
|
67
63
|
areLayoutsEqual(prevProps.layout, nextProps.layout) &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ViewHolder.js","sourceRoot":"","sources":["../../src/recyclerview/ViewHolder.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ViewHolder.js","sourceRoot":"","sources":["../../src/recyclerview/ViewHolder.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,EAEZ,WAAW,EACX,eAAe,EACf,OAAO,EACP,MAAM,GACP,MAAM,OAAO,CAAC;AAKf,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAiCrD;;;GAGG;AACH,MAAM,kBAAkB,GAAG,CAAS,KAA6B,EAAE,EAAE;IACnE,sBAAsB;IACtB,MAAM,OAAO,GAAG,MAAM,CAAa,IAAI,CAAC,CAAC;IACzC,MAAM,EACJ,KAAK,EACL,SAAS,EACT,MAAM,EACN,aAAa,EACb,UAAU,EACV,SAAS,EACT,IAAI,EACJ,MAAM,E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