react-native-nitro-list 0.1.1 → 0.1.3
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/README.md +16 -44
- package/ios/HybridNitroList.swift +12 -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 +31 -3
- package/lib/commonjs/index.js.map +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/native/NitroListView.js +20 -0
- package/lib/commonjs/native/NitroListView.js.map +1 -0
- package/lib/commonjs/recycler/CellPool.js +33 -0
- package/lib/commonjs/recycler/CellPool.js.map +1 -0
- package/lib/commonjs/recycler/NitroList.js +223 -0
- package/lib/commonjs/recycler/NitroList.js.map +1 -0
- package/lib/commonjs/scroll/useScrollVelocity.js +20 -0
- package/lib/commonjs/scroll/useScrollVelocity.js.map +1 -0
- package/lib/commonjs/{native/NitroList.types.js → specs/NitroList.nitro.js} +1 -1
- package/lib/commonjs/{layout/LayoutProvider.js.map → specs/NitroList.nitro.js.map} +1 -1
- package/lib/commonjs/types/Axis.js +2 -0
- package/lib/{module/layout/LayoutProvider.js.map → commonjs/types/Axis.js.map} +1 -1
- package/lib/commonjs/types/CellKey.js +2 -0
- package/lib/commonjs/{layout/LayoutRectangle.js.map → types/CellKey.js.map} +1 -1
- package/lib/commonjs/types/CellType.js +27 -0
- package/lib/commonjs/types/CellType.js.map +1 -0
- package/lib/commonjs/types/VisibleRange.js +2 -0
- package/lib/commonjs/{native/NitroList.types.js.map → 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/{specs/nitro-layout-engine.nitro.js → types/layout/LinearLayoutInput.js} +1 -1
- 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/CellPool.js +42 -0
- package/lib/commonjs/types/recycler/CellPool.js.map +1 -0
- package/lib/commonjs/{layout/LayoutProvider.js → types/recycler/NitroListProps.js} +1 -1
- package/lib/commonjs/types/recycler/NitroListProps.js.map +1 -0
- package/lib/commonjs/types/recycler/RecyclerCell.js +6 -0
- package/lib/commonjs/types/recycler/RecyclerCell.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/index.js +2 -0
- package/lib/commonjs/types/recycler/index.js.map +1 -0
- package/lib/commonjs/types/scroll/ScrollMetrics.js +6 -0
- 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 +61 -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 +5 -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/native/NitroListView.js +17 -0
- package/lib/module/native/NitroListView.js.map +1 -0
- package/lib/module/recycler/CellPool.js +28 -0
- package/lib/module/recycler/CellPool.js.map +1 -0
- package/lib/module/recycler/NitroList.js +220 -0
- package/lib/module/recycler/NitroList.js.map +1 -0
- package/lib/module/scroll/useScrollVelocity.js +16 -0
- package/lib/module/scroll/useScrollVelocity.js.map +1 -0
- package/lib/module/specs/NitroList.nitro.js +4 -0
- package/lib/module/specs/NitroList.nitro.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 +22 -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/CellPool.js +37 -0
- package/lib/module/types/recycler/CellPool.js.map +1 -0
- package/lib/module/types/recycler/NitroListProps.js +4 -0
- package/lib/module/types/recycler/NitroListProps.js.map +1 -0
- package/lib/module/types/recycler/RecyclerCell.js +4 -0
- package/lib/module/types/recycler/RecyclerCell.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/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 +57 -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 +3 -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/NitroListView.d.ts +20 -0
- package/lib/typescript/src/native/NitroListView.d.ts.map +1 -0
- package/lib/typescript/src/recycler/CellPool.d.ts +11 -0
- package/lib/typescript/src/recycler/CellPool.d.ts.map +1 -0
- package/lib/typescript/src/recycler/NitroList.d.ts +4 -0
- package/lib/typescript/src/recycler/NitroList.d.ts.map +1 -0
- package/lib/typescript/src/scroll/useScrollVelocity.d.ts +2 -0
- package/lib/typescript/src/scroll/useScrollVelocity.d.ts.map +1 -0
- package/lib/typescript/src/specs/NitroList.nitro.d.ts +26 -0
- package/lib/typescript/src/specs/NitroList.nitro.d.ts.map +1 -0
- 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 +2 -0
- package/lib/typescript/src/types/CellKey.d.ts.map +1 -0
- package/lib/typescript/src/types/CellType.d.ts +22 -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/CellPool.d.ts +16 -0
- package/lib/typescript/src/types/recycler/CellPool.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/NitroListProps.d.ts +66 -0
- package/lib/typescript/src/types/recycler/NitroListProps.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/RecyclerCell.d.ts +12 -0
- package/lib/typescript/src/types/recycler/RecyclerCell.d.ts.map +1 -0
- package/lib/typescript/src/types/recycler/RecyclerItemRenderer.d.ts +12 -0
- package/lib/typescript/src/types/recycler/RecyclerItemRenderer.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 +19 -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/nitro.json +5 -5
- package/nitrogen/generated/android/NitroList+autolinking.cmake +2 -2
- package/nitrogen/generated/android/NitroListOnLoad.cpp +2 -2
- package/nitrogen/generated/android/c++/{JHybridNitroLayoutEngineSpec.cpp → JHybridNitroListSpec.cpp} +15 -15
- package/nitrogen/generated/android/c++/{JHybridNitroLayoutEngineSpec.hpp → JHybridNitroListSpec.hpp} +11 -11
- package/nitrogen/generated/android/c++/{JLayoutRectangle.hpp → JItemLayout.hpp} +10 -10
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/{HybridNitroLayoutEngineSpec.kt → HybridNitroListSpec.kt} +7 -7
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/{LayoutRectangle.kt → ItemLayout.kt} +5 -5
- package/nitrogen/generated/ios/NitroList-Swift-Cxx-Bridge.cpp +9 -9
- package/nitrogen/generated/ios/NitroList-Swift-Cxx-Bridge.hpp +27 -27
- package/nitrogen/generated/ios/NitroList-Swift-Cxx-Umbrella.hpp +8 -8
- package/nitrogen/generated/ios/c++/{HybridNitroLayoutEngineSpecSwift.cpp → HybridNitroListSpecSwift.cpp} +2 -2
- package/nitrogen/generated/ios/c++/{HybridNitroLayoutEngineSpecSwift.hpp → HybridNitroListSpecSwift.hpp} +16 -16
- package/nitrogen/generated/ios/swift/HybridNitroListSpec.swift +56 -0
- package/nitrogen/generated/ios/swift/{HybridNitroLayoutEngineSpec_cxx.swift → HybridNitroListSpec_cxx.swift} +23 -23
- package/nitrogen/generated/ios/swift/{LayoutRectangle.swift → ItemLayout.swift} +5 -5
- package/nitrogen/generated/shared/c++/{HybridNitroLayoutEngineSpec.cpp → HybridNitroListSpec.cpp} +4 -4
- package/nitrogen/generated/shared/c++/{HybridNitroLayoutEngineSpec.hpp → HybridNitroListSpec.hpp} +13 -13
- package/nitrogen/generated/shared/c++/{LayoutRectangle.hpp → ItemLayout.hpp} +11 -11
- package/package.json +5 -5
- 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 +7 -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/NitroListView.ts +22 -0
- package/src/recycler/CellPool.ts +33 -0
- package/src/recycler/NitroList.tsx +317 -0
- package/src/scroll/useScrollVelocity.ts +16 -0
- package/src/specs/NitroList.nitro.ts +29 -0
- package/src/types/Axis.ts +10 -0
- package/src/types/CellKey.ts +2 -0
- package/src/types/CellType.ts +9 -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/CellPool.ts +45 -0
- package/src/types/recycler/NitroListProps.ts +74 -0
- package/src/types/recycler/RecyclerCell.ts +12 -0
- package/src/types/recycler/RecyclerItemRenderer.ts +12 -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 +82 -0
- package/src/windowing/index.ts +1 -1
- package/lib/commonjs/NitroList.js +0 -9
- package/lib/commonjs/NitroList.js.map +0 -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/native/NitroLayoutEngine.js +0 -9
- package/lib/commonjs/native/NitroLayoutEngine.js.map +0 -1
- package/lib/commonjs/native/NitroRecyclerView.js +0 -9
- package/lib/commonjs/native/NitroRecyclerView.js.map +0 -1
- package/lib/commonjs/specs/nitro-layout-engine.nitro.js.map +0 -1
- 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/NitroList.js +0 -5
- package/lib/module/NitroList.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/layout/LayoutRectangle.js.map +0 -1
- package/lib/module/native/NitroLayoutEngine.js +0 -5
- package/lib/module/native/NitroLayoutEngine.js.map +0 -1
- package/lib/module/native/NitroList.types.js +0 -4
- package/lib/module/native/NitroList.types.js.map +0 -1
- package/lib/module/native/NitroRecyclerView.js +0 -5
- package/lib/module/native/NitroRecyclerView.js.map +0 -1
- package/lib/module/specs/nitro-layout-engine.nitro.js +0 -4
- package/lib/module/specs/nitro-layout-engine.nitro.js.map +0 -1
- 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/NitroList.d.ts +0 -5
- package/lib/typescript/src/NitroList.d.ts.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/native/NitroLayoutEngine.d.ts +0 -3
- package/lib/typescript/src/native/NitroLayoutEngine.d.ts.map +0 -1
- package/lib/typescript/src/native/NitroList.types.d.ts +0 -9
- package/lib/typescript/src/native/NitroList.types.d.ts.map +0 -1
- package/lib/typescript/src/native/NitroRecyclerView.d.ts +0 -5
- package/lib/typescript/src/native/NitroRecyclerView.d.ts.map +0 -1
- package/lib/typescript/src/specs/nitro-layout-engine.nitro.d.ts +0 -14
- package/lib/typescript/src/specs/nitro-layout-engine.nitro.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/nitrogen/generated/ios/swift/HybridNitroLayoutEngineSpec.swift +0 -56
- package/src/NitroList.ts +0 -8
- 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/native/NitroLayoutEngine.ts +0 -7
- package/src/native/NitroList.types.ts +0 -12
- package/src/native/NitroRecyclerView.ts +0 -8
- package/src/specs/nitro-layout-engine.nitro.ts +0 -17
- package/src/viewability/ViewabilityHelper.ts +0 -130
- package/src/windowing/findVisibleIndexRange.ts +0 -60
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"findVisibleIndexRange.d.ts","sourceRoot":"","sources":["../../../../src/windowing/findVisibleIndexRange.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAA;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAEpD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,SAAS,eAAe,EAAE,EACnC,OAAO,EAAE,aAAa,EACtB,QAAQ,EAAE,MAAM,GACf,SAAS,MAAM,EAAE,CA6CnB"}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
///
|
|
2
|
-
/// HybridNitroLayoutEngineSpec.swift
|
|
3
|
-
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
-
/// https://github.com/mrousavy/nitro
|
|
5
|
-
/// Copyright © 2025 Marc Rousavy @ Margelo
|
|
6
|
-
///
|
|
7
|
-
|
|
8
|
-
import Foundation
|
|
9
|
-
import NitroModules
|
|
10
|
-
|
|
11
|
-
/// See ``HybridNitroLayoutEngineSpec``
|
|
12
|
-
public protocol HybridNitroLayoutEngineSpec_protocol: HybridObject {
|
|
13
|
-
// Properties
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
// Methods
|
|
17
|
-
func computeLayout(containerWidth: Double, itemHeights: [Double]) throws -> [LayoutRectangle]
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
public extension HybridNitroLayoutEngineSpec_protocol {
|
|
21
|
-
/// Default implementation of ``HybridObject.toString``
|
|
22
|
-
func toString() -> String {
|
|
23
|
-
return "[HybridObject NitroLayoutEngine]"
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/// See ``HybridNitroLayoutEngineSpec``
|
|
28
|
-
open class HybridNitroLayoutEngineSpec_base {
|
|
29
|
-
private weak var cxxWrapper: HybridNitroLayoutEngineSpec_cxx? = nil
|
|
30
|
-
public init() { }
|
|
31
|
-
public func getCxxWrapper() -> HybridNitroLayoutEngineSpec_cxx {
|
|
32
|
-
#if DEBUG
|
|
33
|
-
guard self is HybridNitroLayoutEngineSpec else {
|
|
34
|
-
fatalError("`self` is not a `HybridNitroLayoutEngineSpec`! Did you accidentally inherit from `HybridNitroLayoutEngineSpec_base` instead of `HybridNitroLayoutEngineSpec`?")
|
|
35
|
-
}
|
|
36
|
-
#endif
|
|
37
|
-
if let cxxWrapper = self.cxxWrapper {
|
|
38
|
-
return cxxWrapper
|
|
39
|
-
} else {
|
|
40
|
-
let cxxWrapper = HybridNitroLayoutEngineSpec_cxx(self as! HybridNitroLayoutEngineSpec)
|
|
41
|
-
self.cxxWrapper = cxxWrapper
|
|
42
|
-
return cxxWrapper
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A Swift base-protocol representing the NitroLayoutEngine HybridObject.
|
|
49
|
-
* Implement this protocol to create Swift-based instances of NitroLayoutEngine.
|
|
50
|
-
* ```swift
|
|
51
|
-
* class HybridNitroLayoutEngine : HybridNitroLayoutEngineSpec {
|
|
52
|
-
* // ...
|
|
53
|
-
* }
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
public typealias HybridNitroLayoutEngineSpec = HybridNitroLayoutEngineSpec_protocol & HybridNitroLayoutEngineSpec_base
|
package/src/NitroList.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { LayoutRectangle } from './layout/LayoutRectangle'
|
|
2
|
-
import type { ScrollMetrics } from './windowing/ScrollMetrics'
|
|
3
|
-
import type { Cell } from './cell/Cell'
|
|
4
|
-
|
|
5
|
-
import { useCellRenderer } from './hooks/useCellRenderer'
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* INTERNAL hook.
|
|
9
|
-
* MUST ALWAYS CALL hooks in the same order.
|
|
10
|
-
*/
|
|
11
|
-
export function useRecyclerListInternal(
|
|
12
|
-
layouts: readonly LayoutRectangle[],
|
|
13
|
-
metrics: ScrollMetrics,
|
|
14
|
-
bufferPx: number,
|
|
15
|
-
getItemType: (index: number) => string
|
|
16
|
-
): readonly Cell[] {
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* FlashList rule:
|
|
20
|
-
* Hooks are ALWAYS called.
|
|
21
|
-
* Inputs are guarded instead.
|
|
22
|
-
*/
|
|
23
|
-
const safeLayouts =
|
|
24
|
-
metrics.height > 0 ? layouts : EMPTY_LAYOUTS
|
|
25
|
-
|
|
26
|
-
const safeBufferPx =
|
|
27
|
-
metrics.height > 0 ? bufferPx : 0
|
|
28
|
-
|
|
29
|
-
return useCellRenderer(
|
|
30
|
-
safeLayouts,
|
|
31
|
-
metrics,
|
|
32
|
-
safeBufferPx,
|
|
33
|
-
getItemType
|
|
34
|
-
)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
/** Stable empty reference */
|
|
38
|
-
const EMPTY_LAYOUTS: readonly LayoutRectangle[] = []
|
package/src/RecyclerList.tsx
DELETED
|
@@ -1,252 +0,0 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
useMemo,
|
|
3
|
-
useRef,
|
|
4
|
-
useEffect,
|
|
5
|
-
} from 'react'
|
|
6
|
-
import {
|
|
7
|
-
ScrollView,
|
|
8
|
-
View,
|
|
9
|
-
StyleSheet,
|
|
10
|
-
} from 'react-native'
|
|
11
|
-
|
|
12
|
-
import type { Cell } from './cell/Cell'
|
|
13
|
-
import type { LayoutRectangle } from './layout/LayoutRectangle'
|
|
14
|
-
|
|
15
|
-
import { useRecyclerListInternal } from './RecyclerList.internal'
|
|
16
|
-
import { useScrollMetrics } from './windowing'
|
|
17
|
-
import { MutableLinearLayout } from './layout/MutableLinearLayout'
|
|
18
|
-
import { ViewabilityHelper } from './viewability/ViewabilityHelper'
|
|
19
|
-
import { PrefetchHelper } from './prefetch/PrefetchHelper'
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Public API — mirrors FlashList behavior, not internals.
|
|
23
|
-
*/
|
|
24
|
-
export type RecyclerListProps = {
|
|
25
|
-
containerWidth: number
|
|
26
|
-
itemCount?: number
|
|
27
|
-
itemHeights?: readonly number[]
|
|
28
|
-
estimatedItemHeight?: number
|
|
29
|
-
renderBufferRatio?: number
|
|
30
|
-
getItemType?: (index: number) => string
|
|
31
|
-
renderItem: (index: number) => React.ReactElement
|
|
32
|
-
onPrefetch?: (indices: number[]) => void
|
|
33
|
-
onViewableItemsChanged?: (info: {
|
|
34
|
-
viewableItems: { index: number; isViewable: boolean }[]
|
|
35
|
-
changed: { index: number; isViewable: boolean }[]
|
|
36
|
-
}) => void
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* FlashList invariant:
|
|
41
|
-
* Never allow viewport height = 0 to gate windowing.
|
|
42
|
-
*/
|
|
43
|
-
const DEFAULT_VIEWPORT_HEIGHT = 800
|
|
44
|
-
|
|
45
|
-
export function RecyclerList(props: RecyclerListProps): React.ReactElement {
|
|
46
|
-
const {
|
|
47
|
-
containerWidth,
|
|
48
|
-
itemCount,
|
|
49
|
-
itemHeights,
|
|
50
|
-
estimatedItemHeight = 80,
|
|
51
|
-
renderBufferRatio = 1.3,
|
|
52
|
-
getItemType = () => 'default',
|
|
53
|
-
renderItem,
|
|
54
|
-
onPrefetch,
|
|
55
|
-
onViewableItemsChanged,
|
|
56
|
-
} = props
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* 🚨 DEV WARNINGS ONLY (never throw in render!)
|
|
60
|
-
*/
|
|
61
|
-
if (__DEV__) {
|
|
62
|
-
if (!itemHeights && itemCount == null) {
|
|
63
|
-
console.error(
|
|
64
|
-
'RecyclerList requires either itemCount or itemHeights.'
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (itemHeights && itemCount != null) {
|
|
69
|
-
console.error(
|
|
70
|
-
'Provide only one of itemCount or itemHeights.'
|
|
71
|
-
)
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
/**
|
|
76
|
-
* STEP 1: Resolve item count safely (props only).
|
|
77
|
-
* Never depend on hooks for structural decisions.
|
|
78
|
-
*/
|
|
79
|
-
const itemLength =
|
|
80
|
-
itemHeights?.length ??
|
|
81
|
-
itemCount ??
|
|
82
|
-
0
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* STEP 2: Resolve initial heights (always defined).
|
|
86
|
-
*/
|
|
87
|
-
const resolvedHeights = useMemo<readonly number[]>(() => {
|
|
88
|
-
if (itemHeights) return itemHeights
|
|
89
|
-
|
|
90
|
-
return Array.from(
|
|
91
|
-
{ length: itemLength },
|
|
92
|
-
() => estimatedItemHeight
|
|
93
|
-
)
|
|
94
|
-
}, [itemHeights, itemLength, estimatedItemHeight])
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* STEP 3: Mutable layout lifecycle.
|
|
98
|
-
* Recreate layout only when shape changes.
|
|
99
|
-
*/
|
|
100
|
-
const layoutRef = useRef<MutableLinearLayout | null>(null)
|
|
101
|
-
const lastLayoutKeyRef = useRef<string | null>(null)
|
|
102
|
-
|
|
103
|
-
const layoutKey = `${containerWidth}-${itemLength}`
|
|
104
|
-
|
|
105
|
-
if (
|
|
106
|
-
!layoutRef.current ||
|
|
107
|
-
lastLayoutKeyRef.current !== layoutKey
|
|
108
|
-
) {
|
|
109
|
-
layoutRef.current = new MutableLinearLayout(
|
|
110
|
-
resolvedHeights,
|
|
111
|
-
containerWidth
|
|
112
|
-
)
|
|
113
|
-
lastLayoutKeyRef.current = layoutKey
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* STEP 4: Read layout snapshot.
|
|
118
|
-
*/
|
|
119
|
-
const layouts: readonly LayoutRectangle[] =
|
|
120
|
-
layoutRef.current.getLayouts()
|
|
121
|
-
|
|
122
|
-
const contentHeight =
|
|
123
|
-
layoutRef.current.getContentHeight()
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* STEP 5: Scroll metrics.
|
|
127
|
-
*/
|
|
128
|
-
const {
|
|
129
|
-
metrics,
|
|
130
|
-
onScroll,
|
|
131
|
-
onLayout,
|
|
132
|
-
} = useScrollMetrics()
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* STEP 6: Guard initial windowing.
|
|
136
|
-
*/
|
|
137
|
-
const effectiveViewportHeight =
|
|
138
|
-
metrics.height > 0
|
|
139
|
-
? metrics.height
|
|
140
|
-
: DEFAULT_VIEWPORT_HEIGHT
|
|
141
|
-
|
|
142
|
-
const bufferPx =
|
|
143
|
-
effectiveViewportHeight * renderBufferRatio
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* STEP 7: Windowing + recycling.
|
|
147
|
-
*/
|
|
148
|
-
const cells: readonly Cell[] =
|
|
149
|
-
useRecyclerListInternal(
|
|
150
|
-
layouts,
|
|
151
|
-
metrics,
|
|
152
|
-
bufferPx,
|
|
153
|
-
getItemType
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* STEP 8: Phase-1 observers.
|
|
158
|
-
*/
|
|
159
|
-
const viewabilityRef = useRef(
|
|
160
|
-
new ViewabilityHelper({
|
|
161
|
-
itemVisiblePercentThreshold: 50,
|
|
162
|
-
})
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
const prefetchRef = useRef(
|
|
166
|
-
new PrefetchHelper()
|
|
167
|
-
)
|
|
168
|
-
|
|
169
|
-
useEffect(() => {
|
|
170
|
-
prefetchRef.current = new PrefetchHelper()
|
|
171
|
-
}, [itemLength])
|
|
172
|
-
|
|
173
|
-
useEffect(() => {
|
|
174
|
-
if (metrics.height === 0) return
|
|
175
|
-
|
|
176
|
-
if (onViewableItemsChanged) {
|
|
177
|
-
const visibleLayouts: LayoutRectangle[] = []
|
|
178
|
-
|
|
179
|
-
for (const cell of cells) {
|
|
180
|
-
const layout = layouts[cell.index]
|
|
181
|
-
if (layout) visibleLayouts.push(layout)
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
const info =
|
|
185
|
-
viewabilityRef.current.computeViewableItems(
|
|
186
|
-
visibleLayouts,
|
|
187
|
-
metrics
|
|
188
|
-
)
|
|
189
|
-
|
|
190
|
-
onViewableItemsChanged(info)
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (onPrefetch && itemLength > 0) {
|
|
194
|
-
prefetchRef.current.runPrefetch(
|
|
195
|
-
cells.map(c => c.index),
|
|
196
|
-
itemLength,
|
|
197
|
-
5,
|
|
198
|
-
onPrefetch
|
|
199
|
-
)
|
|
200
|
-
}
|
|
201
|
-
}, [
|
|
202
|
-
cells,
|
|
203
|
-
metrics.offsetY,
|
|
204
|
-
metrics.height,
|
|
205
|
-
onViewableItemsChanged,
|
|
206
|
-
onPrefetch,
|
|
207
|
-
itemLength,
|
|
208
|
-
layouts,
|
|
209
|
-
])
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* STEP 9: Render absolutely positioned cells.
|
|
213
|
-
*/
|
|
214
|
-
return (
|
|
215
|
-
<ScrollView
|
|
216
|
-
style={styles.container}
|
|
217
|
-
onLayout={onLayout}
|
|
218
|
-
onScroll={onScroll}
|
|
219
|
-
scrollEventThrottle={16}
|
|
220
|
-
removeClippedSubviews
|
|
221
|
-
>
|
|
222
|
-
<View style={[styles.content, { height: contentHeight }]}>
|
|
223
|
-
{cells.map(cell => {
|
|
224
|
-
const layout = layouts[cell.index]
|
|
225
|
-
if (!layout) return null
|
|
226
|
-
|
|
227
|
-
return (
|
|
228
|
-
<View
|
|
229
|
-
key={cell.key}
|
|
230
|
-
style={[
|
|
231
|
-
styles.cell,
|
|
232
|
-
{
|
|
233
|
-
top: layout.y,
|
|
234
|
-
width: layout.width,
|
|
235
|
-
height: layout.height,
|
|
236
|
-
},
|
|
237
|
-
]}
|
|
238
|
-
>
|
|
239
|
-
{renderItem(cell.index)}
|
|
240
|
-
</View>
|
|
241
|
-
)
|
|
242
|
-
})}
|
|
243
|
-
</View>
|
|
244
|
-
</ScrollView>
|
|
245
|
-
)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
const styles = StyleSheet.create({
|
|
249
|
-
container: { flex: 1 },
|
|
250
|
-
content: { position: 'relative', width: '100%' },
|
|
251
|
-
cell: { position: 'absolute', left: 0 },
|
|
252
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import type React from 'react'
|
|
2
|
-
|
|
3
|
-
export type RecyclerListProps = {
|
|
4
|
-
/** Width of the list container (required) */
|
|
5
|
-
readonly containerWidth: number
|
|
6
|
-
|
|
7
|
-
/** Total number of items (used with estimatedItemHeight) */
|
|
8
|
-
readonly itemCount?: number
|
|
9
|
-
|
|
10
|
-
/** Explicit item heights (fast path, skips estimation) */
|
|
11
|
-
readonly itemHeights?: readonly number[]
|
|
12
|
-
|
|
13
|
-
/** Estimated item height when itemHeights not provided */
|
|
14
|
-
readonly estimatedItemHeight?: number
|
|
15
|
-
|
|
16
|
-
/** Render buffer multiplier (FlashList-style, default ~1.3) */
|
|
17
|
-
readonly renderBufferRatio?: number
|
|
18
|
-
|
|
19
|
-
/** Optional item type resolver for recycling */
|
|
20
|
-
readonly getItemType?: (index: number) => string
|
|
21
|
-
|
|
22
|
-
/** Render function */
|
|
23
|
-
readonly renderItem: (index: number) => React.ReactElement
|
|
24
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import { findVisibleIndexRange } from '../../windowing/findVisibleIndexRange'
|
|
2
|
-
|
|
3
|
-
describe('findVisibleIndexRange', () => {
|
|
4
|
-
/**
|
|
5
|
-
* Layouts:
|
|
6
|
-
* index 0 → y: 0–50
|
|
7
|
-
* index 1 → y: 50–100
|
|
8
|
-
* index 2 → y: 100–150
|
|
9
|
-
* ...
|
|
10
|
-
*/
|
|
11
|
-
const layouts = Array.from({ length: 10 }, (_, i) => ({
|
|
12
|
-
x: 0,
|
|
13
|
-
y: i * 50,
|
|
14
|
-
width: 100,
|
|
15
|
-
height: 50,
|
|
16
|
-
}))
|
|
17
|
-
|
|
18
|
-
it('returns empty array when layouts are empty', () => {
|
|
19
|
-
const result = findVisibleIndexRange([], { offsetY: 0, height: 300 }, 100)
|
|
20
|
-
|
|
21
|
-
expect(result).toEqual([])
|
|
22
|
-
})
|
|
23
|
-
it('returns correct visible indices without buffer', () => {
|
|
24
|
-
const result = findVisibleIndexRange(
|
|
25
|
-
layouts,
|
|
26
|
-
{ offsetY: 100, height: 150 },
|
|
27
|
-
0
|
|
28
|
-
)
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Viewport: 100–250 (inclusive)
|
|
32
|
-
* Items that intersect this window:
|
|
33
|
-
* indices 1–5
|
|
34
|
-
*/
|
|
35
|
-
expect(result).toEqual([1, 2, 3, 4, 5])
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('extends window using bufferPx (inclusive boundaries)', () => {
|
|
39
|
-
const result = findVisibleIndexRange(
|
|
40
|
-
layouts,
|
|
41
|
-
{ offsetY: 100, height: 100 },
|
|
42
|
-
100
|
|
43
|
-
)
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Viewport: 100–200
|
|
47
|
-
* Buffer: ±100
|
|
48
|
-
* Effective win: 0–300 (inclusive)
|
|
49
|
-
*
|
|
50
|
-
* index 6 starts at y = 300 → included by design
|
|
51
|
-
* This matches FlashList / RecyclerView behavior
|
|
52
|
-
*/
|
|
53
|
-
expect(result).toEqual([0, 1, 2, 3, 4, 5, 6])
|
|
54
|
-
})
|
|
55
|
-
})
|
package/src/cell/StableKey.ts
DELETED
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo, useRef, useState } from 'react'
|
|
2
|
-
import type { Cell } from '../cell/Cell'
|
|
3
|
-
import { CellRecycler } from '../cell/CellRecycler'
|
|
4
|
-
import { findVisibleIndexRange } from '../windowing/findVisibleIndexRange'
|
|
5
|
-
import type { LayoutRectangle } from '../layout/LayoutRectangle'
|
|
6
|
-
import type { ScrollMetrics } from '../windowing/ScrollMetrics'
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* 🔒 Stable empty references (module-level)
|
|
10
|
-
* These MUST NOT be recreated per render.
|
|
11
|
-
*/
|
|
12
|
-
const EMPTY_INDICES: readonly number[] = []
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* React bridge for CellRecycler.
|
|
16
|
-
* FlashList equivalent: useCellRenderer
|
|
17
|
-
*
|
|
18
|
-
* Responsibilities:
|
|
19
|
-
* - Translate scroll state → visible indices
|
|
20
|
-
* - Ask recycler for physical cells
|
|
21
|
-
* - Commit results with referential stability
|
|
22
|
-
*
|
|
23
|
-
* Responsibilities it does NOT have:
|
|
24
|
-
* ❌ Layout mutation
|
|
25
|
-
* ❌ Measurement
|
|
26
|
-
* ❌ Rendering
|
|
27
|
-
*/
|
|
28
|
-
export function useCellRenderer(
|
|
29
|
-
layouts: readonly LayoutRectangle[],
|
|
30
|
-
metrics: ScrollMetrics,
|
|
31
|
-
bufferPx: number,
|
|
32
|
-
getCellType: (index: number) => string
|
|
33
|
-
): readonly Cell[] {
|
|
34
|
-
/**
|
|
35
|
-
* Recycler instance is stable across renders.
|
|
36
|
-
*/
|
|
37
|
-
const recyclerRef = useRef<CellRecycler>(new CellRecycler())
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Compute visible indices.
|
|
41
|
-
* PURE + TOTAL:
|
|
42
|
-
* - Never throws
|
|
43
|
-
* - Always returns the same reference when empty
|
|
44
|
-
*/
|
|
45
|
-
const visibleIndices = useMemo(
|
|
46
|
-
() =>
|
|
47
|
-
layouts.length === 0
|
|
48
|
-
? EMPTY_INDICES
|
|
49
|
-
: findVisibleIndexRange(
|
|
50
|
-
layouts,
|
|
51
|
-
metrics,
|
|
52
|
-
bufferPx
|
|
53
|
-
),
|
|
54
|
-
[layouts, metrics.offsetY, metrics.height, bufferPx]
|
|
55
|
-
)
|
|
56
|
-
|
|
57
|
-
/**
|
|
58
|
-
* Physical cells to render.
|
|
59
|
-
*/
|
|
60
|
-
const [cells, setCells] =
|
|
61
|
-
useState<readonly Cell[]>([])
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* Reconcile visible indices → physical cells.
|
|
65
|
-
*
|
|
66
|
-
* FlashList invariant:
|
|
67
|
-
* - Only update state if identity truly changed
|
|
68
|
-
* - Prevents pointless re-renders
|
|
69
|
-
*/
|
|
70
|
-
useEffect(() => {
|
|
71
|
-
const next =
|
|
72
|
-
recyclerRef.current.reconcile(
|
|
73
|
-
visibleIndices,
|
|
74
|
-
getCellType
|
|
75
|
-
)
|
|
76
|
-
|
|
77
|
-
setCells(prev =>
|
|
78
|
-
prev.length === next.length &&
|
|
79
|
-
prev.every((c, i) => c === next[i])
|
|
80
|
-
? prev
|
|
81
|
-
: next
|
|
82
|
-
)
|
|
83
|
-
}, [visibleIndices, getCellType])
|
|
84
|
-
|
|
85
|
-
return cells
|
|
86
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { useRef, useCallback } from 'react'
|
|
2
|
-
|
|
3
|
-
export function useStableCallback<T extends (...args: never[]) => unknown>(
|
|
4
|
-
fn: T
|
|
5
|
-
): T {
|
|
6
|
-
const ref = useRef(fn)
|
|
7
|
-
ref.current = fn
|
|
8
|
-
|
|
9
|
-
return useCallback(
|
|
10
|
-
((...args: never[]) => ref.current(...args)) as T,
|
|
11
|
-
[]
|
|
12
|
-
)
|
|
13
|
-
}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import type { LayoutProvider } from './LayoutProvider'
|
|
2
|
-
import type { LayoutRectangle } from './LayoutRectangle'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Layout provider using estimated item heights.
|
|
6
|
-
* Used before real measurements are available.
|
|
7
|
-
*/
|
|
8
|
-
export class EstimatedLayoutProvider implements LayoutProvider {
|
|
9
|
-
private readonly itemCount: number
|
|
10
|
-
private readonly itemHeight: number
|
|
11
|
-
private readonly width: number
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
itemCount: number,
|
|
15
|
-
itemHeight: number,
|
|
16
|
-
width: number
|
|
17
|
-
) {
|
|
18
|
-
this.itemCount = itemCount
|
|
19
|
-
this.itemHeight = itemHeight
|
|
20
|
-
this.width = width
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getItemCount(): number {
|
|
24
|
-
return this.itemCount
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getLayout(index: number): LayoutRectangle {
|
|
28
|
-
return {
|
|
29
|
-
x: 0,
|
|
30
|
-
y: index * this.itemHeight,
|
|
31
|
-
width: this.width,
|
|
32
|
-
height: this.itemHeight,
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { LayoutProvider } from './LayoutProvider'
|
|
2
|
-
import type { LayoutRectangle } from './LayoutRectangle'
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Resolves layouts eagerly into a contiguous array.
|
|
6
|
-
* Pure, deterministic, and reusable.
|
|
7
|
-
*
|
|
8
|
-
* FlashList equivalent: internal layout resolver.
|
|
9
|
-
*/
|
|
10
|
-
export function computeLayouts(
|
|
11
|
-
provider: LayoutProvider
|
|
12
|
-
): readonly LayoutRectangle[] {
|
|
13
|
-
const count = provider.getItemCount()
|
|
14
|
-
const layouts: LayoutRectangle[] = new Array(count)
|
|
15
|
-
|
|
16
|
-
for (let i = 0; i < count; i++) {
|
|
17
|
-
layouts[i] = provider.getLayout(i)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return layouts
|
|
21
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { LayoutRectangle } from './LayoutRectangle'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Provides layout information for items.
|
|
5
|
-
* FlashList equivalent: LayoutProvider
|
|
6
|
-
*/
|
|
7
|
-
export interface LayoutProvider {
|
|
8
|
-
/**
|
|
9
|
-
* Total number of items
|
|
10
|
-
*/
|
|
11
|
-
getItemCount(): number
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* Layout rectangle for a given index
|
|
15
|
-
*/
|
|
16
|
-
getLayout(index: number): LayoutRectangle
|
|
17
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { NitroModules } from 'react-native-nitro-modules'
|
|
2
|
-
import type { NitroLayoutEngine as NitroLayoutEngineSpec } from '../specs/nitro-layout-engine.nitro'
|
|
3
|
-
|
|
4
|
-
export const NitroLayoutEngine =
|
|
5
|
-
NitroModules.createHybridObject<NitroLayoutEngineSpec>(
|
|
6
|
-
'NitroLayoutEngine'
|
|
7
|
-
)
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { LayoutRectangle } from '../layout/LayoutRectangle'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* JS runtime interface backed by Nitro (JSI).
|
|
5
|
-
* Must match native HybridNitroList exactly.
|
|
6
|
-
*/
|
|
7
|
-
export interface NitroList {
|
|
8
|
-
computeLayout(
|
|
9
|
-
containerWidth: number,
|
|
10
|
-
itemHeights: readonly number[]
|
|
11
|
-
): readonly LayoutRectangle[]
|
|
12
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { HybridObject } from 'react-native-nitro-modules'
|
|
2
|
-
|
|
3
|
-
export interface LayoutRectangle {
|
|
4
|
-
readonly x: number
|
|
5
|
-
readonly y: number
|
|
6
|
-
readonly width: number
|
|
7
|
-
readonly height: number
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface NitroLayoutEngine
|
|
11
|
-
extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
|
|
12
|
-
|
|
13
|
-
computeLayout(
|
|
14
|
-
containerWidth: number,
|
|
15
|
-
itemHeights: readonly number[]
|
|
16
|
-
): readonly LayoutRectangle[]
|
|
17
|
-
}
|