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,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// JLayoutRect.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
#pragma once
|
|
9
9
|
|
|
10
10
|
#include <fbjni/fbjni.h>
|
|
11
|
-
#include "
|
|
11
|
+
#include "LayoutRect.hpp"
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
|
|
@@ -17,19 +17,19 @@ namespace margelo::nitro::nitrolist {
|
|
|
17
17
|
using namespace facebook;
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* The C++ JNI bridge between the C++ struct "
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "LayoutRect" and the the Kotlin data class "LayoutRect".
|
|
21
21
|
*/
|
|
22
|
-
struct
|
|
22
|
+
struct JLayoutRect final: public jni::JavaClass<JLayoutRect> {
|
|
23
23
|
public:
|
|
24
|
-
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrolist/
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrolist/LayoutRect;";
|
|
25
25
|
|
|
26
26
|
public:
|
|
27
27
|
/**
|
|
28
|
-
* Convert this Java/Kotlin-based struct to the C++ struct
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct LayoutRect by copying all values to C++.
|
|
29
29
|
*/
|
|
30
30
|
[[maybe_unused]]
|
|
31
31
|
[[nodiscard]]
|
|
32
|
-
|
|
32
|
+
LayoutRect toCpp() const {
|
|
33
33
|
static const auto clazz = javaClassStatic();
|
|
34
34
|
static const auto fieldX = clazz->getField<double>("x");
|
|
35
35
|
double x = this->getFieldValue(fieldX);
|
|
@@ -39,7 +39,7 @@ namespace margelo::nitro::nitrolist {
|
|
|
39
39
|
double width = this->getFieldValue(fieldWidth);
|
|
40
40
|
static const auto fieldHeight = clazz->getField<double>("height");
|
|
41
41
|
double height = this->getFieldValue(fieldHeight);
|
|
42
|
-
return
|
|
42
|
+
return LayoutRect(
|
|
43
43
|
x,
|
|
44
44
|
y,
|
|
45
45
|
width,
|
|
@@ -52,8 +52,8 @@ namespace margelo::nitro::nitrolist {
|
|
|
52
52
|
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
53
53
|
*/
|
|
54
54
|
[[maybe_unused]]
|
|
55
|
-
static jni::local_ref<
|
|
56
|
-
using JSignature =
|
|
55
|
+
static jni::local_ref<JLayoutRect::javaobject> fromCpp(const LayoutRect& value) {
|
|
56
|
+
using JSignature = JLayoutRect(double, double, double, double);
|
|
57
57
|
static const auto clazz = javaClassStatic();
|
|
58
58
|
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
59
59
|
return create(
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/HybridNitroLayoutEngineSpec.kt
CHANGED
|
@@ -47,7 +47,7 @@ abstract class HybridNitroLayoutEngineSpec: HybridObject() {
|
|
|
47
47
|
// Methods
|
|
48
48
|
@DoNotStrip
|
|
49
49
|
@Keep
|
|
50
|
-
abstract fun computeLayout(containerWidth: Double, itemHeights: DoubleArray): Array<
|
|
50
|
+
abstract fun computeLayout(containerWidth: Double, itemHeights: DoubleArray): Array<LayoutRect>
|
|
51
51
|
|
|
52
52
|
private external fun initHybrid(): HybridData
|
|
53
53
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// LayoutRect.kt
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
@@ -12,11 +12,11 @@ import com.facebook.proguard.annotations.DoNotStrip
|
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
|
-
* Represents the JavaScript object/struct "
|
|
15
|
+
* Represents the JavaScript object/struct "LayoutRect".
|
|
16
16
|
*/
|
|
17
17
|
@DoNotStrip
|
|
18
18
|
@Keep
|
|
19
|
-
data class
|
|
19
|
+
data class LayoutRect(
|
|
20
20
|
@DoNotStrip
|
|
21
21
|
@Keep
|
|
22
22
|
val x: Double,
|
|
@@ -40,8 +40,8 @@ data class LayoutRectangle(
|
|
|
40
40
|
@Keep
|
|
41
41
|
@Suppress("unused")
|
|
42
42
|
@JvmStatic
|
|
43
|
-
private fun fromCpp(x: Double, y: Double, width: Double, height: Double):
|
|
44
|
-
return
|
|
43
|
+
private fun fromCpp(x: Double, y: Double, width: Double, height: Double): LayoutRect {
|
|
44
|
+
return LayoutRect(x, y, width, height)
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
11
|
// Forward declaration of `HybridNitroLayoutEngineSpec` to properly resolve imports.
|
|
12
12
|
namespace margelo::nitro::nitrolist { class HybridNitroLayoutEngineSpec; }
|
|
13
|
-
// Forward declaration of `
|
|
14
|
-
namespace margelo::nitro::nitrolist { struct
|
|
13
|
+
// Forward declaration of `LayoutRect` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::nitrolist { struct LayoutRect; }
|
|
15
15
|
|
|
16
16
|
// Forward declarations of Swift defined types
|
|
17
17
|
// Forward declaration of `HybridNitroLayoutEngineSpec_cxx` to properly resolve imports.
|
|
@@ -19,7 +19,7 @@ namespace NitroList { class HybridNitroLayoutEngineSpec_cxx; }
|
|
|
19
19
|
|
|
20
20
|
// Include C++ defined types
|
|
21
21
|
#include "HybridNitroLayoutEngineSpec.hpp"
|
|
22
|
-
#include "
|
|
22
|
+
#include "LayoutRect.hpp"
|
|
23
23
|
#include <NitroModules/Result.hpp>
|
|
24
24
|
#include <exception>
|
|
25
25
|
#include <memory>
|
|
@@ -31,13 +31,13 @@ namespace NitroList { class HybridNitroLayoutEngineSpec_cxx; }
|
|
|
31
31
|
*/
|
|
32
32
|
namespace margelo::nitro::nitrolist::bridge::swift {
|
|
33
33
|
|
|
34
|
-
// pragma MARK: std::vector<
|
|
34
|
+
// pragma MARK: std::vector<LayoutRect>
|
|
35
35
|
/**
|
|
36
|
-
* Specialized version of `std::vector<
|
|
36
|
+
* Specialized version of `std::vector<LayoutRect>`.
|
|
37
37
|
*/
|
|
38
|
-
using
|
|
39
|
-
inline std::vector<
|
|
40
|
-
std::vector<
|
|
38
|
+
using std__vector_LayoutRect_ = std::vector<LayoutRect>;
|
|
39
|
+
inline std::vector<LayoutRect> create_std__vector_LayoutRect_(size_t size) noexcept {
|
|
40
|
+
std::vector<LayoutRect> vector;
|
|
41
41
|
vector.reserve(size);
|
|
42
42
|
return vector;
|
|
43
43
|
}
|
|
@@ -65,13 +65,13 @@ namespace margelo::nitro::nitrolist::bridge::swift {
|
|
|
65
65
|
using std__weak_ptr_HybridNitroLayoutEngineSpec_ = std::weak_ptr<HybridNitroLayoutEngineSpec>;
|
|
66
66
|
inline std__weak_ptr_HybridNitroLayoutEngineSpec_ weakify_std__shared_ptr_HybridNitroLayoutEngineSpec_(const std::shared_ptr<HybridNitroLayoutEngineSpec>& strong) noexcept { return strong; }
|
|
67
67
|
|
|
68
|
-
// pragma MARK: Result<std::vector<
|
|
69
|
-
using
|
|
70
|
-
inline
|
|
71
|
-
return Result<std::vector<
|
|
68
|
+
// pragma MARK: Result<std::vector<LayoutRect>>
|
|
69
|
+
using Result_std__vector_LayoutRect__ = Result<std::vector<LayoutRect>>;
|
|
70
|
+
inline Result_std__vector_LayoutRect__ create_Result_std__vector_LayoutRect__(const std::vector<LayoutRect>& value) noexcept {
|
|
71
|
+
return Result<std::vector<LayoutRect>>::withValue(value);
|
|
72
72
|
}
|
|
73
|
-
inline
|
|
74
|
-
return Result<std::vector<
|
|
73
|
+
inline Result_std__vector_LayoutRect__ create_Result_std__vector_LayoutRect__(const std::exception_ptr& error) noexcept {
|
|
74
|
+
return Result<std::vector<LayoutRect>>::withError(error);
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
} // namespace margelo::nitro::nitrolist::bridge::swift
|
|
@@ -10,12 +10,12 @@
|
|
|
10
10
|
// Forward declarations of C++ defined types
|
|
11
11
|
// Forward declaration of `HybridNitroLayoutEngineSpec` to properly resolve imports.
|
|
12
12
|
namespace margelo::nitro::nitrolist { class HybridNitroLayoutEngineSpec; }
|
|
13
|
-
// Forward declaration of `
|
|
14
|
-
namespace margelo::nitro::nitrolist { struct
|
|
13
|
+
// Forward declaration of `LayoutRect` to properly resolve imports.
|
|
14
|
+
namespace margelo::nitro::nitrolist { struct LayoutRect; }
|
|
15
15
|
|
|
16
16
|
// Include C++ defined types
|
|
17
17
|
#include "HybridNitroLayoutEngineSpec.hpp"
|
|
18
|
-
#include "
|
|
18
|
+
#include "LayoutRect.hpp"
|
|
19
19
|
#include <NitroModules/Result.hpp>
|
|
20
20
|
#include <exception>
|
|
21
21
|
#include <memory>
|
|
@@ -12,10 +12,10 @@
|
|
|
12
12
|
// Forward declaration of `HybridNitroLayoutEngineSpec_cxx` to properly resolve imports.
|
|
13
13
|
namespace NitroList { class HybridNitroLayoutEngineSpec_cxx; }
|
|
14
14
|
|
|
15
|
-
// Forward declaration of `
|
|
16
|
-
namespace margelo::nitro::nitrolist { struct
|
|
15
|
+
// Forward declaration of `LayoutRect` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::nitrolist { struct LayoutRect; }
|
|
17
17
|
|
|
18
|
-
#include "
|
|
18
|
+
#include "LayoutRect.hpp"
|
|
19
19
|
#include <vector>
|
|
20
20
|
|
|
21
21
|
#include "NitroList-Swift-Cxx-Umbrella.hpp"
|
|
@@ -62,7 +62,7 @@ namespace margelo::nitro::nitrolist {
|
|
|
62
62
|
|
|
63
63
|
public:
|
|
64
64
|
// Methods
|
|
65
|
-
inline std::vector<
|
|
65
|
+
inline std::vector<LayoutRect> computeLayout(double containerWidth, const std::vector<double>& itemHeights) override {
|
|
66
66
|
auto __result = _swiftPart.computeLayout(std::forward<decltype(containerWidth)>(containerWidth), itemHeights);
|
|
67
67
|
if (__result.hasError()) [[unlikely]] {
|
|
68
68
|
std::rethrow_exception(__result.error());
|
|
@@ -14,7 +14,7 @@ public protocol HybridNitroLayoutEngineSpec_protocol: HybridObject {
|
|
|
14
14
|
|
|
15
15
|
|
|
16
16
|
// Methods
|
|
17
|
-
func computeLayout(containerWidth: Double, itemHeights: [Double]) throws -> [
|
|
17
|
+
func computeLayout(containerWidth: Double, itemHeights: [Double]) throws -> [LayoutRect]
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
public extension HybridNitroLayoutEngineSpec_protocol {
|
|
@@ -118,20 +118,20 @@ open class HybridNitroLayoutEngineSpec_cxx {
|
|
|
118
118
|
|
|
119
119
|
// Methods
|
|
120
120
|
@inline(__always)
|
|
121
|
-
public final func computeLayout(containerWidth: Double, itemHeights: bridge.std__vector_double_) -> bridge.
|
|
121
|
+
public final func computeLayout(containerWidth: Double, itemHeights: bridge.std__vector_double_) -> bridge.Result_std__vector_LayoutRect__ {
|
|
122
122
|
do {
|
|
123
123
|
let __result = try self.__implementation.computeLayout(containerWidth: containerWidth, itemHeights: itemHeights.map({ __item in __item }))
|
|
124
|
-
let __resultCpp = { () -> bridge.
|
|
125
|
-
var __vector = bridge.
|
|
124
|
+
let __resultCpp = { () -> bridge.std__vector_LayoutRect_ in
|
|
125
|
+
var __vector = bridge.create_std__vector_LayoutRect_(__result.count)
|
|
126
126
|
for __item in __result {
|
|
127
127
|
__vector.push_back(__item)
|
|
128
128
|
}
|
|
129
129
|
return __vector
|
|
130
130
|
}()
|
|
131
|
-
return bridge.
|
|
131
|
+
return bridge.create_Result_std__vector_LayoutRect__(__resultCpp)
|
|
132
132
|
} catch (let __error) {
|
|
133
133
|
let __exceptionPtr = __error.toCpp()
|
|
134
|
-
return bridge.
|
|
134
|
+
return bridge.create_Result_std__vector_LayoutRect__(__exceptionPtr)
|
|
135
135
|
}
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// LayoutRect.swift
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
@@ -9,15 +9,15 @@ import Foundation
|
|
|
9
9
|
import NitroModules
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
|
-
* Represents an instance of `
|
|
12
|
+
* Represents an instance of `LayoutRect`, backed by a C++ struct.
|
|
13
13
|
*/
|
|
14
|
-
public typealias
|
|
14
|
+
public typealias LayoutRect = margelo.nitro.nitrolist.LayoutRect
|
|
15
15
|
|
|
16
|
-
public extension
|
|
16
|
+
public extension LayoutRect {
|
|
17
17
|
private typealias bridge = margelo.nitro.nitrolist.bridge.swift
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
|
-
* Create a new instance of `
|
|
20
|
+
* Create a new instance of `LayoutRect`.
|
|
21
21
|
*/
|
|
22
22
|
init(x: Double, y: Double, width: Double, height: Double) {
|
|
23
23
|
self.init(x, y, width, height)
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
14
|
#endif
|
|
15
15
|
|
|
16
|
-
// Forward declaration of `
|
|
17
|
-
namespace margelo::nitro::nitrolist { struct
|
|
16
|
+
// Forward declaration of `LayoutRect` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrolist { struct LayoutRect; }
|
|
18
18
|
|
|
19
|
-
#include "
|
|
19
|
+
#include "LayoutRect.hpp"
|
|
20
20
|
#include <vector>
|
|
21
21
|
|
|
22
22
|
namespace margelo::nitro::nitrolist {
|
|
@@ -50,7 +50,7 @@ namespace margelo::nitro::nitrolist {
|
|
|
50
50
|
|
|
51
51
|
public:
|
|
52
52
|
// Methods
|
|
53
|
-
virtual std::vector<
|
|
53
|
+
virtual std::vector<LayoutRect> computeLayout(double containerWidth, const std::vector<double>& itemHeights) = 0;
|
|
54
54
|
|
|
55
55
|
protected:
|
|
56
56
|
// Hybrid Setup
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
///
|
|
2
|
-
///
|
|
2
|
+
/// LayoutRect.hpp
|
|
3
3
|
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
4
|
/// https://github.com/mrousavy/nitro
|
|
5
5
|
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
namespace margelo::nitro::nitrolist {
|
|
36
36
|
|
|
37
37
|
/**
|
|
38
|
-
* A struct which can be represented as a JavaScript object (
|
|
38
|
+
* A struct which can be represented as a JavaScript object (LayoutRect).
|
|
39
39
|
*/
|
|
40
|
-
struct
|
|
40
|
+
struct LayoutRect final {
|
|
41
41
|
public:
|
|
42
42
|
double x SWIFT_PRIVATE;
|
|
43
43
|
double y SWIFT_PRIVATE;
|
|
@@ -45,30 +45,30 @@ namespace margelo::nitro::nitrolist {
|
|
|
45
45
|
double height SWIFT_PRIVATE;
|
|
46
46
|
|
|
47
47
|
public:
|
|
48
|
-
|
|
49
|
-
explicit
|
|
48
|
+
LayoutRect() = default;
|
|
49
|
+
explicit LayoutRect(double x, double y, double width, double height): x(x), y(y), width(width), height(height) {}
|
|
50
50
|
|
|
51
51
|
public:
|
|
52
|
-
friend bool operator==(const
|
|
52
|
+
friend bool operator==(const LayoutRect& lhs, const LayoutRect& rhs) = default;
|
|
53
53
|
};
|
|
54
54
|
|
|
55
55
|
} // namespace margelo::nitro::nitrolist
|
|
56
56
|
|
|
57
57
|
namespace margelo::nitro {
|
|
58
58
|
|
|
59
|
-
// C++
|
|
59
|
+
// C++ LayoutRect <> JS LayoutRect (object)
|
|
60
60
|
template <>
|
|
61
|
-
struct JSIConverter<margelo::nitro::nitrolist::
|
|
62
|
-
static inline margelo::nitro::nitrolist::
|
|
61
|
+
struct JSIConverter<margelo::nitro::nitrolist::LayoutRect> final {
|
|
62
|
+
static inline margelo::nitro::nitrolist::LayoutRect fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
63
63
|
jsi::Object obj = arg.asObject(runtime);
|
|
64
|
-
return margelo::nitro::nitrolist::
|
|
64
|
+
return margelo::nitro::nitrolist::LayoutRect(
|
|
65
65
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "x"))),
|
|
66
66
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "y"))),
|
|
67
67
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "width"))),
|
|
68
68
|
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "height")))
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
|
-
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrolist::
|
|
71
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrolist::LayoutRect& arg) {
|
|
72
72
|
jsi::Object obj(runtime);
|
|
73
73
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "x"), JSIConverter<double>::toJSI(runtime, arg.x));
|
|
74
74
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "y"), JSIConverter<double>::toJSI(runtime, arg.y));
|
package/package.json
CHANGED
package/src/cell/Cell.ts
CHANGED
|
@@ -1,14 +1,23 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Physical reusable cell.
|
|
3
|
-
*
|
|
3
|
+
* Represents a single mounted view instance.
|
|
4
4
|
*/
|
|
5
5
|
export interface Cell {
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Stable physical identity.
|
|
8
|
+
* Used as React key. NEVER changes.
|
|
9
|
+
*/
|
|
7
10
|
readonly key: string
|
|
8
11
|
|
|
9
|
-
/**
|
|
12
|
+
/**
|
|
13
|
+
* Logical data index currently bound.
|
|
14
|
+
* Changes as the cell is recycled.
|
|
15
|
+
*/
|
|
10
16
|
index: number
|
|
11
17
|
|
|
12
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Compatibility type (row, header, etc).
|
|
20
|
+
* Determines reuse eligibility.
|
|
21
|
+
*/
|
|
13
22
|
readonly type: string
|
|
14
23
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CellKey } from '../types/CellKey'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Monotonic key generator for physical cell instances.
|
|
5
|
+
* Guarantees stable keys across the lifetime of the list.
|
|
6
|
+
*/
|
|
7
|
+
export class CellKeyGenerator {
|
|
8
|
+
private nextId = 0
|
|
9
|
+
|
|
10
|
+
next(): CellKey {
|
|
11
|
+
return this.nextId++
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
reset(): void {
|
|
15
|
+
this.nextId = 0
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/cell/CellRecycler.ts
CHANGED
|
@@ -1,66 +1,76 @@
|
|
|
1
1
|
import type { Cell } from './Cell'
|
|
2
|
-
|
|
3
|
-
const MAX_CELLS = 40
|
|
2
|
+
import { createCell } from './createCell'
|
|
4
3
|
|
|
5
4
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
* FlashList equivalent: CellRecycler
|
|
5
|
+
* Manages physical cell reuse.
|
|
6
|
+
* Imperative and stateful by design.
|
|
7
|
+
* This is NOT React code.
|
|
10
8
|
*/
|
|
11
9
|
export class CellRecycler {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
private
|
|
10
|
+
/**
|
|
11
|
+
* Active cells mapped by logical index.
|
|
12
|
+
*/
|
|
13
|
+
private readonly indexToCell = new Map<number, Cell>()
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Pool of detached reusable cells.
|
|
17
|
+
*/
|
|
18
|
+
private readonly recycledCells: Cell[] = []
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
|
-
* Reconcile
|
|
19
|
-
*
|
|
21
|
+
* Reconcile a contiguous visible index range
|
|
22
|
+
* into a stable list of physical cells.
|
|
23
|
+
*
|
|
24
|
+
* HOT PATH:
|
|
25
|
+
* - No index arrays
|
|
26
|
+
* - Minimal allocations
|
|
27
|
+
* - Deterministic
|
|
20
28
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
29
|
+
reconcileRange(
|
|
30
|
+
startIndex: number,
|
|
31
|
+
endIndex: number,
|
|
32
|
+
resolveCellType: (index: number) => string
|
|
24
33
|
): readonly Cell[] {
|
|
25
|
-
const
|
|
34
|
+
const nextActive: Cell[] = []
|
|
26
35
|
|
|
27
|
-
//
|
|
28
|
-
|
|
29
|
-
if (visibleSet.has(index)) continue
|
|
36
|
+
// Track which current indices are no longer visible
|
|
37
|
+
const unusedIndices = new Set(this.indexToCell.keys())
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
for (let index = startIndex; index <= endIndex; index++) {
|
|
40
|
+
unusedIndices.delete(index)
|
|
32
41
|
|
|
33
|
-
|
|
34
|
-
if (
|
|
35
|
-
|
|
42
|
+
let cell = this.indexToCell.get(index)
|
|
43
|
+
if (cell) {
|
|
44
|
+
// Existing assignment — reuse
|
|
45
|
+
nextActive.push(cell)
|
|
46
|
+
continue
|
|
36
47
|
}
|
|
37
48
|
|
|
38
|
-
const
|
|
39
|
-
if (pool.length < MAX_CELLS) pool.push(cell)
|
|
40
|
-
this.reusableCellsByType.set(cell.type, pool)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// 2️⃣ Acquire cells for newly visible indices
|
|
44
|
-
for (const index of visibleIndices) {
|
|
45
|
-
if (this.activeCells.has(index)) continue
|
|
49
|
+
const type = resolveCellType(index)
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
const
|
|
49
|
-
|
|
51
|
+
// Try to reuse a recycled cell of same type
|
|
52
|
+
const recycledIdx = this.recycledCells.findIndex(
|
|
53
|
+
c => c.type === type
|
|
54
|
+
)
|
|
50
55
|
|
|
51
|
-
if (
|
|
52
|
-
cell =
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
index,
|
|
56
|
-
}
|
|
56
|
+
if (recycledIdx !== -1) {
|
|
57
|
+
cell = this.recycledCells.splice(recycledIdx, 1)[0]!
|
|
58
|
+
} else {
|
|
59
|
+
cell = createCell(type)
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
cell.index = index
|
|
60
|
-
this.
|
|
61
|
-
|
|
63
|
+
this.indexToCell.set(index, cell)
|
|
64
|
+
nextActive.push(cell)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Recycle cells that left the visible window
|
|
68
|
+
for (const index of unusedIndices) {
|
|
69
|
+
const cell = this.indexToCell.get(index)!
|
|
70
|
+
this.indexToCell.delete(index)
|
|
71
|
+
this.recycledCells.push(cell)
|
|
62
72
|
}
|
|
63
73
|
|
|
64
|
-
return
|
|
74
|
+
return nextActive
|
|
65
75
|
}
|
|
66
76
|
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Cell } from './Cell'
|
|
2
|
+
|
|
3
|
+
let nextCellId = 0
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new physical cell with a stable identity.
|
|
7
|
+
* The key is generated ONCE and never changes.
|
|
8
|
+
*/
|
|
9
|
+
export function createCell(type: string): Cell {
|
|
10
|
+
return {
|
|
11
|
+
key: `cell-${nextCellId++}`, // stable physical identity
|
|
12
|
+
type,
|
|
13
|
+
index: -1, // assigned by recycler
|
|
14
|
+
}
|
|
15
|
+
}
|
package/src/getVisibleIndices.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
|
|
1
|
+
|
|
2
|
+
|
|
3
|
+
import type { LayoutRect } from './types/layout'
|
|
2
4
|
import type { ScrollMetrics } from './windowing/ScrollMetrics'
|
|
3
5
|
|
|
4
6
|
/**
|
|
@@ -6,7 +8,7 @@ import type { ScrollMetrics } from './windowing/ScrollMetrics'
|
|
|
6
8
|
* Returns indices intersecting viewport ± buffer.
|
|
7
9
|
*/
|
|
8
10
|
export function getVisibleRange(
|
|
9
|
-
layouts: readonly
|
|
11
|
+
layouts: readonly LayoutRect[],
|
|
10
12
|
metrics: ScrollMetrics,
|
|
11
13
|
bufferPx: number
|
|
12
14
|
): readonly number[] {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { useRef, useCallback } from 'react'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Returns a function whose identity is stable across renders,
|
|
5
|
+
* but always invokes the latest provided implementation.
|
|
6
|
+
*
|
|
7
|
+
* Invariants:
|
|
8
|
+
* - Function reference NEVER changes
|
|
9
|
+
* - Logic is ALWAYS up to date
|
|
10
|
+
*
|
|
11
|
+
* This is critical for long-lived systems such as:
|
|
12
|
+
* - Recyclers
|
|
13
|
+
* - Effects
|
|
14
|
+
* - Native bridges
|
|
15
|
+
* - Event pipelines
|
|
16
|
+
*/
|
|
17
|
+
export function usePersistentCallback<
|
|
18
|
+
T extends (...args: never[]) => unknown
|
|
19
|
+
>(fn: T): T {
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Holds the latest implementation.
|
|
23
|
+
* Updating this does NOT trigger re-renders.
|
|
24
|
+
*/
|
|
25
|
+
const fnRef = useRef(fn)
|
|
26
|
+
fnRef.current = fn
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Stable wrapper that forwards calls
|
|
30
|
+
* to the latest implementation.
|
|
31
|
+
*/
|
|
32
|
+
return useCallback(
|
|
33
|
+
((...args: never[]) =>
|
|
34
|
+
fnRef.current(...args)) as T,
|
|
35
|
+
[]
|
|
36
|
+
)
|
|
37
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,2 +1 @@
|
|
|
1
|
-
export { RecyclerList } from './RecyclerList'
|
|
2
|
-
export type { RecyclerListProps } from './RecyclerList.types'
|
|
1
|
+
export { RecyclerList } from './recycler/RecyclerList'
|