react-native-nitro-list 0.1.1 → 0.1.2
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/ios/HybridNitroList.swift +10 -14
- package/lib/commonjs/cell/CellKeyGenerator.js +21 -0
- package/lib/commonjs/cell/CellKeyGenerator.js.map +1 -0
- package/lib/commonjs/cell/CellRecycler.js +48 -40
- package/lib/commonjs/cell/CellRecycler.js.map +1 -1
- package/lib/commonjs/cell/createCell.js +21 -0
- package/lib/commonjs/cell/createCell.js.map +1 -0
- package/lib/commonjs/cell/index.js +20 -0
- package/lib/commonjs/cell/index.js.map +1 -0
- package/lib/commonjs/getVisibleIndices.js.map +1 -1
- package/lib/commonjs/hooks/usePersistentCallback.js +36 -0
- package/lib/commonjs/hooks/usePersistentCallback.js.map +1 -0
- package/lib/commonjs/index.js +1 -1
- package/lib/commonjs/layout/MutableLinearLayout.js +78 -39
- package/lib/commonjs/layout/MutableLinearLayout.js.map +1 -1
- package/lib/commonjs/layout/constants/layoutDefaults.js +19 -0
- package/lib/commonjs/layout/constants/layoutDefaults.js.map +1 -0
- package/lib/commonjs/layout/index.js +0 -18
- package/lib/commonjs/layout/index.js.map +1 -1
- package/lib/commonjs/recycler/CellPool.js +46 -0
- package/lib/commonjs/recycler/CellPool.js.map +1 -0
- package/lib/commonjs/recycler/RecyclerList.js +224 -0
- package/lib/commonjs/recycler/RecyclerList.js.map +1 -0
- package/lib/commonjs/types/Axis.js +2 -0
- package/lib/commonjs/{layout/LayoutProvider.js.map → types/Axis.js.map} +1 -1
- package/lib/commonjs/types/CellKey.js +2 -0
- package/lib/{module/layout/LayoutProvider.js.map → commonjs/types/CellKey.js.map} +1 -1
- package/lib/commonjs/types/CellType.js +2 -0
- package/lib/commonjs/{layout/LayoutRectangle.js.map → types/CellType.js.map} +1 -1
- package/lib/commonjs/types/VisibleRange.js +2 -0
- package/lib/{module/layout/LayoutRectangle.js.map → commonjs/types/VisibleRange.js.map} +1 -1
- package/lib/commonjs/{RecyclerList.types.js → types/VisibleRangeInput.js} +1 -1
- package/lib/commonjs/types/VisibleRangeInput.js.map +1 -0
- package/lib/commonjs/types/index.js +13 -0
- package/lib/commonjs/types/index.js.map +1 -0
- package/lib/commonjs/types/layout/LayoutRect.js +2 -0
- package/lib/commonjs/types/layout/LayoutRect.js.map +1 -0
- package/lib/commonjs/types/layout/LinearLayoutInput.js +6 -0
- package/lib/commonjs/types/layout/LinearLayoutInput.js.map +1 -0
- package/lib/commonjs/types/layout/MainAxisPadding.js +26 -0
- package/lib/commonjs/types/layout/MainAxisPadding.js.map +1 -0
- package/lib/commonjs/types/layout/index.js +2 -0
- package/lib/commonjs/types/layout/index.js.map +1 -0
- package/lib/commonjs/types/recycler/RecyclerCellInstance.js +6 -0
- package/lib/commonjs/types/recycler/RecyclerCellInstance.js.map +1 -0
- package/lib/commonjs/types/recycler/RecyclerItemRenderer.js +6 -0
- package/lib/commonjs/types/recycler/RecyclerItemRenderer.js.map +1 -0
- package/lib/commonjs/types/recycler/RecyclerListProps.js +6 -0
- package/lib/commonjs/types/recycler/RecyclerListProps.js.map +1 -0
- package/lib/commonjs/types/recycler/index.js +2 -0
- package/lib/commonjs/types/recycler/index.js.map +1 -0
- package/lib/commonjs/{layout/LayoutProvider.js → types/scroll/ScrollMetrics.js} +1 -1
- package/lib/commonjs/types/scroll/ScrollMetrics.js.map +1 -0
- package/lib/commonjs/types/scroll/index.js +2 -0
- package/lib/commonjs/types/scroll/index.js.map +1 -0
- package/lib/commonjs/windowing/computeVisibleItemRange.js +71 -0
- package/lib/commonjs/windowing/computeVisibleItemRange.js.map +1 -0
- package/lib/commonjs/windowing/index.js +3 -3
- package/lib/commonjs/windowing/index.js.map +1 -1
- package/lib/module/cell/CellKeyGenerator.js +16 -0
- package/lib/module/cell/CellKeyGenerator.js.map +1 -0
- package/lib/module/cell/CellRecycler.js +48 -39
- package/lib/module/cell/CellRecycler.js.map +1 -1
- package/lib/module/cell/createCell.js +17 -0
- package/lib/module/cell/createCell.js.map +1 -0
- package/lib/module/cell/index.js +7 -0
- package/lib/module/cell/index.js.map +1 -0
- package/lib/module/getVisibleIndices.js.map +1 -1
- package/lib/module/hooks/usePersistentCallback.js +33 -0
- package/lib/module/hooks/usePersistentCallback.js.map +1 -0
- package/lib/module/index.js +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/layout/MutableLinearLayout.js +78 -38
- package/lib/module/layout/MutableLinearLayout.js.map +1 -1
- package/lib/module/layout/constants/layoutDefaults.js +15 -0
- package/lib/module/layout/constants/layoutDefaults.js.map +1 -0
- package/lib/module/layout/index.js +0 -3
- package/lib/module/layout/index.js.map +1 -1
- package/lib/module/recycler/CellPool.js +41 -0
- package/lib/module/recycler/CellPool.js.map +1 -0
- package/lib/module/recycler/RecyclerList.js +221 -0
- package/lib/module/recycler/RecyclerList.js.map +1 -0
- package/lib/module/types/Axis.js +2 -0
- package/lib/module/types/Axis.js.map +1 -0
- package/lib/module/types/CellKey.js +2 -0
- package/lib/module/types/CellKey.js.map +1 -0
- package/lib/module/types/CellType.js +2 -0
- package/lib/module/types/CellType.js.map +1 -0
- package/lib/module/types/VisibleRange.js +2 -0
- package/lib/module/types/VisibleRange.js.map +1 -0
- package/lib/module/types/VisibleRangeInput.js +4 -0
- package/lib/module/types/VisibleRangeInput.js.map +1 -0
- package/lib/module/types/index.js +4 -0
- package/lib/module/types/index.js.map +1 -0
- package/lib/module/types/layout/LayoutRect.js +2 -0
- package/lib/module/types/layout/LayoutRect.js.map +1 -0
- package/lib/module/types/layout/LinearLayoutInput.js +4 -0
- package/lib/module/types/layout/LinearLayoutInput.js.map +1 -0
- package/lib/module/types/layout/MainAxisPadding.js +22 -0
- package/lib/module/types/layout/MainAxisPadding.js.map +1 -0
- package/lib/module/types/layout/index.js +2 -0
- package/lib/module/types/layout/index.js.map +1 -0
- package/lib/module/types/recycler/RecyclerCellInstance.js +4 -0
- package/lib/module/types/recycler/RecyclerCellInstance.js.map +1 -0
- package/lib/module/types/recycler/RecyclerItemRenderer.js +4 -0
- package/lib/module/types/recycler/RecyclerItemRenderer.js.map +1 -0
- package/lib/module/types/recycler/RecyclerListProps.js +4 -0
- package/lib/module/types/recycler/RecyclerListProps.js.map +1 -0
- package/lib/module/types/recycler/index.js +2 -0
- package/lib/module/types/recycler/index.js.map +1 -0
- package/lib/module/types/scroll/ScrollMetrics.js +4 -0
- package/lib/module/types/scroll/ScrollMetrics.js.map +1 -0
- package/lib/module/types/scroll/index.js +2 -0
- package/lib/module/types/scroll/index.js.map +1 -0
- package/lib/module/windowing/computeVisibleItemRange.js +67 -0
- package/lib/module/windowing/computeVisibleItemRange.js.map +1 -0
- package/lib/module/windowing/index.js +1 -1
- package/lib/module/windowing/index.js.map +1 -1
- package/lib/typescript/src/cell/Cell.d.ts +13 -4
- package/lib/typescript/src/cell/Cell.d.ts.map +1 -1
- package/lib/typescript/src/cell/CellKeyGenerator.d.ts +11 -0
- package/lib/typescript/src/cell/CellKeyGenerator.d.ts.map +1 -0
- package/lib/typescript/src/cell/CellRecycler.d.ts +19 -11
- package/lib/typescript/src/cell/CellRecycler.d.ts.map +1 -1
- package/lib/typescript/src/cell/createCell.d.ts +7 -0
- package/lib/typescript/src/cell/createCell.d.ts.map +1 -0
- package/lib/typescript/src/cell/index.d.ts +4 -0
- package/lib/typescript/src/cell/index.d.ts.map +1 -0
- package/lib/typescript/src/getVisibleIndices.d.ts +2 -2
- package/lib/typescript/src/getVisibleIndices.d.ts.map +1 -1
- package/lib/typescript/src/hooks/usePersistentCallback.d.ts +16 -0
- package/lib/typescript/src/hooks/usePersistentCallback.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +1 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/layout/MutableLinearLayout.d.ts +45 -13
- package/lib/typescript/src/layout/MutableLinearLayout.d.ts.map +1 -1
- package/lib/typescript/src/layout/constants/layoutDefaults.d.ts +13 -0
- package/lib/typescript/src/layout/constants/layoutDefaults.d.ts.map +1 -0
- package/lib/typescript/src/layout/index.d.ts +1 -4
- package/lib/typescript/src/layout/index.d.ts.map +1 -1
- package/lib/typescript/src/native/NitroList.types.d.ts +2 -2
- package/lib/typescript/src/native/NitroList.types.d.ts.map +1 -1
- package/lib/typescript/src/recycler/CellPool.d.ts +14 -0
- package/lib/typescript/src/recycler/CellPool.d.ts.map +1 -0
- package/lib/typescript/src/recycler/RecyclerList.d.ts +4 -0
- package/lib/typescript/src/recycler/RecyclerList.d.ts.map +1 -0
- package/lib/typescript/src/specs/nitro-layout-engine.nitro.d.ts +2 -2
- package/lib/typescript/src/specs/nitro-layout-engine.nitro.d.ts.map +1 -1
- package/lib/typescript/src/types/Axis.d.ts +11 -0
- package/lib/typescript/src/types/Axis.d.ts.map +1 -0
- package/lib/typescript/src/types/CellKey.d.ts +10 -0
- package/lib/typescript/src/types/CellKey.d.ts.map +1 -0
- package/lib/typescript/src/types/CellType.d.ts +11 -0
- package/lib/typescript/src/types/CellType.d.ts.map +1 -0
- package/lib/typescript/src/types/VisibleRange.d.ts +10 -0
- package/lib/typescript/src/types/VisibleRange.d.ts.map +1 -0
- package/lib/typescript/src/types/VisibleRangeInput.d.ts +35 -0
- package/lib/typescript/src/types/VisibleRangeInput.d.ts.map +1 -0
- package/lib/typescript/src/types/index.d.ts +8 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -0
- package/lib/typescript/src/types/layout/LayoutRect.d.ts +15 -0
- package/lib/typescript/src/types/layout/LayoutRect.d.ts.map +1 -0
- package/lib/typescript/src/types/layout/LinearLayoutInput.d.ts +10 -0
- package/lib/typescript/src/types/layout/LinearLayoutInput.d.ts.map +1 -0
- package/lib/typescript/src/types/layout/MainAxisPadding.d.ts +20 -0
- package/lib/typescript/src/types/layout/MainAxisPadding.d.ts.map +1 -0
- package/lib/typescript/src/types/layout/index.d.ts +4 -0
- package/lib/typescript/src/types/layout/index.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/RecyclerCellInstance.d.ts +37 -0
- package/lib/typescript/src/types/recycler/RecyclerCellInstance.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/RecyclerItemRenderer.d.ts +8 -0
- package/lib/typescript/src/types/recycler/RecyclerItemRenderer.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/RecyclerListProps.d.ts +66 -0
- package/lib/typescript/src/types/recycler/RecyclerListProps.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/index.d.ts +4 -0
- package/lib/typescript/src/types/recycler/index.d.ts.map +1 -0
- package/lib/typescript/src/types/scroll/ScrollMetrics.d.ts +15 -0
- package/lib/typescript/src/types/scroll/ScrollMetrics.d.ts.map +1 -0
- package/lib/typescript/src/types/scroll/index.d.ts +2 -0
- package/lib/typescript/src/types/scroll/index.d.ts.map +1 -0
- package/lib/typescript/src/windowing/computeVisibleItemRange.d.ts +15 -0
- package/lib/typescript/src/windowing/computeVisibleItemRange.d.ts.map +1 -0
- package/lib/typescript/src/windowing/index.d.ts +1 -1
- package/lib/typescript/src/windowing/index.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridNitroLayoutEngineSpec.cpp +7 -7
- package/nitrogen/generated/android/c++/JHybridNitroLayoutEngineSpec.hpp +1 -1
- package/nitrogen/generated/android/c++/{JLayoutRectangle.hpp → JLayoutRect.hpp} +10 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/HybridNitroLayoutEngineSpec.kt +1 -1
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/{LayoutRectangle.kt → LayoutRect.kt} +5 -5
- package/nitrogen/generated/ios/NitroList-Swift-Cxx-Bridge.hpp +14 -14
- package/nitrogen/generated/ios/NitroList-Swift-Cxx-Umbrella.hpp +3 -3
- package/nitrogen/generated/ios/c++/HybridNitroLayoutEngineSpecSwift.hpp +4 -4
- package/nitrogen/generated/ios/swift/HybridNitroLayoutEngineSpec.swift +1 -1
- package/nitrogen/generated/ios/swift/HybridNitroLayoutEngineSpec_cxx.swift +5 -5
- package/nitrogen/generated/ios/swift/{LayoutRectangle.swift → LayoutRect.swift} +5 -5
- package/nitrogen/generated/shared/c++/HybridNitroLayoutEngineSpec.hpp +4 -4
- package/nitrogen/generated/shared/c++/{LayoutRectangle.hpp → LayoutRect.hpp} +11 -11
- package/package.json +1 -1
- package/src/cell/Cell.ts +13 -4
- package/src/cell/CellKeyGenerator.ts +17 -0
- package/src/cell/CellRecycler.ts +53 -43
- package/src/cell/createCell.ts +15 -0
- package/src/cell/index.ts +5 -0
- package/src/getVisibleIndices.ts +4 -2
- package/src/hooks/usePersistentCallback.ts +37 -0
- package/src/index.ts +1 -2
- package/src/layout/MutableLinearLayout.ts +91 -58
- package/src/layout/constants/layoutDefaults.ts +12 -0
- package/src/layout/index.ts +1 -4
- package/src/native/NitroList.types.ts +3 -2
- package/src/recycler/CellPool.ts +47 -0
- package/src/recycler/RecyclerList.tsx +304 -0
- package/src/specs/nitro-layout-engine.nitro.ts +2 -2
- package/src/types/Axis.ts +10 -0
- package/src/types/CellKey.ts +9 -0
- package/src/types/CellType.ts +10 -0
- package/src/types/VisibleRange.ts +9 -0
- package/src/types/VisibleRangeInput.ts +39 -0
- package/src/types/index.ts +15 -0
- package/src/types/layout/LayoutRect.ts +14 -0
- package/src/types/layout/LinearLayoutInput.ts +12 -0
- package/src/types/layout/MainAxisPadding.ts +23 -0
- package/src/types/layout/index.ts +3 -0
- package/src/types/recycler/RecyclerCellInstance.ts +40 -0
- package/src/types/recycler/RecyclerItemRenderer.ts +8 -0
- package/src/types/recycler/RecyclerListProps.ts +74 -0
- package/src/types/recycler/index.ts +3 -0
- package/src/types/scroll/ScrollMetrics.ts +18 -0
- package/src/types/scroll/index.ts +1 -0
- package/src/windowing/computeVisibleItemRange.ts +78 -0
- package/src/windowing/index.ts +1 -1
- package/lib/commonjs/RecyclerList.internal.js +0 -25
- package/lib/commonjs/RecyclerList.internal.js.map +0 -1
- package/lib/commonjs/RecyclerList.js +0 -171
- package/lib/commonjs/RecyclerList.js.map +0 -1
- package/lib/commonjs/RecyclerList.types.js.map +0 -1
- package/lib/commonjs/cell/StableKey.js +0 -10
- package/lib/commonjs/cell/StableKey.js.map +0 -1
- package/lib/commonjs/hooks/useCellRenderer.js +0 -62
- package/lib/commonjs/hooks/useCellRenderer.js.map +0 -1
- package/lib/commonjs/hooks/useStableCallback.js +0 -13
- package/lib/commonjs/hooks/useStableCallback.js.map +0 -1
- package/lib/commonjs/layout/EstimatedLayoutProvider.js +0 -30
- package/lib/commonjs/layout/EstimatedLayoutProvider.js.map +0 -1
- package/lib/commonjs/layout/LayoutEngine.js +0 -21
- package/lib/commonjs/layout/LayoutEngine.js.map +0 -1
- package/lib/commonjs/layout/LayoutRectangle.js +0 -2
- package/lib/commonjs/viewability/ViewabilityHelper.js +0 -121
- package/lib/commonjs/viewability/ViewabilityHelper.js.map +0 -1
- package/lib/commonjs/windowing/findVisibleIndexRange.js +0 -48
- package/lib/commonjs/windowing/findVisibleIndexRange.js.map +0 -1
- package/lib/module/RecyclerList.internal.js +0 -22
- package/lib/module/RecyclerList.internal.js.map +0 -1
- package/lib/module/RecyclerList.js +0 -166
- package/lib/module/RecyclerList.js.map +0 -1
- package/lib/module/RecyclerList.types.js +0 -4
- package/lib/module/RecyclerList.types.js.map +0 -1
- package/lib/module/cell/StableKey.js +0 -6
- package/lib/module/cell/StableKey.js.map +0 -1
- package/lib/module/hooks/useCellRenderer.js +0 -58
- package/lib/module/hooks/useCellRenderer.js.map +0 -1
- package/lib/module/hooks/useStableCallback.js +0 -9
- package/lib/module/hooks/useStableCallback.js.map +0 -1
- package/lib/module/layout/EstimatedLayoutProvider.js +0 -25
- package/lib/module/layout/EstimatedLayoutProvider.js.map +0 -1
- package/lib/module/layout/LayoutEngine.js +0 -17
- package/lib/module/layout/LayoutEngine.js.map +0 -1
- package/lib/module/layout/LayoutProvider.js +0 -4
- package/lib/module/layout/LayoutRectangle.js +0 -2
- package/lib/module/viewability/ViewabilityHelper.js +0 -116
- package/lib/module/viewability/ViewabilityHelper.js.map +0 -1
- package/lib/module/windowing/findVisibleIndexRange.js +0 -44
- package/lib/module/windowing/findVisibleIndexRange.js.map +0 -1
- package/lib/typescript/src/RecyclerList.d.ts +0 -26
- package/lib/typescript/src/RecyclerList.d.ts.map +0 -1
- package/lib/typescript/src/RecyclerList.internal.d.ts +0 -9
- package/lib/typescript/src/RecyclerList.internal.d.ts.map +0 -1
- package/lib/typescript/src/RecyclerList.types.d.ts +0 -18
- package/lib/typescript/src/RecyclerList.types.d.ts.map +0 -1
- package/lib/typescript/src/__tests__/windowing/findVisibleIndexRange.test.d.ts +0 -2
- package/lib/typescript/src/__tests__/windowing/findVisibleIndexRange.test.d.ts.map +0 -1
- package/lib/typescript/src/cell/StableKey.d.ts +0 -2
- package/lib/typescript/src/cell/StableKey.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useCellRenderer.d.ts +0 -19
- package/lib/typescript/src/hooks/useCellRenderer.d.ts.map +0 -1
- package/lib/typescript/src/hooks/useStableCallback.d.ts +0 -2
- package/lib/typescript/src/hooks/useStableCallback.d.ts.map +0 -1
- package/lib/typescript/src/layout/EstimatedLayoutProvider.d.ts +0 -15
- package/lib/typescript/src/layout/EstimatedLayoutProvider.d.ts.map +0 -1
- package/lib/typescript/src/layout/LayoutEngine.d.ts +0 -10
- package/lib/typescript/src/layout/LayoutEngine.d.ts.map +0 -1
- package/lib/typescript/src/layout/LayoutProvider.d.ts +0 -16
- package/lib/typescript/src/layout/LayoutProvider.d.ts.map +0 -1
- package/lib/typescript/src/layout/LayoutRectangle.d.ts +0 -11
- package/lib/typescript/src/layout/LayoutRectangle.d.ts.map +0 -1
- package/lib/typescript/src/viewability/ViewabilityHelper.d.ts +0 -50
- package/lib/typescript/src/viewability/ViewabilityHelper.d.ts.map +0 -1
- package/lib/typescript/src/windowing/findVisibleIndexRange.d.ts +0 -11
- package/lib/typescript/src/windowing/findVisibleIndexRange.d.ts.map +0 -1
- package/src/RecyclerList.internal.ts +0 -38
- package/src/RecyclerList.tsx +0 -252
- package/src/RecyclerList.types.ts +0 -24
- package/src/__tests__/windowing/findVisibleIndexRange.test.ts +0 -55
- package/src/cell/StableKey.ts +0 -6
- package/src/hooks/useCellRenderer.ts +0 -86
- package/src/hooks/useStableCallback.ts +0 -13
- package/src/layout/EstimatedLayoutProvider.ts +0 -35
- package/src/layout/LayoutEngine.ts +0 -21
- package/src/layout/LayoutProvider.ts +0 -17
- package/src/layout/LayoutRectangle.ts +0 -10
- package/src/viewability/ViewabilityHelper.ts +0 -130
- package/src/windowing/findVisibleIndexRange.ts +0 -60
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.ViewabilityHelper = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Public token describing viewability state of an item.
|
|
9
|
-
* Mirrors FlashList's ViewToken concept.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Configuration for viewability calculations.
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* ViewabilityHelper
|
|
18
|
-
*
|
|
19
|
-
* Pure observer:
|
|
20
|
-
* - Does NOT affect layout
|
|
21
|
-
* - Does NOT affect recycling
|
|
22
|
-
* - Computes visibility based on layout + scroll metrics
|
|
23
|
-
*
|
|
24
|
-
* This class is intentionally stateful (lastVisible)
|
|
25
|
-
* to compute "changed" items efficiently.
|
|
26
|
-
*/
|
|
27
|
-
class ViewabilityHelper {
|
|
28
|
-
/** Previously visible indices */
|
|
29
|
-
lastVisible = new Set();
|
|
30
|
-
constructor(config = {}) {
|
|
31
|
-
this.config = config;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Computes which items are viewable and which changed
|
|
36
|
-
* since the last invocation.
|
|
37
|
-
*
|
|
38
|
-
* IMPORTANT:
|
|
39
|
-
* - This method should be called AFTER windowing,
|
|
40
|
-
* not on the full dataset.
|
|
41
|
-
*/
|
|
42
|
-
computeViewableItems(layouts, metrics) {
|
|
43
|
-
const visibleNow = new Set();
|
|
44
|
-
const viewableItems = [];
|
|
45
|
-
const changed = [];
|
|
46
|
-
const viewportTop = metrics.offsetY;
|
|
47
|
-
const viewportBottom = viewportTop + metrics.height;
|
|
48
|
-
|
|
49
|
-
// Normalize threshold into [0, 1]
|
|
50
|
-
const threshold = (this.config.itemVisiblePercentThreshold ?? 0) / 100;
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* NOTE:
|
|
54
|
-
* We intentionally iterate layouts sequentially,
|
|
55
|
-
* but EXIT EARLY when items are completely below viewport.
|
|
56
|
-
*
|
|
57
|
-
* This keeps complexity near O(visibleItems),
|
|
58
|
-
* not O(totalItems).
|
|
59
|
-
*/
|
|
60
|
-
for (let i = 0; i < layouts.length; i++) {
|
|
61
|
-
const layout = layouts[i];
|
|
62
|
-
|
|
63
|
-
// If item is completely below viewport, stop
|
|
64
|
-
if (layout.y > viewportBottom) {
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
const itemTop = layout.y;
|
|
68
|
-
const itemBottom = layout.y + layout.height;
|
|
69
|
-
|
|
70
|
-
// If item is completely above viewport, skip
|
|
71
|
-
if (itemBottom < viewportTop) {
|
|
72
|
-
continue;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
// Compute visible intersection
|
|
76
|
-
const visibleTop = Math.max(itemTop, viewportTop);
|
|
77
|
-
const visibleBottom = Math.min(itemBottom, viewportBottom);
|
|
78
|
-
const visibleHeight = Math.max(0, visibleBottom - visibleTop);
|
|
79
|
-
|
|
80
|
-
// Guard against zero-height items
|
|
81
|
-
const itemHeight = layout.height > 0 ? layout.height : 1;
|
|
82
|
-
const visibleRatio = visibleHeight / itemHeight;
|
|
83
|
-
if (visibleRatio >= threshold) {
|
|
84
|
-
visibleNow.add(i);
|
|
85
|
-
viewableItems.push({
|
|
86
|
-
index: i,
|
|
87
|
-
isViewable: true
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
// Newly visible
|
|
91
|
-
if (!this.lastVisible.has(i)) {
|
|
92
|
-
changed.push({
|
|
93
|
-
index: i,
|
|
94
|
-
isViewable: true
|
|
95
|
-
});
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* Items that were visible before but not anymore
|
|
102
|
-
*/
|
|
103
|
-
for (const index of this.lastVisible) {
|
|
104
|
-
if (!visibleNow.has(index)) {
|
|
105
|
-
changed.push({
|
|
106
|
-
index,
|
|
107
|
-
isViewable: false
|
|
108
|
-
});
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// Update snapshot
|
|
113
|
-
this.lastVisible = visibleNow;
|
|
114
|
-
return {
|
|
115
|
-
viewableItems,
|
|
116
|
-
changed
|
|
117
|
-
};
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
exports.ViewabilityHelper = ViewabilityHelper;
|
|
121
|
-
//# sourceMappingURL=ViewabilityHelper.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["ViewabilityHelper","lastVisible","Set","constructor","config","computeViewableItems","layouts","metrics","visibleNow","viewableItems","changed","viewportTop","offsetY","viewportBottom","height","threshold","itemVisiblePercentThreshold","i","length","layout","y","itemTop","itemBottom","visibleTop","Math","max","visibleBottom","min","visibleHeight","itemHeight","visibleRatio","add","push","index","isViewable","has","exports"],"sourceRoot":"../../../src","sources":["viewability/ViewabilityHelper.ts"],"mappings":";;;;;;AAGA;AACA;AACA;AACA;;AAMA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,iBAAiB,CAAC;EAC7B;EACQC,WAAW,GAAG,IAAIC,GAAG,CAAS,CAAC;EAEvCC,WAAWA,CACQC,MAAyB,GAAG,CAAC,CAAC,EA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AC;MAEvC,MAAMgB,YAAY,GAAGF,aAAa,GAAGC,UAAU;MAE/C,IAAIC,YAAY,IAAIf,SAAS,EAAE;QAC7BP,UAAU,CAACuB,GAAG,CAACd,CAAC,CAAC;QACjBR,aAAa,CAACuB,IAAI,CAAC;UAAEC,KAAK,EAAEhB,CAAC;UAAEiB,UAAU,EAAE;QAAK,CAAC,CAAC;;QAElD;QACA,IAAI,CAAC,IAAI,CAACjC,WAAW,CAACkC,GAAG,CAAClB,CAAC,CAAC,EAAE;UAC5BP,OAAO,CAACsB,IAAI,CAAC;YAAEC,KAAK,EAAEhB,CAAC;YAAEiB,UAAU,EAAE;UAAK,CAAC,CAAC;QAC9C;MACF;IACF;;IAEA;AACJ;AACA;IACI,KAAK,MAAMD,KAAK,IAAI,IAAI,CAAChC,WAAW,EAAE;MACpC,IAAI,CAACO,UAAU,CAAC2B,GAAG,CAACF,KAAK,CAAC,EAAE;QAC1BvB,OAAO,CAACsB,IAAI,CAAC;UAAEC,KAAK;UAAEC,UAAU,EAAE;QAAM,CAAC,CAAC;MAC5C;IACF;;IAEA;IACA,IAAI,CAACjC,WAAW,GAAGO,UAAU;IAE7B,OAAO;MAAEC,aAAa;MAAEC;IAAQ,CAAC;EACnC;AACF;AAAC0B,OAAA,CAAApC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.findVisibleIndexRange = findVisibleIndexRange;
|
|
7
|
-
/**
|
|
8
|
-
* Computes the contiguous range of item indices
|
|
9
|
-
* intersecting the viewport expanded by bufferPx.
|
|
10
|
-
*
|
|
11
|
-
* PURE function. No allocations besides output.
|
|
12
|
-
* FlashList-style windowing.
|
|
13
|
-
*/
|
|
14
|
-
function findVisibleIndexRange(layouts, metrics, bufferPx) {
|
|
15
|
-
const count = layouts.length;
|
|
16
|
-
|
|
17
|
-
// 🔒 CRITICAL GUARDS (FlashList-style)
|
|
18
|
-
if (count === 0 || metrics.height <= 0 || bufferPx < 0) {
|
|
19
|
-
return [];
|
|
20
|
-
}
|
|
21
|
-
const windowStart = Math.max(0, metrics.offsetY - bufferPx);
|
|
22
|
-
const windowEnd = metrics.offsetY + metrics.height + bufferPx;
|
|
23
|
-
|
|
24
|
-
// Binary search for first intersecting item
|
|
25
|
-
let low = 0;
|
|
26
|
-
let high = count - 1;
|
|
27
|
-
let firstVisible = count;
|
|
28
|
-
while (low <= high) {
|
|
29
|
-
const mid = low + high >> 1;
|
|
30
|
-
const rect = layouts[mid];
|
|
31
|
-
if (rect.y + rect.height >= windowStart) {
|
|
32
|
-
firstVisible = mid;
|
|
33
|
-
high = mid - 1;
|
|
34
|
-
} else {
|
|
35
|
-
low = mid + 1;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// Linear scan forward
|
|
40
|
-
const visible = [];
|
|
41
|
-
for (let i = firstVisible; i < count; i++) {
|
|
42
|
-
const rect = layouts[i];
|
|
43
|
-
if (rect.y > windowEnd) break;
|
|
44
|
-
visible.push(i);
|
|
45
|
-
}
|
|
46
|
-
return visible;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=findVisibleIndexRange.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["findVisibleIndexRange","layouts","metrics","bufferPx","count","length","height","windowStart","Math","max","offsetY","windowEnd","low","high","firstVisible","mid","rect","y","visible","i","push"],"sourceRoot":"../../../src","sources":["windowing/findVisibleIndexRange.ts"],"mappings":";;;;;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAqBA,CACnCC,OAAmC,EACnCC,OAAsB,EACtBC,QAAgB,EACG;EACnB,MAAMC,KAAK,GAAGH,OAAO,CAACI,MAAM;;EAE5B;EACA,IACED,KAAK,KAAK,CAAC,IACXF,OAAO,CAACI,MAAM,IAAI,CAAC,IACnBH,QAAQ,GAAG,CAAC,EACZ;IACA,OAAO,EAAE;EACX;EAEA,MAAMI,WAAW,GACfC,IAAI,CAACC,GAAG,CAAC,CAAC,EAAEP,OAAO,CAACQ,OAAO,GAAGP,QAAQ,CAAC;EAEzC,MAAMQ,SAAS,GACbT,OAAO,CAACQ,OAAO,GAAGR,OAAO,CAACI,MAAM,GAAGH,QAAQ;;EAE7C;EACA,IAAIS,GAAG,GAAG,CAAC;EACX,IAAIC,IAAI,GAAGT,KAAK,GAAG,CAAC;EACpB,IAAIU,YAAY,GAAGV,KAAK;EAExB,OAAOQ,GAAG,IAAIC,IAAI,EAAE;IAClB,MAAME,GAAG,GAAIH,GAAG,GAAGC,IAAI,IAAK,CAAC;IAC7B,MAAMG,IAAI,GAAGf,OAAO,CAACc,GAAG,CAAE;IAE1B,IAAIC,IAAI,CAACC,CAAC,GAAGD,IAAI,CAACV,MAAM,IAAIC,WAAW,EAAE;MACvCO,YAAY,GAAGC,GAAG;MAClBF,IAAI,GAAGE,GAAG,GAAG,CAAC;IAChB,CAAC,MAAM;MACLH,GAAG,GAAGG,GAAG,GAAG,CAAC;IACf;EACF;;EAEA;EACA,MAAMG,OAAiB,GAAG,EAAE;EAE5B,KAAK,IAAIC,CAAC,GAAGL,YAAY,EAAEK,CAAC,GAAGf,KAAK,EAAEe,CAAC,EAAE,EAAE;IACzC,MAAMH,IAAI,GAAGf,OAAO,CAACkB,CAAC,CAAE;IACxB,IAAIH,IAAI,CAACC,CAAC,GAAGN,SAAS,EAAE;IACxBO,OAAO,CAACE,IAAI,CAACD,CAAC,CAAC;EACjB;EAEA,OAAOD,OAAO;AAChB","ignoreList":[]}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { useCellRenderer } from './hooks/useCellRenderer';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* INTERNAL hook.
|
|
7
|
-
* MUST ALWAYS CALL hooks in the same order.
|
|
8
|
-
*/
|
|
9
|
-
export function useRecyclerListInternal(layouts, metrics, bufferPx, getItemType) {
|
|
10
|
-
/**
|
|
11
|
-
* FlashList rule:
|
|
12
|
-
* Hooks are ALWAYS called.
|
|
13
|
-
* Inputs are guarded instead.
|
|
14
|
-
*/
|
|
15
|
-
const safeLayouts = metrics.height > 0 ? layouts : EMPTY_LAYOUTS;
|
|
16
|
-
const safeBufferPx = metrics.height > 0 ? bufferPx : 0;
|
|
17
|
-
return useCellRenderer(safeLayouts, metrics, safeBufferPx, getItemType);
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** Stable empty reference */
|
|
21
|
-
const EMPTY_LAYOUTS = [];
|
|
22
|
-
//# sourceMappingURL=RecyclerList.internal.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useCellRenderer","useRecyclerListInternal","layouts","metrics","bufferPx","getItemType","safeLayouts","height","EMPTY_LAYOUTS","safeBufferPx"],"sourceRoot":"../../src","sources":["RecyclerList.internal.ts"],"mappings":";;AAIA,SAASA,eAAe,QAAQ,yBAAyB;;AAEzD;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CACrCC,OAAmC,EACnCC,OAAsB,EACtBC,QAAgB,EAChBC,WAAsC,EACrB;EAEjB;AACF;AACA;AACA;AACA;EACE,MAAMC,WAAW,GACfH,OAAO,CAACI,MAAM,GAAG,CAAC,GAAGL,OAAO,GAAGM,aAAa;EAE9C,MAAMC,YAAY,GAChBN,OAAO,CAACI,MAAM,GAAG,CAAC,GAAGH,QAAQ,GAAG,CAAC;EAEnC,OAAOJ,eAAe,CACpBM,WAAW,EACXH,OAAO,EACPM,YAAY,EACZJ,WACF,CAAC;AACH;;AAEA;AACA,MAAMG,aAAyC,GAAG,EAAE","ignoreList":[]}
|
|
@@ -1,166 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import React, { useMemo, useRef, useEffect } from 'react';
|
|
4
|
-
import { ScrollView, View, StyleSheet } from 'react-native';
|
|
5
|
-
import { useRecyclerListInternal } from './RecyclerList.internal';
|
|
6
|
-
import { useScrollMetrics } from './windowing';
|
|
7
|
-
import { MutableLinearLayout } from './layout/MutableLinearLayout';
|
|
8
|
-
import { ViewabilityHelper } from './viewability/ViewabilityHelper';
|
|
9
|
-
import { PrefetchHelper } from './prefetch/PrefetchHelper';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Public API — mirrors FlashList behavior, not internals.
|
|
13
|
-
*/
|
|
14
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
-
/**
|
|
16
|
-
* FlashList invariant:
|
|
17
|
-
* Never allow viewport height = 0 to gate windowing.
|
|
18
|
-
*/
|
|
19
|
-
const DEFAULT_VIEWPORT_HEIGHT = 800;
|
|
20
|
-
export function RecyclerList(props) {
|
|
21
|
-
const {
|
|
22
|
-
containerWidth,
|
|
23
|
-
itemCount,
|
|
24
|
-
itemHeights,
|
|
25
|
-
estimatedItemHeight = 80,
|
|
26
|
-
renderBufferRatio = 1.3,
|
|
27
|
-
getItemType = () => 'default',
|
|
28
|
-
renderItem,
|
|
29
|
-
onPrefetch,
|
|
30
|
-
onViewableItemsChanged
|
|
31
|
-
} = props;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* 🚨 DEV WARNINGS ONLY (never throw in render!)
|
|
35
|
-
*/
|
|
36
|
-
if (__DEV__) {
|
|
37
|
-
if (!itemHeights && itemCount == null) {
|
|
38
|
-
console.error('RecyclerList requires either itemCount or itemHeights.');
|
|
39
|
-
}
|
|
40
|
-
if (itemHeights && itemCount != null) {
|
|
41
|
-
console.error('Provide only one of itemCount or itemHeights.');
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* STEP 1: Resolve item count safely (props only).
|
|
47
|
-
* Never depend on hooks for structural decisions.
|
|
48
|
-
*/
|
|
49
|
-
const itemLength = itemHeights?.length ?? itemCount ?? 0;
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* STEP 2: Resolve initial heights (always defined).
|
|
53
|
-
*/
|
|
54
|
-
const resolvedHeights = useMemo(() => {
|
|
55
|
-
if (itemHeights) return itemHeights;
|
|
56
|
-
return Array.from({
|
|
57
|
-
length: itemLength
|
|
58
|
-
}, () => estimatedItemHeight);
|
|
59
|
-
}, [itemHeights, itemLength, estimatedItemHeight]);
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* STEP 3: Mutable layout lifecycle.
|
|
63
|
-
* Recreate layout only when shape changes.
|
|
64
|
-
*/
|
|
65
|
-
const layoutRef = useRef(null);
|
|
66
|
-
const lastLayoutKeyRef = useRef(null);
|
|
67
|
-
const layoutKey = `${containerWidth}-${itemLength}`;
|
|
68
|
-
if (!layoutRef.current || lastLayoutKeyRef.current !== layoutKey) {
|
|
69
|
-
layoutRef.current = new MutableLinearLayout(resolvedHeights, containerWidth);
|
|
70
|
-
lastLayoutKeyRef.current = layoutKey;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* STEP 4: Read layout snapshot.
|
|
75
|
-
*/
|
|
76
|
-
const layouts = layoutRef.current.getLayouts();
|
|
77
|
-
const contentHeight = layoutRef.current.getContentHeight();
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* STEP 5: Scroll metrics.
|
|
81
|
-
*/
|
|
82
|
-
const {
|
|
83
|
-
metrics,
|
|
84
|
-
onScroll,
|
|
85
|
-
onLayout
|
|
86
|
-
} = useScrollMetrics();
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* STEP 6: Guard initial windowing.
|
|
90
|
-
*/
|
|
91
|
-
const effectiveViewportHeight = metrics.height > 0 ? metrics.height : DEFAULT_VIEWPORT_HEIGHT;
|
|
92
|
-
const bufferPx = effectiveViewportHeight * renderBufferRatio;
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* STEP 7: Windowing + recycling.
|
|
96
|
-
*/
|
|
97
|
-
const cells = useRecyclerListInternal(layouts, metrics, bufferPx, getItemType);
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* STEP 8: Phase-1 observers.
|
|
101
|
-
*/
|
|
102
|
-
const viewabilityRef = useRef(new ViewabilityHelper({
|
|
103
|
-
itemVisiblePercentThreshold: 50
|
|
104
|
-
}));
|
|
105
|
-
const prefetchRef = useRef(new PrefetchHelper());
|
|
106
|
-
useEffect(() => {
|
|
107
|
-
prefetchRef.current = new PrefetchHelper();
|
|
108
|
-
}, [itemLength]);
|
|
109
|
-
useEffect(() => {
|
|
110
|
-
if (metrics.height === 0) return;
|
|
111
|
-
if (onViewableItemsChanged) {
|
|
112
|
-
const visibleLayouts = [];
|
|
113
|
-
for (const cell of cells) {
|
|
114
|
-
const layout = layouts[cell.index];
|
|
115
|
-
if (layout) visibleLayouts.push(layout);
|
|
116
|
-
}
|
|
117
|
-
const info = viewabilityRef.current.computeViewableItems(visibleLayouts, metrics);
|
|
118
|
-
onViewableItemsChanged(info);
|
|
119
|
-
}
|
|
120
|
-
if (onPrefetch && itemLength > 0) {
|
|
121
|
-
prefetchRef.current.runPrefetch(cells.map(c => c.index), itemLength, 5, onPrefetch);
|
|
122
|
-
}
|
|
123
|
-
}, [cells, metrics.offsetY, metrics.height, onViewableItemsChanged, onPrefetch, itemLength, layouts]);
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* STEP 9: Render absolutely positioned cells.
|
|
127
|
-
*/
|
|
128
|
-
return /*#__PURE__*/_jsx(ScrollView, {
|
|
129
|
-
style: styles.container,
|
|
130
|
-
onLayout: onLayout,
|
|
131
|
-
onScroll: onScroll,
|
|
132
|
-
scrollEventThrottle: 16,
|
|
133
|
-
removeClippedSubviews: true,
|
|
134
|
-
children: /*#__PURE__*/_jsx(View, {
|
|
135
|
-
style: [styles.content, {
|
|
136
|
-
height: contentHeight
|
|
137
|
-
}],
|
|
138
|
-
children: cells.map(cell => {
|
|
139
|
-
const layout = layouts[cell.index];
|
|
140
|
-
if (!layout) return null;
|
|
141
|
-
return /*#__PURE__*/_jsx(View, {
|
|
142
|
-
style: [styles.cell, {
|
|
143
|
-
top: layout.y,
|
|
144
|
-
width: layout.width,
|
|
145
|
-
height: layout.height
|
|
146
|
-
}],
|
|
147
|
-
children: renderItem(cell.index)
|
|
148
|
-
}, cell.key);
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
});
|
|
152
|
-
}
|
|
153
|
-
const styles = StyleSheet.create({
|
|
154
|
-
container: {
|
|
155
|
-
flex: 1
|
|
156
|
-
},
|
|
157
|
-
content: {
|
|
158
|
-
position: 'relative',
|
|
159
|
-
width: '100%'
|
|
160
|
-
},
|
|
161
|
-
cell: {
|
|
162
|
-
position: 'absolute',
|
|
163
|
-
left: 0
|
|
164
|
-
}
|
|
165
|
-
});
|
|
166
|
-
//# sourceMappingURL=RecyclerList.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","useMemo","useRef","useEffect","ScrollView","View","StyleSheet","useRecyclerListInternal","useScrollMetrics","MutableLinearLayout","ViewabilityHelper","PrefetchHelper","jsx","_jsx","DEFAULT_VIEWPORT_HEIGHT","RecyclerList","props","containerWidth","itemCount","itemHeights","estimatedItemHeight","renderBufferRatio","getItemType","renderItem","onPrefetch","onViewableItemsChanged","__DEV__","console","error","itemLength","length","resolvedHeights","Array","from","layoutRef","lastLayoutKeyRef","layoutKey","current","layouts","getLayouts","contentHeight","getContentHeight","metrics","onScroll","onLayout","effectiveViewportHeight","height","bufferPx","cells","viewabilityRef","itemVisiblePercentThreshold","prefetchRef","visibleLayouts","cell","layout","index","push","info","computeViewableItems","runPrefetch","map","c","offsetY","style","styles","container","scrollEventThrottle","removeClippedSubviews","children","content","top","y","width","key","create","flex","position","left"],"sourceRoot":"../../src","sources":["RecyclerList.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IACVC,OAAO,EACPC,MAAM,EACNC,SAAS,QACJ,OAAO;AACd,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,CAACD,MAAM,EAAE,OAAO,IAAI;QAExB,oBACEzC,IAAA,CAACR,IAAI;UAEH0D,KAAK,EAAE,CACLC,MAAM,CAACX,IAAI,EACX;YACEiB,GAAG,EAAEhB,MAAM,CAACiB,CAAC;YACbC,KAAK,EAAElB,MAAM,CAACkB,KAAK;YACnB1B,MAAM,EAAEQ,MAAM,CAACR;UACjB,CAAC,CACD;UAAAsB,QAAA,EAED7C,UAAU,CAAC8B,IAAI,CAACE,KAAK;QAAC,GAVlBF,IAAI,CAACoB,GAWN,CAAC;MAEX,CAAC;IAAC,CACE;EAAC,CACG,CAAC;AAEjB;AAEA,MAAMT,MAAM,GAAG1D,UAAU,CAACoE,MAAM,CAAC;EAC/BT,SAAS,EAAE;IAAEU,IAAI,EAAE;EAAE,CAAC;EACtBN,OAAO,EAAE;IAAEO,QAAQ,EAAE,UAAU;IAAEJ,KAAK,EAAE;EAAO,CAAC;EAChDnB,IAAI,EAAE;IAAEuB,QAAQ,EAAE,UAAU;IAAEC,IAAI,EAAE;EAAE;AACxC,CAAC,CAAC","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../src","sources":["RecyclerList.types.ts"],"mappings":"","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["getStableKey","slotKey","index"],"sourceRoot":"../../../src","sources":["cell/StableKey.ts"],"mappings":";;AAAA,OAAO,SAASA,YAAYA,CAC1BC,OAAe,EACfC,KAAa,EACL;EACR,OAAO,GAAGD,OAAO,IAAIC,KAAK,EAAE;AAC9B","ignoreList":[]}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
4
|
-
import { CellRecycler } from '../cell/CellRecycler';
|
|
5
|
-
import { findVisibleIndexRange } from '../windowing/findVisibleIndexRange';
|
|
6
|
-
/**
|
|
7
|
-
* 🔒 Stable empty references (module-level)
|
|
8
|
-
* These MUST NOT be recreated per render.
|
|
9
|
-
*/
|
|
10
|
-
const EMPTY_INDICES = [];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* React bridge for CellRecycler.
|
|
14
|
-
* FlashList equivalent: useCellRenderer
|
|
15
|
-
*
|
|
16
|
-
* Responsibilities:
|
|
17
|
-
* - Translate scroll state → visible indices
|
|
18
|
-
* - Ask recycler for physical cells
|
|
19
|
-
* - Commit results with referential stability
|
|
20
|
-
*
|
|
21
|
-
* Responsibilities it does NOT have:
|
|
22
|
-
* ❌ Layout mutation
|
|
23
|
-
* ❌ Measurement
|
|
24
|
-
* ❌ Rendering
|
|
25
|
-
*/
|
|
26
|
-
export function useCellRenderer(layouts, metrics, bufferPx, getCellType) {
|
|
27
|
-
/**
|
|
28
|
-
* Recycler instance is stable across renders.
|
|
29
|
-
*/
|
|
30
|
-
const recyclerRef = useRef(new CellRecycler());
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Compute visible indices.
|
|
34
|
-
* PURE + TOTAL:
|
|
35
|
-
* - Never throws
|
|
36
|
-
* - Always returns the same reference when empty
|
|
37
|
-
*/
|
|
38
|
-
const visibleIndices = useMemo(() => layouts.length === 0 ? EMPTY_INDICES : findVisibleIndexRange(layouts, metrics, bufferPx), [layouts, metrics.offsetY, metrics.height, bufferPx]);
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Physical cells to render.
|
|
42
|
-
*/
|
|
43
|
-
const [cells, setCells] = useState([]);
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Reconcile visible indices → physical cells.
|
|
47
|
-
*
|
|
48
|
-
* FlashList invariant:
|
|
49
|
-
* - Only update state if identity truly changed
|
|
50
|
-
* - Prevents pointless re-renders
|
|
51
|
-
*/
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
const next = recyclerRef.current.reconcile(visibleIndices, getCellType);
|
|
54
|
-
setCells(prev => prev.length === next.length && prev.every((c, i) => c === next[i]) ? prev : next);
|
|
55
|
-
}, [visibleIndices, getCellType]);
|
|
56
|
-
return cells;
|
|
57
|
-
}
|
|
58
|
-
//# sourceMappingURL=useCellRenderer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useMemo","useRef","useState","CellRecycler","findVisibleIndexRange","EMPTY_INDICES","useCellRenderer","layouts","metrics","bufferPx","getCellType","recyclerRef","visibleIndices","length","offsetY","height","cells","setCells","next","current","reconcile","prev","every","c","i"],"sourceRoot":"../../../src","sources":["hooks/useCellRenderer.ts"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAE5D,SAASC,YAAY,QAAQ,sBAAsB;AACnD,SAASC,qBAAqB,QAAQ,oCAAoC;AAI1E;AACA;AACA;AACA;AACA,MAAMC,aAAgC,GAAG,EAAE;;AAE3C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAC7BC,OAAmC,EACnCC,OAAsB,EACtBC,QAAgB,EAChBC,WAAsC,EACrB;EACjB;AACF;AACA;EACE,MAAMC,WAAW,GAAGV,MAAM,CAAe,IAAIE,YAAY,CAAC,CAAC,CAAC;;EAE5D;AACF;AACA;AACA;AACA;AACA;EACE,MAAMS,cAAc,GAAGZ,OAAO,CAC5B,MACEO,OAAO,CAACM,MAAM,KAAK,CAAC,GAChBR,aAAa,GACbD,qBAAqB,CACnBG,OAAO,EACPC,OAAO,EACPC,QACF,CAAC,EACP,CAACF,OAAO,EAAEC,OAAO,CAACM,OAAO,EAAEN,OAAO,CAACO,MAAM,EAAEN,QAAQ,CACrD,CAAC;;EAED;AACF;AACA;EACE,MAAM,CAACO,KAAK,EAAEC,QAAQ,CAAC,GACrBf,QAAQ,CAAkB,EAAE,CAAC;;EAE/B;AACF;AACA;AACA;AACA;AACA;AACA;EACEH,SAAS,CAAC,MAAM;IACd,MAAMmB,IAAI,GACRP,WAAW,CAACQ,OAAO,CAACC,SAAS,CAC3BR,cAAc,EACdF,WACF,CAAC;IAEHO,QAAQ,CAACI,IAAI,IACXA,IAAI,CAACR,MAAM,KAAKK,IAAI,CAACL,MAAM,IAC3BQ,IAAI,CAACC,KAAK,CAAC,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,KAAKL,IAAI,CAACM,CAAC,CAAC,CAAC,GAC/BH,IAAI,GACJH,IACN,CAAC;EACH,CAAC,EAAE,CAACN,cAAc,EAAEF,WAAW,CAAC,CAAC;EAEjC,OAAOM,KAAK;AACd","ignoreList":[]}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["useRef","useCallback","useStableCallback","fn","ref","current","args"],"sourceRoot":"../../../src","sources":["hooks/useStableCallback.ts"],"mappings":";;AAAA,SAASA,MAAM,EAAEC,WAAW,QAAQ,OAAO;AAE3C,OAAO,SAASC,iBAAiBA,CAC/BC,EAAK,EACF;EACH,MAAMC,GAAG,GAAGJ,MAAM,CAACG,EAAE,CAAC;EACtBC,GAAG,CAACC,OAAO,GAAGF,EAAE;EAEhB,OAAOF,WAAW,CACf,CAAC,GAAGK,IAAa,KAAKF,GAAG,CAACC,OAAO,CAAC,GAAGC,IAAI,CAAC,EAC3C,EACF,CAAC;AACH","ignoreList":[]}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Layout provider using estimated item heights.
|
|
5
|
-
* Used before real measurements are available.
|
|
6
|
-
*/
|
|
7
|
-
export class EstimatedLayoutProvider {
|
|
8
|
-
constructor(itemCount, itemHeight, width) {
|
|
9
|
-
this.itemCount = itemCount;
|
|
10
|
-
this.itemHeight = itemHeight;
|
|
11
|
-
this.width = width;
|
|
12
|
-
}
|
|
13
|
-
getItemCount() {
|
|
14
|
-
return this.itemCount;
|
|
15
|
-
}
|
|
16
|
-
getLayout(index) {
|
|
17
|
-
return {
|
|
18
|
-
x: 0,
|
|
19
|
-
y: index * this.itemHeight,
|
|
20
|
-
width: this.width,
|
|
21
|
-
height: this.itemHeight
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
//# sourceMappingURL=EstimatedLayoutProvider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["EstimatedLayoutProvider","constructor","itemCount","itemHeight","width","getItemCount","getLayout","index","x","y","height"],"sourceRoot":"../../../src","sources":["layout/EstimatedLayoutProvider.ts"],"mappings":";;AAGA;AACA;AACA;AACA;AACA,OAAO,MAAMA,uBAAuB,CAA2B;EAK7DC,WAAWA,CACTC,SAAiB,EACjBC,UAAkB,EAClBC,KAAa,EACb;IACA,IAAI,CAACF,SAAS,GAAGA,SAAS;IAC1B,IAAI,CAACC,UAAU,GAAGA,UAAU;IAC5B,IAAI,CAACC,KAAK,GAAGA,KAAK;EACpB;EAEAC,YAAYA,CAAA,EAAW;IACrB,OAAO,IAAI,CAACH,SAAS;EACvB;EAEAI,SAASA,CAACC,KAAa,EAAmB;IACxC,OAAO;MACLC,CAAC,EAAE,CAAC;MACJC,CAAC,EAAEF,KAAK,GAAG,IAAI,CAACJ,UAAU;MAC1BC,KAAK,EAAE,IAAI,CAACA,KAAK;MACjBM,MAAM,EAAE,IAAI,CAACP;IACf,CAAC;EACH;AACF","ignoreList":[]}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Resolves layouts eagerly into a contiguous array.
|
|
5
|
-
* Pure, deterministic, and reusable.
|
|
6
|
-
*
|
|
7
|
-
* FlashList equivalent: internal layout resolver.
|
|
8
|
-
*/
|
|
9
|
-
export function computeLayouts(provider) {
|
|
10
|
-
const count = provider.getItemCount();
|
|
11
|
-
const layouts = new Array(count);
|
|
12
|
-
for (let i = 0; i < count; i++) {
|
|
13
|
-
layouts[i] = provider.getLayout(i);
|
|
14
|
-
}
|
|
15
|
-
return layouts;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=LayoutEngine.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["computeLayouts","provider","count","getItemCount","layouts","Array","i","getLayout"],"sourceRoot":"../../../src","sources":["layout/LayoutEngine.ts"],"mappings":";;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,cAAcA,CAC5BC,QAAwB,EACI;EAC5B,MAAMC,KAAK,GAAGD,QAAQ,CAACE,YAAY,CAAC,CAAC;EACrC,MAAMC,OAA0B,GAAG,IAAIC,KAAK,CAACH,KAAK,CAAC;EAEnD,KAAK,IAAII,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGJ,KAAK,EAAEI,CAAC,EAAE,EAAE;IAC9BF,OAAO,CAACE,CAAC,CAAC,GAAGL,QAAQ,CAACM,SAAS,CAACD,CAAC,CAAC;EACpC;EAEA,OAAOF,OAAO;AAChB","ignoreList":[]}
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Public token describing viewability state of an item.
|
|
5
|
-
* Mirrors FlashList's ViewToken concept.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Configuration for viewability calculations.
|
|
10
|
-
*/
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* ViewabilityHelper
|
|
14
|
-
*
|
|
15
|
-
* Pure observer:
|
|
16
|
-
* - Does NOT affect layout
|
|
17
|
-
* - Does NOT affect recycling
|
|
18
|
-
* - Computes visibility based on layout + scroll metrics
|
|
19
|
-
*
|
|
20
|
-
* This class is intentionally stateful (lastVisible)
|
|
21
|
-
* to compute "changed" items efficiently.
|
|
22
|
-
*/
|
|
23
|
-
export class ViewabilityHelper {
|
|
24
|
-
/** Previously visible indices */
|
|
25
|
-
lastVisible = new Set();
|
|
26
|
-
constructor(config = {}) {
|
|
27
|
-
this.config = config;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Computes which items are viewable and which changed
|
|
32
|
-
* since the last invocation.
|
|
33
|
-
*
|
|
34
|
-
* IMPORTANT:
|
|
35
|
-
* - This method should be called AFTER windowing,
|
|
36
|
-
* not on the full dataset.
|
|
37
|
-
*/
|
|
38
|
-
computeViewableItems(layouts, metrics) {
|
|
39
|
-
const visibleNow = new Set();
|
|
40
|
-
const viewableItems = [];
|
|
41
|
-
const changed = [];
|
|
42
|
-
const viewportTop = metrics.offsetY;
|
|
43
|
-
const viewportBottom = viewportTop + metrics.height;
|
|
44
|
-
|
|
45
|
-
// Normalize threshold into [0, 1]
|
|
46
|
-
const threshold = (this.config.itemVisiblePercentThreshold ?? 0) / 100;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* NOTE:
|
|
50
|
-
* We intentionally iterate layouts sequentially,
|
|
51
|
-
* but EXIT EARLY when items are completely below viewport.
|
|
52
|
-
*
|
|
53
|
-
* This keeps complexity near O(visibleItems),
|
|
54
|
-
* not O(totalItems).
|
|
55
|
-
*/
|
|
56
|
-
for (let i = 0; i < layouts.length; i++) {
|
|
57
|
-
const layout = layouts[i];
|
|
58
|
-
|
|
59
|
-
// If item is completely below viewport, stop
|
|
60
|
-
if (layout.y > viewportBottom) {
|
|
61
|
-
break;
|
|
62
|
-
}
|
|
63
|
-
const itemTop = layout.y;
|
|
64
|
-
const itemBottom = layout.y + layout.height;
|
|
65
|
-
|
|
66
|
-
// If item is completely above viewport, skip
|
|
67
|
-
if (itemBottom < viewportTop) {
|
|
68
|
-
continue;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
// Compute visible intersection
|
|
72
|
-
const visibleTop = Math.max(itemTop, viewportTop);
|
|
73
|
-
const visibleBottom = Math.min(itemBottom, viewportBottom);
|
|
74
|
-
const visibleHeight = Math.max(0, visibleBottom - visibleTop);
|
|
75
|
-
|
|
76
|
-
// Guard against zero-height items
|
|
77
|
-
const itemHeight = layout.height > 0 ? layout.height : 1;
|
|
78
|
-
const visibleRatio = visibleHeight / itemHeight;
|
|
79
|
-
if (visibleRatio >= threshold) {
|
|
80
|
-
visibleNow.add(i);
|
|
81
|
-
viewableItems.push({
|
|
82
|
-
index: i,
|
|
83
|
-
isViewable: true
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
// Newly visible
|
|
87
|
-
if (!this.lastVisible.has(i)) {
|
|
88
|
-
changed.push({
|
|
89
|
-
index: i,
|
|
90
|
-
isViewable: true
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Items that were visible before but not anymore
|
|
98
|
-
*/
|
|
99
|
-
for (const index of this.lastVisible) {
|
|
100
|
-
if (!visibleNow.has(index)) {
|
|
101
|
-
changed.push({
|
|
102
|
-
index,
|
|
103
|
-
isViewable: false
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
// Update snapshot
|
|
109
|
-
this.lastVisible = visibleNow;
|
|
110
|
-
return {
|
|
111
|
-
viewableItems,
|
|
112
|
-
changed
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
//# sourceMappingURL=ViewabilityHelper.js.map
|