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.
Files changed (312) hide show
  1. package/ios/HybridNitroList.swift +10 -14
  2. package/lib/commonjs/cell/CellKeyGenerator.js +21 -0
  3. package/lib/commonjs/cell/CellKeyGenerator.js.map +1 -0
  4. package/lib/commonjs/cell/CellRecycler.js +48 -40
  5. package/lib/commonjs/cell/CellRecycler.js.map +1 -1
  6. package/lib/commonjs/cell/createCell.js +21 -0
  7. package/lib/commonjs/cell/createCell.js.map +1 -0
  8. package/lib/commonjs/cell/index.js +20 -0
  9. package/lib/commonjs/cell/index.js.map +1 -0
  10. package/lib/commonjs/getVisibleIndices.js.map +1 -1
  11. package/lib/commonjs/hooks/usePersistentCallback.js +36 -0
  12. package/lib/commonjs/hooks/usePersistentCallback.js.map +1 -0
  13. package/lib/commonjs/index.js +1 -1
  14. package/lib/commonjs/layout/MutableLinearLayout.js +78 -39
  15. package/lib/commonjs/layout/MutableLinearLayout.js.map +1 -1
  16. package/lib/commonjs/layout/constants/layoutDefaults.js +19 -0
  17. package/lib/commonjs/layout/constants/layoutDefaults.js.map +1 -0
  18. package/lib/commonjs/layout/index.js +0 -18
  19. package/lib/commonjs/layout/index.js.map +1 -1
  20. package/lib/commonjs/recycler/CellPool.js +46 -0
  21. package/lib/commonjs/recycler/CellPool.js.map +1 -0
  22. package/lib/commonjs/recycler/RecyclerList.js +224 -0
  23. package/lib/commonjs/recycler/RecyclerList.js.map +1 -0
  24. package/lib/commonjs/types/Axis.js +2 -0
  25. package/lib/commonjs/{layout/LayoutProvider.js.map → types/Axis.js.map} +1 -1
  26. package/lib/commonjs/types/CellKey.js +2 -0
  27. package/lib/{module/layout/LayoutProvider.js.map → commonjs/types/CellKey.js.map} +1 -1
  28. package/lib/commonjs/types/CellType.js +2 -0
  29. package/lib/commonjs/{layout/LayoutRectangle.js.map → types/CellType.js.map} +1 -1
  30. package/lib/commonjs/types/VisibleRange.js +2 -0
  31. package/lib/{module/layout/LayoutRectangle.js.map → commonjs/types/VisibleRange.js.map} +1 -1
  32. package/lib/commonjs/{RecyclerList.types.js → types/VisibleRangeInput.js} +1 -1
  33. package/lib/commonjs/types/VisibleRangeInput.js.map +1 -0
  34. package/lib/commonjs/types/index.js +13 -0
  35. package/lib/commonjs/types/index.js.map +1 -0
  36. package/lib/commonjs/types/layout/LayoutRect.js +2 -0
  37. package/lib/commonjs/types/layout/LayoutRect.js.map +1 -0
  38. package/lib/commonjs/types/layout/LinearLayoutInput.js +6 -0
  39. package/lib/commonjs/types/layout/LinearLayoutInput.js.map +1 -0
  40. package/lib/commonjs/types/layout/MainAxisPadding.js +26 -0
  41. package/lib/commonjs/types/layout/MainAxisPadding.js.map +1 -0
  42. package/lib/commonjs/types/layout/index.js +2 -0
  43. package/lib/commonjs/types/layout/index.js.map +1 -0
  44. package/lib/commonjs/types/recycler/RecyclerCellInstance.js +6 -0
  45. package/lib/commonjs/types/recycler/RecyclerCellInstance.js.map +1 -0
  46. package/lib/commonjs/types/recycler/RecyclerItemRenderer.js +6 -0
  47. package/lib/commonjs/types/recycler/RecyclerItemRenderer.js.map +1 -0
  48. package/lib/commonjs/types/recycler/RecyclerListProps.js +6 -0
  49. package/lib/commonjs/types/recycler/RecyclerListProps.js.map +1 -0
  50. package/lib/commonjs/types/recycler/index.js +2 -0
  51. package/lib/commonjs/types/recycler/index.js.map +1 -0
  52. package/lib/commonjs/{layout/LayoutProvider.js → types/scroll/ScrollMetrics.js} +1 -1
  53. package/lib/commonjs/types/scroll/ScrollMetrics.js.map +1 -0
  54. package/lib/commonjs/types/scroll/index.js +2 -0
  55. package/lib/commonjs/types/scroll/index.js.map +1 -0
  56. package/lib/commonjs/windowing/computeVisibleItemRange.js +71 -0
  57. package/lib/commonjs/windowing/computeVisibleItemRange.js.map +1 -0
  58. package/lib/commonjs/windowing/index.js +3 -3
  59. package/lib/commonjs/windowing/index.js.map +1 -1
  60. package/lib/module/cell/CellKeyGenerator.js +16 -0
  61. package/lib/module/cell/CellKeyGenerator.js.map +1 -0
  62. package/lib/module/cell/CellRecycler.js +48 -39
  63. package/lib/module/cell/CellRecycler.js.map +1 -1
  64. package/lib/module/cell/createCell.js +17 -0
  65. package/lib/module/cell/createCell.js.map +1 -0
  66. package/lib/module/cell/index.js +7 -0
  67. package/lib/module/cell/index.js.map +1 -0
  68. package/lib/module/getVisibleIndices.js.map +1 -1
  69. package/lib/module/hooks/usePersistentCallback.js +33 -0
  70. package/lib/module/hooks/usePersistentCallback.js.map +1 -0
  71. package/lib/module/index.js +1 -1
  72. package/lib/module/index.js.map +1 -1
  73. package/lib/module/layout/MutableLinearLayout.js +78 -38
  74. package/lib/module/layout/MutableLinearLayout.js.map +1 -1
  75. package/lib/module/layout/constants/layoutDefaults.js +15 -0
  76. package/lib/module/layout/constants/layoutDefaults.js.map +1 -0
  77. package/lib/module/layout/index.js +0 -3
  78. package/lib/module/layout/index.js.map +1 -1
  79. package/lib/module/recycler/CellPool.js +41 -0
  80. package/lib/module/recycler/CellPool.js.map +1 -0
  81. package/lib/module/recycler/RecyclerList.js +221 -0
  82. package/lib/module/recycler/RecyclerList.js.map +1 -0
  83. package/lib/module/types/Axis.js +2 -0
  84. package/lib/module/types/Axis.js.map +1 -0
  85. package/lib/module/types/CellKey.js +2 -0
  86. package/lib/module/types/CellKey.js.map +1 -0
  87. package/lib/module/types/CellType.js +2 -0
  88. package/lib/module/types/CellType.js.map +1 -0
  89. package/lib/module/types/VisibleRange.js +2 -0
  90. package/lib/module/types/VisibleRange.js.map +1 -0
  91. package/lib/module/types/VisibleRangeInput.js +4 -0
  92. package/lib/module/types/VisibleRangeInput.js.map +1 -0
  93. package/lib/module/types/index.js +4 -0
  94. package/lib/module/types/index.js.map +1 -0
  95. package/lib/module/types/layout/LayoutRect.js +2 -0
  96. package/lib/module/types/layout/LayoutRect.js.map +1 -0
  97. package/lib/module/types/layout/LinearLayoutInput.js +4 -0
  98. package/lib/module/types/layout/LinearLayoutInput.js.map +1 -0
  99. package/lib/module/types/layout/MainAxisPadding.js +22 -0
  100. package/lib/module/types/layout/MainAxisPadding.js.map +1 -0
  101. package/lib/module/types/layout/index.js +2 -0
  102. package/lib/module/types/layout/index.js.map +1 -0
  103. package/lib/module/types/recycler/RecyclerCellInstance.js +4 -0
  104. package/lib/module/types/recycler/RecyclerCellInstance.js.map +1 -0
  105. package/lib/module/types/recycler/RecyclerItemRenderer.js +4 -0
  106. package/lib/module/types/recycler/RecyclerItemRenderer.js.map +1 -0
  107. package/lib/module/types/recycler/RecyclerListProps.js +4 -0
  108. package/lib/module/types/recycler/RecyclerListProps.js.map +1 -0
  109. package/lib/module/types/recycler/index.js +2 -0
  110. package/lib/module/types/recycler/index.js.map +1 -0
  111. package/lib/module/types/scroll/ScrollMetrics.js +4 -0
  112. package/lib/module/types/scroll/ScrollMetrics.js.map +1 -0
  113. package/lib/module/types/scroll/index.js +2 -0
  114. package/lib/module/types/scroll/index.js.map +1 -0
  115. package/lib/module/windowing/computeVisibleItemRange.js +67 -0
  116. package/lib/module/windowing/computeVisibleItemRange.js.map +1 -0
  117. package/lib/module/windowing/index.js +1 -1
  118. package/lib/module/windowing/index.js.map +1 -1
  119. package/lib/typescript/src/cell/Cell.d.ts +13 -4
  120. package/lib/typescript/src/cell/Cell.d.ts.map +1 -1
  121. package/lib/typescript/src/cell/CellKeyGenerator.d.ts +11 -0
  122. package/lib/typescript/src/cell/CellKeyGenerator.d.ts.map +1 -0
  123. package/lib/typescript/src/cell/CellRecycler.d.ts +19 -11
  124. package/lib/typescript/src/cell/CellRecycler.d.ts.map +1 -1
  125. package/lib/typescript/src/cell/createCell.d.ts +7 -0
  126. package/lib/typescript/src/cell/createCell.d.ts.map +1 -0
  127. package/lib/typescript/src/cell/index.d.ts +4 -0
  128. package/lib/typescript/src/cell/index.d.ts.map +1 -0
  129. package/lib/typescript/src/getVisibleIndices.d.ts +2 -2
  130. package/lib/typescript/src/getVisibleIndices.d.ts.map +1 -1
  131. package/lib/typescript/src/hooks/usePersistentCallback.d.ts +16 -0
  132. package/lib/typescript/src/hooks/usePersistentCallback.d.ts.map +1 -0
  133. package/lib/typescript/src/index.d.ts +1 -2
  134. package/lib/typescript/src/index.d.ts.map +1 -1
  135. package/lib/typescript/src/layout/MutableLinearLayout.d.ts +45 -13
  136. package/lib/typescript/src/layout/MutableLinearLayout.d.ts.map +1 -1
  137. package/lib/typescript/src/layout/constants/layoutDefaults.d.ts +13 -0
  138. package/lib/typescript/src/layout/constants/layoutDefaults.d.ts.map +1 -0
  139. package/lib/typescript/src/layout/index.d.ts +1 -4
  140. package/lib/typescript/src/layout/index.d.ts.map +1 -1
  141. package/lib/typescript/src/native/NitroList.types.d.ts +2 -2
  142. package/lib/typescript/src/native/NitroList.types.d.ts.map +1 -1
  143. package/lib/typescript/src/recycler/CellPool.d.ts +14 -0
  144. package/lib/typescript/src/recycler/CellPool.d.ts.map +1 -0
  145. package/lib/typescript/src/recycler/RecyclerList.d.ts +4 -0
  146. package/lib/typescript/src/recycler/RecyclerList.d.ts.map +1 -0
  147. package/lib/typescript/src/specs/nitro-layout-engine.nitro.d.ts +2 -2
  148. package/lib/typescript/src/specs/nitro-layout-engine.nitro.d.ts.map +1 -1
  149. package/lib/typescript/src/types/Axis.d.ts +11 -0
  150. package/lib/typescript/src/types/Axis.d.ts.map +1 -0
  151. package/lib/typescript/src/types/CellKey.d.ts +10 -0
  152. package/lib/typescript/src/types/CellKey.d.ts.map +1 -0
  153. package/lib/typescript/src/types/CellType.d.ts +11 -0
  154. package/lib/typescript/src/types/CellType.d.ts.map +1 -0
  155. package/lib/typescript/src/types/VisibleRange.d.ts +10 -0
  156. package/lib/typescript/src/types/VisibleRange.d.ts.map +1 -0
  157. package/lib/typescript/src/types/VisibleRangeInput.d.ts +35 -0
  158. package/lib/typescript/src/types/VisibleRangeInput.d.ts.map +1 -0
  159. package/lib/typescript/src/types/index.d.ts +8 -0
  160. package/lib/typescript/src/types/index.d.ts.map +1 -0
  161. package/lib/typescript/src/types/layout/LayoutRect.d.ts +15 -0
  162. package/lib/typescript/src/types/layout/LayoutRect.d.ts.map +1 -0
  163. package/lib/typescript/src/types/layout/LinearLayoutInput.d.ts +10 -0
  164. package/lib/typescript/src/types/layout/LinearLayoutInput.d.ts.map +1 -0
  165. package/lib/typescript/src/types/layout/MainAxisPadding.d.ts +20 -0
  166. package/lib/typescript/src/types/layout/MainAxisPadding.d.ts.map +1 -0
  167. package/lib/typescript/src/types/layout/index.d.ts +4 -0
  168. package/lib/typescript/src/types/layout/index.d.ts.map +1 -0
  169. package/lib/typescript/src/types/recycler/RecyclerCellInstance.d.ts +37 -0
  170. package/lib/typescript/src/types/recycler/RecyclerCellInstance.d.ts.map +1 -0
  171. package/lib/typescript/src/types/recycler/RecyclerItemRenderer.d.ts +8 -0
  172. package/lib/typescript/src/types/recycler/RecyclerItemRenderer.d.ts.map +1 -0
  173. package/lib/typescript/src/types/recycler/RecyclerListProps.d.ts +66 -0
  174. package/lib/typescript/src/types/recycler/RecyclerListProps.d.ts.map +1 -0
  175. package/lib/typescript/src/types/recycler/index.d.ts +4 -0
  176. package/lib/typescript/src/types/recycler/index.d.ts.map +1 -0
  177. package/lib/typescript/src/types/scroll/ScrollMetrics.d.ts +15 -0
  178. package/lib/typescript/src/types/scroll/ScrollMetrics.d.ts.map +1 -0
  179. package/lib/typescript/src/types/scroll/index.d.ts +2 -0
  180. package/lib/typescript/src/types/scroll/index.d.ts.map +1 -0
  181. package/lib/typescript/src/windowing/computeVisibleItemRange.d.ts +15 -0
  182. package/lib/typescript/src/windowing/computeVisibleItemRange.d.ts.map +1 -0
  183. package/lib/typescript/src/windowing/index.d.ts +1 -1
  184. package/lib/typescript/src/windowing/index.d.ts.map +1 -1
  185. package/nitrogen/generated/android/c++/JHybridNitroLayoutEngineSpec.cpp +7 -7
  186. package/nitrogen/generated/android/c++/JHybridNitroLayoutEngineSpec.hpp +1 -1
  187. package/nitrogen/generated/android/c++/{JLayoutRectangle.hpp → JLayoutRect.hpp} +10 -10
  188. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/HybridNitroLayoutEngineSpec.kt +1 -1
  189. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolist/{LayoutRectangle.kt → LayoutRect.kt} +5 -5
  190. package/nitrogen/generated/ios/NitroList-Swift-Cxx-Bridge.hpp +14 -14
  191. package/nitrogen/generated/ios/NitroList-Swift-Cxx-Umbrella.hpp +3 -3
  192. package/nitrogen/generated/ios/c++/HybridNitroLayoutEngineSpecSwift.hpp +4 -4
  193. package/nitrogen/generated/ios/swift/HybridNitroLayoutEngineSpec.swift +1 -1
  194. package/nitrogen/generated/ios/swift/HybridNitroLayoutEngineSpec_cxx.swift +5 -5
  195. package/nitrogen/generated/ios/swift/{LayoutRectangle.swift → LayoutRect.swift} +5 -5
  196. package/nitrogen/generated/shared/c++/HybridNitroLayoutEngineSpec.hpp +4 -4
  197. package/nitrogen/generated/shared/c++/{LayoutRectangle.hpp → LayoutRect.hpp} +11 -11
  198. package/package.json +1 -1
  199. package/src/cell/Cell.ts +13 -4
  200. package/src/cell/CellKeyGenerator.ts +17 -0
  201. package/src/cell/CellRecycler.ts +53 -43
  202. package/src/cell/createCell.ts +15 -0
  203. package/src/cell/index.ts +5 -0
  204. package/src/getVisibleIndices.ts +4 -2
  205. package/src/hooks/usePersistentCallback.ts +37 -0
  206. package/src/index.ts +1 -2
  207. package/src/layout/MutableLinearLayout.ts +91 -58
  208. package/src/layout/constants/layoutDefaults.ts +12 -0
  209. package/src/layout/index.ts +1 -4
  210. package/src/native/NitroList.types.ts +3 -2
  211. package/src/recycler/CellPool.ts +47 -0
  212. package/src/recycler/RecyclerList.tsx +304 -0
  213. package/src/specs/nitro-layout-engine.nitro.ts +2 -2
  214. package/src/types/Axis.ts +10 -0
  215. package/src/types/CellKey.ts +9 -0
  216. package/src/types/CellType.ts +10 -0
  217. package/src/types/VisibleRange.ts +9 -0
  218. package/src/types/VisibleRangeInput.ts +39 -0
  219. package/src/types/index.ts +15 -0
  220. package/src/types/layout/LayoutRect.ts +14 -0
  221. package/src/types/layout/LinearLayoutInput.ts +12 -0
  222. package/src/types/layout/MainAxisPadding.ts +23 -0
  223. package/src/types/layout/index.ts +3 -0
  224. package/src/types/recycler/RecyclerCellInstance.ts +40 -0
  225. package/src/types/recycler/RecyclerItemRenderer.ts +8 -0
  226. package/src/types/recycler/RecyclerListProps.ts +74 -0
  227. package/src/types/recycler/index.ts +3 -0
  228. package/src/types/scroll/ScrollMetrics.ts +18 -0
  229. package/src/types/scroll/index.ts +1 -0
  230. package/src/windowing/computeVisibleItemRange.ts +78 -0
  231. package/src/windowing/index.ts +1 -1
  232. package/lib/commonjs/RecyclerList.internal.js +0 -25
  233. package/lib/commonjs/RecyclerList.internal.js.map +0 -1
  234. package/lib/commonjs/RecyclerList.js +0 -171
  235. package/lib/commonjs/RecyclerList.js.map +0 -1
  236. package/lib/commonjs/RecyclerList.types.js.map +0 -1
  237. package/lib/commonjs/cell/StableKey.js +0 -10
  238. package/lib/commonjs/cell/StableKey.js.map +0 -1
  239. package/lib/commonjs/hooks/useCellRenderer.js +0 -62
  240. package/lib/commonjs/hooks/useCellRenderer.js.map +0 -1
  241. package/lib/commonjs/hooks/useStableCallback.js +0 -13
  242. package/lib/commonjs/hooks/useStableCallback.js.map +0 -1
  243. package/lib/commonjs/layout/EstimatedLayoutProvider.js +0 -30
  244. package/lib/commonjs/layout/EstimatedLayoutProvider.js.map +0 -1
  245. package/lib/commonjs/layout/LayoutEngine.js +0 -21
  246. package/lib/commonjs/layout/LayoutEngine.js.map +0 -1
  247. package/lib/commonjs/layout/LayoutRectangle.js +0 -2
  248. package/lib/commonjs/viewability/ViewabilityHelper.js +0 -121
  249. package/lib/commonjs/viewability/ViewabilityHelper.js.map +0 -1
  250. package/lib/commonjs/windowing/findVisibleIndexRange.js +0 -48
  251. package/lib/commonjs/windowing/findVisibleIndexRange.js.map +0 -1
  252. package/lib/module/RecyclerList.internal.js +0 -22
  253. package/lib/module/RecyclerList.internal.js.map +0 -1
  254. package/lib/module/RecyclerList.js +0 -166
  255. package/lib/module/RecyclerList.js.map +0 -1
  256. package/lib/module/RecyclerList.types.js +0 -4
  257. package/lib/module/RecyclerList.types.js.map +0 -1
  258. package/lib/module/cell/StableKey.js +0 -6
  259. package/lib/module/cell/StableKey.js.map +0 -1
  260. package/lib/module/hooks/useCellRenderer.js +0 -58
  261. package/lib/module/hooks/useCellRenderer.js.map +0 -1
  262. package/lib/module/hooks/useStableCallback.js +0 -9
  263. package/lib/module/hooks/useStableCallback.js.map +0 -1
  264. package/lib/module/layout/EstimatedLayoutProvider.js +0 -25
  265. package/lib/module/layout/EstimatedLayoutProvider.js.map +0 -1
  266. package/lib/module/layout/LayoutEngine.js +0 -17
  267. package/lib/module/layout/LayoutEngine.js.map +0 -1
  268. package/lib/module/layout/LayoutProvider.js +0 -4
  269. package/lib/module/layout/LayoutRectangle.js +0 -2
  270. package/lib/module/viewability/ViewabilityHelper.js +0 -116
  271. package/lib/module/viewability/ViewabilityHelper.js.map +0 -1
  272. package/lib/module/windowing/findVisibleIndexRange.js +0 -44
  273. package/lib/module/windowing/findVisibleIndexRange.js.map +0 -1
  274. package/lib/typescript/src/RecyclerList.d.ts +0 -26
  275. package/lib/typescript/src/RecyclerList.d.ts.map +0 -1
  276. package/lib/typescript/src/RecyclerList.internal.d.ts +0 -9
  277. package/lib/typescript/src/RecyclerList.internal.d.ts.map +0 -1
  278. package/lib/typescript/src/RecyclerList.types.d.ts +0 -18
  279. package/lib/typescript/src/RecyclerList.types.d.ts.map +0 -1
  280. package/lib/typescript/src/__tests__/windowing/findVisibleIndexRange.test.d.ts +0 -2
  281. package/lib/typescript/src/__tests__/windowing/findVisibleIndexRange.test.d.ts.map +0 -1
  282. package/lib/typescript/src/cell/StableKey.d.ts +0 -2
  283. package/lib/typescript/src/cell/StableKey.d.ts.map +0 -1
  284. package/lib/typescript/src/hooks/useCellRenderer.d.ts +0 -19
  285. package/lib/typescript/src/hooks/useCellRenderer.d.ts.map +0 -1
  286. package/lib/typescript/src/hooks/useStableCallback.d.ts +0 -2
  287. package/lib/typescript/src/hooks/useStableCallback.d.ts.map +0 -1
  288. package/lib/typescript/src/layout/EstimatedLayoutProvider.d.ts +0 -15
  289. package/lib/typescript/src/layout/EstimatedLayoutProvider.d.ts.map +0 -1
  290. package/lib/typescript/src/layout/LayoutEngine.d.ts +0 -10
  291. package/lib/typescript/src/layout/LayoutEngine.d.ts.map +0 -1
  292. package/lib/typescript/src/layout/LayoutProvider.d.ts +0 -16
  293. package/lib/typescript/src/layout/LayoutProvider.d.ts.map +0 -1
  294. package/lib/typescript/src/layout/LayoutRectangle.d.ts +0 -11
  295. package/lib/typescript/src/layout/LayoutRectangle.d.ts.map +0 -1
  296. package/lib/typescript/src/viewability/ViewabilityHelper.d.ts +0 -50
  297. package/lib/typescript/src/viewability/ViewabilityHelper.d.ts.map +0 -1
  298. package/lib/typescript/src/windowing/findVisibleIndexRange.d.ts +0 -11
  299. package/lib/typescript/src/windowing/findVisibleIndexRange.d.ts.map +0 -1
  300. package/src/RecyclerList.internal.ts +0 -38
  301. package/src/RecyclerList.tsx +0 -252
  302. package/src/RecyclerList.types.ts +0 -24
  303. package/src/__tests__/windowing/findVisibleIndexRange.test.ts +0 -55
  304. package/src/cell/StableKey.ts +0 -6
  305. package/src/hooks/useCellRenderer.ts +0 -86
  306. package/src/hooks/useStableCallback.ts +0 -13
  307. package/src/layout/EstimatedLayoutProvider.ts +0 -35
  308. package/src/layout/LayoutEngine.ts +0 -21
  309. package/src/layout/LayoutProvider.ts +0 -17
  310. package/src/layout/LayoutRectangle.ts +0 -10
  311. package/src/viewability/ViewabilityHelper.ts +0 -130
  312. package/src/windowing/findVisibleIndexRange.ts +0 -60
@@ -1,5 +1,5 @@
1
1
  ///
2
- /// JLayoutRectangle.hpp
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 "LayoutRectangle.hpp"
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 "LayoutRectangle" and the the Kotlin data class "LayoutRectangle".
20
+ * The C++ JNI bridge between the C++ struct "LayoutRect" and the the Kotlin data class "LayoutRect".
21
21
  */
22
- struct JLayoutRectangle final: public jni::JavaClass<JLayoutRectangle> {
22
+ struct JLayoutRect final: public jni::JavaClass<JLayoutRect> {
23
23
  public:
24
- static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrolist/LayoutRectangle;";
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 LayoutRectangle by copying all values to C++.
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
- LayoutRectangle toCpp() const {
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 LayoutRectangle(
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<JLayoutRectangle::javaobject> fromCpp(const LayoutRectangle& value) {
56
- using JSignature = JLayoutRectangle(double, double, double, double);
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(
@@ -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<LayoutRectangle>
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
- /// LayoutRectangle.kt
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 "LayoutRectangle".
15
+ * Represents the JavaScript object/struct "LayoutRect".
16
16
  */
17
17
  @DoNotStrip
18
18
  @Keep
19
- data class LayoutRectangle(
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): LayoutRectangle {
44
- return LayoutRectangle(x, y, width, height)
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 `LayoutRectangle` to properly resolve imports.
14
- namespace margelo::nitro::nitrolist { struct LayoutRectangle; }
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 "LayoutRectangle.hpp"
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<LayoutRectangle>
34
+ // pragma MARK: std::vector<LayoutRect>
35
35
  /**
36
- * Specialized version of `std::vector<LayoutRectangle>`.
36
+ * Specialized version of `std::vector<LayoutRect>`.
37
37
  */
38
- using std__vector_LayoutRectangle_ = std::vector<LayoutRectangle>;
39
- inline std::vector<LayoutRectangle> create_std__vector_LayoutRectangle_(size_t size) noexcept {
40
- std::vector<LayoutRectangle> 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<LayoutRectangle>>
69
- using Result_std__vector_LayoutRectangle__ = Result<std::vector<LayoutRectangle>>;
70
- inline Result_std__vector_LayoutRectangle__ create_Result_std__vector_LayoutRectangle__(const std::vector<LayoutRectangle>& value) noexcept {
71
- return Result<std::vector<LayoutRectangle>>::withValue(value);
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 Result_std__vector_LayoutRectangle__ create_Result_std__vector_LayoutRectangle__(const std::exception_ptr& error) noexcept {
74
- return Result<std::vector<LayoutRectangle>>::withError(error);
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 `LayoutRectangle` to properly resolve imports.
14
- namespace margelo::nitro::nitrolist { struct LayoutRectangle; }
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 "LayoutRectangle.hpp"
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 `LayoutRectangle` to properly resolve imports.
16
- namespace margelo::nitro::nitrolist { struct LayoutRectangle; }
15
+ // Forward declaration of `LayoutRect` to properly resolve imports.
16
+ namespace margelo::nitro::nitrolist { struct LayoutRect; }
17
17
 
18
- #include "LayoutRectangle.hpp"
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<LayoutRectangle> computeLayout(double containerWidth, const std::vector<double>& itemHeights) override {
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 -> [LayoutRectangle]
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.Result_std__vector_LayoutRectangle__ {
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.std__vector_LayoutRectangle_ in
125
- var __vector = bridge.create_std__vector_LayoutRectangle_(__result.count)
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.create_Result_std__vector_LayoutRectangle__(__resultCpp)
131
+ return bridge.create_Result_std__vector_LayoutRect__(__resultCpp)
132
132
  } catch (let __error) {
133
133
  let __exceptionPtr = __error.toCpp()
134
- return bridge.create_Result_std__vector_LayoutRectangle__(__exceptionPtr)
134
+ return bridge.create_Result_std__vector_LayoutRect__(__exceptionPtr)
135
135
  }
136
136
  }
137
137
  }
@@ -1,5 +1,5 @@
1
1
  ///
2
- /// LayoutRectangle.swift
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 `LayoutRectangle`, backed by a C++ struct.
12
+ * Represents an instance of `LayoutRect`, backed by a C++ struct.
13
13
  */
14
- public typealias LayoutRectangle = margelo.nitro.nitrolist.LayoutRectangle
14
+ public typealias LayoutRect = margelo.nitro.nitrolist.LayoutRect
15
15
 
16
- public extension LayoutRectangle {
16
+ public extension LayoutRect {
17
17
  private typealias bridge = margelo.nitro.nitrolist.bridge.swift
18
18
 
19
19
  /**
20
- * Create a new instance of `LayoutRectangle`.
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 `LayoutRectangle` to properly resolve imports.
17
- namespace margelo::nitro::nitrolist { struct LayoutRectangle; }
16
+ // Forward declaration of `LayoutRect` to properly resolve imports.
17
+ namespace margelo::nitro::nitrolist { struct LayoutRect; }
18
18
 
19
- #include "LayoutRectangle.hpp"
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<LayoutRectangle> computeLayout(double containerWidth, const std::vector<double>& itemHeights) = 0;
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
- /// LayoutRectangle.hpp
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 (LayoutRectangle).
38
+ * A struct which can be represented as a JavaScript object (LayoutRect).
39
39
  */
40
- struct LayoutRectangle final {
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
- LayoutRectangle() = default;
49
- explicit LayoutRectangle(double x, double y, double width, double height): x(x), y(y), width(width), height(height) {}
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 LayoutRectangle& lhs, const LayoutRectangle& rhs) = default;
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++ LayoutRectangle <> JS LayoutRectangle (object)
59
+ // C++ LayoutRect <> JS LayoutRect (object)
60
60
  template <>
61
- struct JSIConverter<margelo::nitro::nitrolist::LayoutRectangle> final {
62
- static inline margelo::nitro::nitrolist::LayoutRectangle fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
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::LayoutRectangle(
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::LayoutRectangle& arg) {
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-nitro-list",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "react-native-nitro-list is a react native package built with Nitro",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "module": "./lib/module/index.js",
package/src/cell/Cell.ts CHANGED
@@ -1,14 +1,23 @@
1
1
  /**
2
2
  * Physical reusable cell.
3
- * Mirrors FlashList's Cell abstraction.
3
+ * Represents a single mounted view instance.
4
4
  */
5
5
  export interface Cell {
6
- /** Stable physical identity (never changes) */
6
+ /**
7
+ * Stable physical identity.
8
+ * Used as React key. NEVER changes.
9
+ */
7
10
  readonly key: string
8
11
 
9
- /** Logical data index currently bound */
12
+ /**
13
+ * Logical data index currently bound.
14
+ * Changes as the cell is recycled.
15
+ */
10
16
  index: number
11
17
 
12
- /** Compatibility type (row, header, etc.) */
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
+ }
@@ -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
- * Owns physical cell reuse.
7
- * Stateful, imperative, React-agnostic.
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
- private readonly activeCells = new Map<number, Cell>()
13
- private readonly reusableCellsByType = new Map<string, Cell[]>()
14
- private readonly orderedCells: Cell[] = []
15
- private nextCellId = 0
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 visible indices against existing cells.
19
- * Returns a stable ordered snapshot.
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
- reconcile(
22
- visibleIndices: readonly number[],
23
- getCellType: (index: number) => string
29
+ reconcileRange(
30
+ startIndex: number,
31
+ endIndex: number,
32
+ resolveCellType: (index: number) => string
24
33
  ): readonly Cell[] {
25
- const visibleSet = new Set(visibleIndices)
34
+ const nextActive: Cell[] = []
26
35
 
27
- // 1️⃣ Release cells no longer visible
28
- for (const [index, cell] of this.activeCells) {
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
- this.activeCells.delete(index)
39
+ for (let index = startIndex; index <= endIndex; index++) {
40
+ unusedIndices.delete(index)
32
41
 
33
- const orderedIndex = this.orderedCells.indexOf(cell)
34
- if (orderedIndex !== -1) {
35
- this.orderedCells.splice(orderedIndex, 1)
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 pool = this.reusableCellsByType.get(cell.type) ?? []
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
- const type = getCellType(index)
48
- const pool = this.reusableCellsByType.get(type)
49
- let cell = pool?.pop()
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 (!cell) {
52
- cell = {
53
- key: `cell-${this.nextCellId++}`,
54
- type,
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.activeCells.set(index, cell)
61
- this.orderedCells.push(cell)
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 this.orderedCells
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
+ }
@@ -0,0 +1,5 @@
1
+ // Public cell-layer exports
2
+
3
+ export type { Cell } from './Cell'
4
+ export { CellRecycler } from './CellRecycler'
5
+ export { createCell } from './createCell'
@@ -1,4 +1,6 @@
1
- import type { LayoutRectangle } from './layout/LayoutRectangle'
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 LayoutRectangle[],
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'