@shopify/flash-list 2.0.0-alpha.2 → 2.0.0-alpha.21

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 (329) hide show
  1. package/README.md +67 -96
  2. package/android/src/main/kotlin/com/shopify/reactnative/flash_list/BlankAreaEvent.kt +2 -2
  3. package/dist/AnimatedFlashList.d.ts +0 -1
  4. package/dist/AnimatedFlashList.d.ts.map +1 -1
  5. package/dist/AnimatedFlashList.js +3 -3
  6. package/dist/AnimatedFlashList.js.map +1 -1
  7. package/dist/FlashList.d.ts +9 -0
  8. package/dist/FlashList.d.ts.map +1 -1
  9. package/dist/FlashList.js +22 -3
  10. package/dist/FlashList.js.map +1 -1
  11. package/dist/FlashListProps.d.ts +33 -13
  12. package/dist/FlashListProps.d.ts.map +1 -1
  13. package/dist/FlashListProps.js.map +1 -1
  14. package/dist/FlashListRef.d.ts +305 -0
  15. package/dist/FlashListRef.d.ts.map +1 -0
  16. package/dist/FlashListRef.js +3 -0
  17. package/dist/FlashListRef.js.map +1 -0
  18. package/dist/GridLayoutProviderWithProps.js +1 -2
  19. package/dist/GridLayoutProviderWithProps.js.map +1 -1
  20. package/dist/MasonryFlashList.d.ts +2 -2
  21. package/dist/MasonryFlashList.d.ts.map +1 -1
  22. package/dist/MasonryFlashList.js.map +1 -1
  23. package/dist/PureComponentWrapper.js +1 -1
  24. package/dist/PureComponentWrapper.js.map +1 -1
  25. package/dist/__tests__/AverageWindow.test.js.map +1 -1
  26. package/dist/__tests__/ConsecutiveNumbers.test.d.ts +2 -0
  27. package/dist/__tests__/ConsecutiveNumbers.test.d.ts.map +1 -0
  28. package/dist/__tests__/ConsecutiveNumbers.test.js +224 -0
  29. package/dist/__tests__/ConsecutiveNumbers.test.js.map +1 -0
  30. package/dist/__tests__/FlashList.test.js.map +1 -1
  31. package/dist/__tests__/GridLayoutManager.test.d.ts +2 -0
  32. package/dist/__tests__/GridLayoutManager.test.d.ts.map +1 -0
  33. package/dist/__tests__/GridLayoutManager.test.js +69 -0
  34. package/dist/__tests__/GridLayoutManager.test.js.map +1 -0
  35. package/dist/__tests__/GridLayoutProviderWithProps.test.js.map +1 -1
  36. package/dist/__tests__/LayoutCommitObserver.test.d.ts +2 -0
  37. package/dist/__tests__/LayoutCommitObserver.test.d.ts.map +1 -0
  38. package/dist/__tests__/LayoutCommitObserver.test.js +35 -0
  39. package/dist/__tests__/LayoutCommitObserver.test.js.map +1 -0
  40. package/dist/__tests__/LinearLayoutManager.test.d.ts +2 -0
  41. package/dist/__tests__/LinearLayoutManager.test.d.ts.map +1 -0
  42. package/dist/__tests__/LinearLayoutManager.test.js +140 -0
  43. package/dist/__tests__/LinearLayoutManager.test.js.map +1 -0
  44. package/dist/__tests__/MasonryFlashList.test.js.map +1 -1
  45. package/dist/__tests__/MasonryLayoutManager.test.d.ts +2 -0
  46. package/dist/__tests__/MasonryLayoutManager.test.d.ts.map +1 -0
  47. package/dist/__tests__/MasonryLayoutManager.test.js +148 -0
  48. package/dist/__tests__/MasonryLayoutManager.test.js.map +1 -0
  49. package/dist/__tests__/RecyclerView.test.d.ts +2 -0
  50. package/dist/__tests__/RecyclerView.test.d.ts.map +1 -0
  51. package/dist/__tests__/RecyclerView.test.js +103 -0
  52. package/dist/__tests__/RecyclerView.test.js.map +1 -0
  53. package/dist/__tests__/RenderStackManager.test.d.ts +2 -0
  54. package/dist/__tests__/RenderStackManager.test.d.ts.map +1 -0
  55. package/dist/__tests__/RenderStackManager.test.js +485 -0
  56. package/dist/__tests__/RenderStackManager.test.js.map +1 -0
  57. package/dist/__tests__/ViewabilityHelper.test.js.map +1 -1
  58. package/dist/__tests__/findVisibleIndex.test.d.ts +2 -0
  59. package/dist/__tests__/findVisibleIndex.test.d.ts.map +1 -0
  60. package/dist/__tests__/findVisibleIndex.test.js +259 -0
  61. package/dist/__tests__/findVisibleIndex.test.js.map +1 -0
  62. package/dist/__tests__/helpers/createLayoutManager.d.ts +34 -0
  63. package/dist/__tests__/helpers/createLayoutManager.d.ts.map +1 -0
  64. package/dist/__tests__/helpers/createLayoutManager.js +110 -0
  65. package/dist/__tests__/helpers/createLayoutManager.js.map +1 -0
  66. package/dist/__tests__/helpers/mountFlashList.d.ts +2 -2
  67. package/dist/__tests__/helpers/mountFlashList.d.ts.map +1 -1
  68. package/dist/__tests__/helpers/mountFlashList.js +2 -2
  69. package/dist/__tests__/helpers/mountFlashList.js.map +1 -1
  70. package/dist/__tests__/helpers/mountMasonryFlashList.d.ts +2 -2
  71. package/dist/__tests__/helpers/mountMasonryFlashList.d.ts.map +1 -1
  72. package/dist/__tests__/helpers/mountMasonryFlashList.js +2 -2
  73. package/dist/__tests__/helpers/mountMasonryFlashList.js.map +1 -1
  74. package/dist/__tests__/useBlankAreaTracker.test.js.map +1 -1
  75. package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts +2 -0
  76. package/dist/__tests__/useUnmountAwareCallbacks.test.d.ts.map +1 -0
  77. package/dist/__tests__/useUnmountAwareCallbacks.test.js +185 -0
  78. package/dist/__tests__/useUnmountAwareCallbacks.test.js.map +1 -0
  79. package/dist/benchmark/AutoScrollHelper.js +2 -2
  80. package/dist/benchmark/AutoScrollHelper.js.map +1 -1
  81. package/dist/benchmark/JSFPSMonitor.js.map +1 -1
  82. package/dist/benchmark/roundToDecimalPlaces.js +1 -2
  83. package/dist/benchmark/roundToDecimalPlaces.js.map +1 -1
  84. package/dist/benchmark/useBenchmark.js +2 -28
  85. package/dist/benchmark/useBenchmark.js.map +1 -1
  86. package/dist/benchmark/useBlankAreaTracker.js +1 -2
  87. package/dist/benchmark/useBlankAreaTracker.js.map +1 -1
  88. package/dist/benchmark/useDataMultiplier.js +1 -2
  89. package/dist/benchmark/useDataMultiplier.js.map +1 -1
  90. package/dist/benchmark/useFlatListBenchmark.d.ts +0 -1
  91. package/dist/benchmark/useFlatListBenchmark.d.ts.map +1 -1
  92. package/dist/benchmark/useFlatListBenchmark.js +9 -9
  93. package/dist/benchmark/useFlatListBenchmark.js.map +1 -1
  94. package/dist/enableNewCore.d.ts.map +1 -1
  95. package/dist/enableNewCore.js +4 -4
  96. package/dist/enableNewCore.js.map +1 -1
  97. package/dist/errors/CustomError.js.map +1 -1
  98. package/dist/index.d.ts +4 -1
  99. package/dist/index.d.ts.map +1 -1
  100. package/dist/index.js +11 -3
  101. package/dist/index.js.map +1 -1
  102. package/dist/native/auto-layout/AutoLayoutView.d.ts +1 -1
  103. package/dist/native/auto-layout/AutoLayoutView.d.ts.map +1 -1
  104. package/dist/native/auto-layout/AutoLayoutView.js +1 -1
  105. package/dist/native/auto-layout/AutoLayoutView.js.map +1 -1
  106. package/dist/native/auto-layout/AutoLayoutViewNativeComponent.d.ts.map +1 -1
  107. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts +1 -1
  108. package/dist/native/auto-layout/AutoLayoutViewNativeComponentProps.d.ts.map +1 -1
  109. package/dist/native/config/PlatformHelper.android.d.ts +2 -0
  110. package/dist/native/config/PlatformHelper.android.d.ts.map +1 -1
  111. package/dist/native/config/PlatformHelper.android.js +2 -0
  112. package/dist/native/config/PlatformHelper.android.js.map +1 -1
  113. package/dist/native/config/PlatformHelper.d.ts +2 -0
  114. package/dist/native/config/PlatformHelper.d.ts.map +1 -1
  115. package/dist/native/config/PlatformHelper.ios.d.ts +2 -0
  116. package/dist/native/config/PlatformHelper.ios.d.ts.map +1 -1
  117. package/dist/native/config/PlatformHelper.ios.js +2 -0
  118. package/dist/native/config/PlatformHelper.ios.js.map +1 -1
  119. package/dist/native/config/PlatformHelper.js +2 -0
  120. package/dist/native/config/PlatformHelper.js.map +1 -1
  121. package/dist/native/config/PlatformHelper.web.d.ts +2 -0
  122. package/dist/native/config/PlatformHelper.web.d.ts.map +1 -1
  123. package/dist/native/config/PlatformHelper.web.js +3 -1
  124. package/dist/native/config/PlatformHelper.web.js.map +1 -1
  125. package/dist/recyclerview/LayoutCommitObserver.d.ts +12 -0
  126. package/dist/recyclerview/LayoutCommitObserver.d.ts.map +1 -0
  127. package/dist/recyclerview/LayoutCommitObserver.js +62 -0
  128. package/dist/recyclerview/LayoutCommitObserver.js.map +1 -0
  129. package/dist/recyclerview/RecyclerView.d.ts +3 -2
  130. package/dist/recyclerview/RecyclerView.d.ts.map +1 -1
  131. package/dist/recyclerview/RecyclerView.js +133 -69
  132. package/dist/recyclerview/RecyclerView.js.map +1 -1
  133. package/dist/recyclerview/RecyclerViewContextProvider.d.ts +41 -7
  134. package/dist/recyclerview/RecyclerViewContextProvider.d.ts.map +1 -1
  135. package/dist/recyclerview/RecyclerViewContextProvider.js +6 -2
  136. package/dist/recyclerview/RecyclerViewContextProvider.js.map +1 -1
  137. package/dist/recyclerview/RecyclerViewManager.d.ts +31 -7
  138. package/dist/recyclerview/RecyclerViewManager.d.ts.map +1 -1
  139. package/dist/recyclerview/RecyclerViewManager.js +154 -117
  140. package/dist/recyclerview/RecyclerViewManager.js.map +1 -1
  141. package/dist/recyclerview/RecyclerViewProps.d.ts +1 -1
  142. package/dist/recyclerview/RecyclerViewProps.d.ts.map +1 -1
  143. package/dist/recyclerview/RenderStackManager.d.ts +86 -0
  144. package/dist/recyclerview/RenderStackManager.d.ts.map +1 -0
  145. package/dist/recyclerview/RenderStackManager.js +343 -0
  146. package/dist/recyclerview/RenderStackManager.js.map +1 -0
  147. package/dist/recyclerview/ViewHolder.d.ts.map +1 -1
  148. package/dist/recyclerview/ViewHolder.js +8 -6
  149. package/dist/recyclerview/ViewHolder.js.map +1 -1
  150. package/dist/recyclerview/ViewHolderCollection.d.ts +10 -4
  151. package/dist/recyclerview/ViewHolderCollection.d.ts.map +1 -1
  152. package/dist/recyclerview/ViewHolderCollection.js +26 -10
  153. package/dist/recyclerview/ViewHolderCollection.js.map +1 -1
  154. package/dist/recyclerview/components/ScrollAnchor.d.ts +2 -1
  155. package/dist/recyclerview/components/ScrollAnchor.d.ts.map +1 -1
  156. package/dist/recyclerview/components/ScrollAnchor.js +12 -9
  157. package/dist/recyclerview/components/ScrollAnchor.js.map +1 -1
  158. package/dist/recyclerview/components/StickyHeaders.d.ts +2 -2
  159. package/dist/recyclerview/components/StickyHeaders.d.ts.map +1 -1
  160. package/dist/recyclerview/components/StickyHeaders.js +44 -45
  161. package/dist/recyclerview/components/StickyHeaders.js.map +1 -1
  162. package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts +1 -1
  163. package/dist/recyclerview/helpers/ConsecutiveNumbers.d.ts.map +1 -1
  164. package/dist/recyclerview/helpers/ConsecutiveNumbers.js +2 -2
  165. package/dist/recyclerview/helpers/ConsecutiveNumbers.js.map +1 -1
  166. package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts +48 -2
  167. package/dist/recyclerview/helpers/EngagedIndicesTracker.d.ts.map +1 -1
  168. package/dist/recyclerview/helpers/EngagedIndicesTracker.js +89 -19
  169. package/dist/recyclerview/helpers/EngagedIndicesTracker.js.map +1 -1
  170. package/dist/recyclerview/helpers/RenderTimeTracker.d.ts +11 -0
  171. package/dist/recyclerview/helpers/RenderTimeTracker.d.ts.map +1 -0
  172. package/dist/recyclerview/helpers/RenderTimeTracker.js +42 -0
  173. package/dist/recyclerview/helpers/RenderTimeTracker.js.map +1 -0
  174. package/dist/recyclerview/helpers/VelocityTracker.d.ts +29 -0
  175. package/dist/recyclerview/helpers/VelocityTracker.d.ts.map +1 -0
  176. package/dist/recyclerview/helpers/VelocityTracker.js +70 -0
  177. package/dist/recyclerview/helpers/VelocityTracker.js.map +1 -0
  178. package/dist/recyclerview/hooks/useBoundDetection.d.ts +1 -3
  179. package/dist/recyclerview/hooks/useBoundDetection.d.ts.map +1 -1
  180. package/dist/recyclerview/hooks/useBoundDetection.js +60 -28
  181. package/dist/recyclerview/hooks/useBoundDetection.js.map +1 -1
  182. package/dist/recyclerview/hooks/useLayoutState.d.ts +3 -1
  183. package/dist/recyclerview/hooks/useLayoutState.d.ts.map +1 -1
  184. package/dist/recyclerview/hooks/useLayoutState.js +6 -5
  185. package/dist/recyclerview/hooks/useLayoutState.js.map +1 -1
  186. package/dist/recyclerview/hooks/useMappingHelper.d.ts +9 -0
  187. package/dist/recyclerview/hooks/useMappingHelper.d.ts.map +1 -0
  188. package/dist/recyclerview/hooks/useMappingHelper.js +19 -0
  189. package/dist/recyclerview/hooks/useMappingHelper.js.map +1 -0
  190. package/dist/recyclerview/hooks/useOnLoad.d.ts +2 -2
  191. package/dist/recyclerview/hooks/useOnLoad.d.ts.map +1 -1
  192. package/dist/recyclerview/hooks/useOnLoad.js +9 -10
  193. package/dist/recyclerview/hooks/useOnLoad.js.map +1 -1
  194. package/dist/recyclerview/hooks/useRecyclerViewController.d.ts +5 -49
  195. package/dist/recyclerview/hooks/useRecyclerViewController.d.ts.map +1 -1
  196. package/dist/recyclerview/hooks/useRecyclerViewController.js +343 -191
  197. package/dist/recyclerview/hooks/useRecyclerViewController.js.map +1 -1
  198. package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts +2 -0
  199. package/dist/recyclerview/hooks/useRecyclerViewManager.d.ts.map +1 -1
  200. package/dist/recyclerview/hooks/useRecyclerViewManager.js +11 -1
  201. package/dist/recyclerview/hooks/useRecyclerViewManager.js.map +1 -1
  202. package/dist/recyclerview/hooks/useRecyclingState.d.ts +4 -2
  203. package/dist/recyclerview/hooks/useRecyclingState.d.ts.map +1 -1
  204. package/dist/recyclerview/hooks/useRecyclingState.js +3 -4
  205. package/dist/recyclerview/hooks/useRecyclingState.js.map +1 -1
  206. package/dist/recyclerview/hooks/useSecondaryProps.d.ts +1 -1
  207. package/dist/recyclerview/hooks/useSecondaryProps.d.ts.map +1 -1
  208. package/dist/recyclerview/hooks/useSecondaryProps.js +15 -12
  209. package/dist/recyclerview/hooks/useSecondaryProps.js.map +1 -1
  210. package/dist/recyclerview/hooks/useUnmountAwareCallbacks.d.ts +15 -0
  211. package/dist/recyclerview/hooks/useUnmountAwareCallbacks.d.ts.map +1 -0
  212. package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js +63 -0
  213. package/dist/recyclerview/hooks/useUnmountAwareCallbacks.js.map +1 -0
  214. package/dist/recyclerview/hooks/useUnmountFlag.d.ts +0 -1
  215. package/dist/recyclerview/hooks/useUnmountFlag.d.ts.map +1 -1
  216. package/dist/recyclerview/hooks/useUnmountFlag.js +1 -0
  217. package/dist/recyclerview/hooks/useUnmountFlag.js.map +1 -1
  218. package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts +18 -4
  219. package/dist/recyclerview/layout-managers/GridLayoutManager.d.ts.map +1 -1
  220. package/dist/recyclerview/layout-managers/GridLayoutManager.js +61 -25
  221. package/dist/recyclerview/layout-managers/GridLayoutManager.js.map +1 -1
  222. package/dist/recyclerview/layout-managers/LayoutManager.d.ts +36 -21
  223. package/dist/recyclerview/layout-managers/LayoutManager.d.ts.map +1 -1
  224. package/dist/recyclerview/layout-managers/LayoutManager.js +96 -28
  225. package/dist/recyclerview/layout-managers/LayoutManager.js.map +1 -1
  226. package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts +1 -2
  227. package/dist/recyclerview/layout-managers/LinearLayoutManager.d.ts.map +1 -1
  228. package/dist/recyclerview/layout-managers/LinearLayoutManager.js +3 -3
  229. package/dist/recyclerview/layout-managers/LinearLayoutManager.js.map +1 -1
  230. package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts +9 -1
  231. package/dist/recyclerview/layout-managers/MasonryLayoutManager.d.ts.map +1 -1
  232. package/dist/recyclerview/layout-managers/MasonryLayoutManager.js +30 -16
  233. package/dist/recyclerview/layout-managers/MasonryLayoutManager.js.map +1 -1
  234. package/dist/recyclerview/utils/adjustOffsetForRTL.js +1 -2
  235. package/dist/recyclerview/utils/adjustOffsetForRTL.js.map +1 -1
  236. package/dist/recyclerview/utils/componentUtils.d.ts +1 -1
  237. package/dist/recyclerview/utils/componentUtils.d.ts.map +1 -1
  238. package/dist/recyclerview/utils/componentUtils.js.map +1 -1
  239. package/dist/recyclerview/utils/findVisibleIndex.d.ts.map +1 -1
  240. package/dist/recyclerview/utils/findVisibleIndex.js +3 -5
  241. package/dist/recyclerview/utils/findVisibleIndex.js.map +1 -1
  242. package/dist/recyclerview/utils/measureLayout.d.ts +24 -28
  243. package/dist/recyclerview/utils/measureLayout.d.ts.map +1 -1
  244. package/dist/recyclerview/utils/measureLayout.js +36 -6
  245. package/dist/recyclerview/utils/measureLayout.js.map +1 -1
  246. package/dist/recyclerview/utils/measureLayout.web.d.ts +29 -0
  247. package/dist/recyclerview/utils/measureLayout.web.d.ts.map +1 -0
  248. package/dist/recyclerview/utils/measureLayout.web.js +87 -0
  249. package/dist/recyclerview/utils/measureLayout.web.js.map +1 -0
  250. package/dist/specs/AutoLayoutNativeComponent.d.ts +1 -2
  251. package/dist/specs/AutoLayoutNativeComponent.d.ts.map +1 -1
  252. package/dist/specs/CellContainerNativeComponent.d.ts +0 -1
  253. package/dist/specs/CellContainerNativeComponent.d.ts.map +1 -1
  254. package/dist/tsconfig.tsbuildinfo +1 -1
  255. package/dist/utils/AverageWindow.js.map +1 -1
  256. package/dist/utils/ContentContainerUtils.d.ts.map +1 -1
  257. package/dist/utils/ContentContainerUtils.js.map +1 -1
  258. package/dist/viewability/ViewToken.d.ts +2 -2
  259. package/dist/viewability/ViewToken.d.ts.map +1 -1
  260. package/dist/viewability/ViewabilityHelper.js +1 -1
  261. package/dist/viewability/ViewabilityHelper.js.map +1 -1
  262. package/dist/viewability/ViewabilityManager.d.ts.map +1 -1
  263. package/dist/viewability/ViewabilityManager.js +11 -5
  264. package/dist/viewability/ViewabilityManager.js.map +1 -1
  265. package/jestSetup.js +30 -11
  266. package/package.json +4 -3
  267. package/src/AnimatedFlashList.ts +3 -2
  268. package/src/FlashList.tsx +25 -1
  269. package/src/FlashListProps.ts +42 -11
  270. package/src/FlashListRef.ts +320 -0
  271. package/src/MasonryFlashList.tsx +2 -2
  272. package/src/__tests__/ConsecutiveNumbers.test.ts +232 -0
  273. package/src/__tests__/GridLayoutManager.test.ts +113 -0
  274. package/src/__tests__/LayoutCommitObserver.test.tsx +60 -0
  275. package/src/__tests__/LinearLayoutManager.test.ts +227 -0
  276. package/src/__tests__/MasonryLayoutManager.test.ts +202 -0
  277. package/src/__tests__/RecyclerView.test.tsx +144 -0
  278. package/src/__tests__/RenderStackManager.test.ts +574 -0
  279. package/src/__tests__/findVisibleIndex.test.ts +369 -0
  280. package/src/__tests__/helpers/createLayoutManager.ts +141 -0
  281. package/src/__tests__/useUnmountAwareCallbacks.test.tsx +285 -0
  282. package/src/benchmark/useBenchmark.ts +0 -37
  283. package/src/benchmark/useFlatListBenchmark.ts +2 -2
  284. package/src/enableNewCore.ts +3 -1
  285. package/src/index.ts +14 -3
  286. package/src/native/config/PlatformHelper.android.ts +2 -0
  287. package/src/native/config/PlatformHelper.ios.ts +2 -0
  288. package/src/native/config/PlatformHelper.ts +2 -0
  289. package/src/native/config/PlatformHelper.web.ts +3 -1
  290. package/src/recyclerview/LayoutCommitObserver.tsx +74 -0
  291. package/src/recyclerview/RecyclerView.tsx +178 -89
  292. package/src/recyclerview/RecyclerViewContextProvider.ts +53 -7
  293. package/src/recyclerview/RecyclerViewManager.ts +176 -97
  294. package/src/recyclerview/RecyclerViewProps.ts +2 -1
  295. package/src/recyclerview/RenderStackManager.ts +317 -0
  296. package/src/recyclerview/ViewHolder.tsx +13 -6
  297. package/src/recyclerview/ViewHolderCollection.tsx +45 -16
  298. package/src/recyclerview/components/ScrollAnchor.tsx +24 -11
  299. package/src/recyclerview/components/StickyHeaders.tsx +70 -58
  300. package/src/recyclerview/helpers/ConsecutiveNumbers.ts +2 -2
  301. package/src/recyclerview/helpers/EngagedIndicesTracker.ts +135 -25
  302. package/src/recyclerview/helpers/RenderTimeTracker.ts +42 -0
  303. package/src/recyclerview/helpers/VelocityTracker.ts +77 -0
  304. package/src/recyclerview/hooks/useBoundDetection.ts +74 -25
  305. package/src/recyclerview/hooks/useLayoutState.ts +15 -6
  306. package/src/recyclerview/hooks/useMappingHelper.ts +20 -0
  307. package/src/recyclerview/hooks/useOnLoad.ts +11 -10
  308. package/src/recyclerview/hooks/useRecyclerViewController.tsx +380 -241
  309. package/src/recyclerview/hooks/useRecyclerViewManager.ts +13 -1
  310. package/src/recyclerview/hooks/useRecyclingState.ts +11 -7
  311. package/src/recyclerview/hooks/useSecondaryProps.tsx +12 -7
  312. package/src/recyclerview/hooks/useUnmountAwareCallbacks.ts +73 -0
  313. package/src/recyclerview/hooks/useUnmountFlag.ts +1 -0
  314. package/src/recyclerview/layout-managers/GridLayoutManager.ts +68 -27
  315. package/src/recyclerview/layout-managers/LayoutManager.ts +116 -42
  316. package/src/recyclerview/layout-managers/LinearLayoutManager.ts +12 -8
  317. package/src/recyclerview/layout-managers/MasonryLayoutManager.ts +34 -13
  318. package/src/recyclerview/utils/componentUtils.ts +1 -1
  319. package/src/recyclerview/utils/findVisibleIndex.ts +1 -2
  320. package/src/recyclerview/utils/measureLayout.ts +41 -2
  321. package/src/recyclerview/utils/measureLayout.web.ts +102 -0
  322. package/src/viewability/ViewToken.ts +2 -2
  323. package/src/viewability/ViewabilityHelper.ts +1 -1
  324. package/src/viewability/ViewabilityManager.ts +16 -9
  325. package/dist/recyclerview/RecycleKeyManager.d.ts +0 -82
  326. package/dist/recyclerview/RecycleKeyManager.d.ts.map +0 -1
  327. package/dist/recyclerview/RecycleKeyManager.js +0 -135
  328. package/dist/recyclerview/RecycleKeyManager.js.map +0 -1
  329. package/src/recyclerview/RecycleKeyManager.ts +0 -185
@@ -1,9 +1,10 @@
1
- import { useCallback, useEffect, useMemo } from "react";
2
- import { useRef } from "react";
1
+ import { useCallback, useEffect, useMemo, useRef } from "react";
2
+
3
3
  import { RecyclerViewManager } from "../RecyclerViewManager";
4
- import { RecyclerViewProps } from "../RecyclerViewProps";
5
4
  import { CompatScroller } from "../components/CompatScroller";
6
5
 
6
+ import { useUnmountAwareAnimationFrame } from "./useUnmountAwareCallbacks";
7
+
7
8
  /**
8
9
  * Hook to detect when the scroll position reaches near the start or end of the list
9
10
  * and trigger the appropriate callbacks. This hook is responsible for:
@@ -17,7 +18,6 @@ import { CompatScroller } from "../components/CompatScroller";
17
18
  */
18
19
  export function useBoundDetection<T>(
19
20
  recyclerViewManager: RecyclerViewManager<T>,
20
- props: RecyclerViewProps<T>,
21
21
  scrollViewRef: React.RefObject<CompatScroller>
22
22
  ) {
23
23
  // Track whether we've already triggered the end reached callback to prevent duplicate calls
@@ -26,22 +26,48 @@ export function useBoundDetection<T>(
26
26
  const pendingStartReached = useRef(false);
27
27
  // Track whether we should auto-scroll to bottom when new content is added
28
28
  const pendingAutoscrollToBottom = useRef(false);
29
- const { horizontal, data, maintainVisibleContentPosition } = props;
29
+
30
+ const lastCheckBoundsTime = useRef(Date.now());
31
+
32
+ const { data } = recyclerViewManager.props;
33
+ const { requestAnimationFrame } = useUnmountAwareAnimationFrame();
34
+
35
+ const windowHeight = recyclerViewManager.hasLayout()
36
+ ? recyclerViewManager.getWindowSize().height
37
+ : 0;
38
+
39
+ const contentHeight = recyclerViewManager.hasLayout()
40
+ ? recyclerViewManager.getChildContainerDimensions().height
41
+ : 0;
42
+
43
+ const windowWidth = recyclerViewManager.hasLayout()
44
+ ? recyclerViewManager.getWindowSize().width
45
+ : 0;
46
+
47
+ const contentWidth = recyclerViewManager.hasLayout()
48
+ ? recyclerViewManager.getChildContainerDimensions().width
49
+ : 0;
30
50
 
31
51
  /**
32
52
  * Checks if the scroll position is near the start or end of the list
33
53
  * and triggers appropriate callbacks if configured.
34
54
  */
35
55
  const checkBounds = useCallback(() => {
56
+ lastCheckBoundsTime.current = Date.now();
57
+
58
+ const {
59
+ onEndReached,
60
+ onStartReached,
61
+ maintainVisibleContentPosition,
62
+ horizontal,
63
+ onEndReachedThreshold: onEndReachedThresholdProp,
64
+ onStartReachedThreshold: onStartReachedThresholdProp,
65
+ } = recyclerViewManager.props;
36
66
  // Skip all calculations if neither callback is provided and autoscroll is disabled
37
67
  const autoscrollToBottomThreshold =
38
68
  maintainVisibleContentPosition?.autoscrollToBottomThreshold ?? -1;
39
69
 
40
- if (
41
- !props.onEndReached &&
42
- !props.onStartReached &&
43
- autoscrollToBottomThreshold < 0
44
- ) {
70
+ if (!onEndReached && !onStartReached && autoscrollToBottomThreshold < 0) {
45
71
  return;
46
72
  }
47
73
 
@@ -50,7 +76,7 @@ export function useBoundDetection<T>(
50
76
  recyclerViewManager.getAbsoluteLastScrollOffset();
51
77
  const contentSize = recyclerViewManager.getChildContainerDimensions();
52
78
  const windowSize = recyclerViewManager.getWindowSize();
53
- const isHorizontal = props.horizontal === true;
79
+ const isHorizontal = horizontal === true;
54
80
 
55
81
  // Calculate dimensions based on scroll direction
56
82
  const visibleLength = isHorizontal ? windowSize.width : windowSize.height;
@@ -59,8 +85,8 @@ export function useBoundDetection<T>(
59
85
  recyclerViewManager.firstItemOffset;
60
86
 
61
87
  // Check if we're near the end of the list
62
- if (props.onEndReached) {
63
- const onEndReachedThreshold = props.onEndReachedThreshold ?? 0.5;
88
+ if (onEndReached) {
89
+ const onEndReachedThreshold = onEndReachedThresholdProp ?? 0.5;
64
90
  const endThresholdDistance = onEndReachedThreshold * visibleLength;
65
91
 
66
92
  const isNearEnd =
@@ -69,27 +95,27 @@ export function useBoundDetection<T>(
69
95
 
70
96
  if (isNearEnd && !pendingEndReached.current) {
71
97
  pendingEndReached.current = true;
72
- props.onEndReached();
98
+ onEndReached();
73
99
  }
74
100
  pendingEndReached.current = isNearEnd;
75
101
  }
76
102
 
77
103
  // Check if we're near the start of the list
78
- if (props.onStartReached) {
79
- const onStartReachedThreshold = props.onStartReachedThreshold ?? 0.2;
104
+ if (onStartReached) {
105
+ const onStartReachedThreshold = onStartReachedThresholdProp ?? 0.2;
80
106
  const startThresholdDistance = onStartReachedThreshold * visibleLength;
81
107
 
82
108
  const isNearStart = lastScrollOffset <= startThresholdDistance;
83
109
 
84
110
  if (isNearStart && !pendingStartReached.current) {
85
111
  pendingStartReached.current = true;
86
- props.onStartReached();
112
+ onStartReached();
87
113
  }
88
114
  pendingStartReached.current = isNearStart;
89
115
  }
90
116
 
91
117
  // Handle auto-scrolling to bottom for vertical lists
92
- if (!horizontal) {
118
+ if (!isHorizontal && autoscrollToBottomThreshold >= 0) {
93
119
  const autoscrollToBottomThresholdDistance =
94
120
  autoscrollToBottomThreshold * visibleLength;
95
121
 
@@ -104,22 +130,45 @@ export function useBoundDetection<T>(
104
130
  }
105
131
  }
106
132
  }
107
- }, [recyclerViewManager, props]);
133
+ }, [recyclerViewManager]);
134
+
135
+ const runAutoScrollToBottomCheck = useCallback(() => {
136
+ if (pendingAutoscrollToBottom.current) {
137
+ pendingAutoscrollToBottom.current = false;
138
+ requestAnimationFrame(() => {
139
+ const shouldAnimate =
140
+ recyclerViewManager.props.maintainVisibleContentPosition
141
+ ?.animateAutoScrollToBottom ?? true;
142
+ scrollViewRef.current?.scrollToEnd({
143
+ animated: shouldAnimate,
144
+ });
145
+ });
146
+ }
147
+ }, [requestAnimationFrame, scrollViewRef, recyclerViewManager]);
108
148
 
109
149
  // Reset end reached state when data changes
110
150
  useMemo(() => {
111
151
  pendingEndReached.current = false;
152
+ // needs to run only when data changes
153
+ // eslint-disable-next-line react-hooks/exhaustive-deps
112
154
  }, [data]);
113
155
 
114
156
  // Auto-scroll to bottom when new content is added and we're near the bottom
115
157
  useEffect(() => {
116
- if (pendingAutoscrollToBottom.current) {
117
- requestAnimationFrame(() => {
118
- scrollViewRef.current?.scrollToEnd();
119
- pendingAutoscrollToBottom.current = false;
120
- });
158
+ runAutoScrollToBottomCheck();
159
+ }, [data, runAutoScrollToBottomCheck, windowHeight, windowWidth]);
160
+
161
+ // Since content changes frequently, we try and avoid doing the auto scroll during active scrolls
162
+ useEffect(() => {
163
+ if (Date.now() - lastCheckBoundsTime.current >= 100) {
164
+ runAutoScrollToBottomCheck();
121
165
  }
122
- }, [data]);
166
+ }, [
167
+ contentHeight,
168
+ contentWidth,
169
+ recyclerViewManager.firstItemOffset,
170
+ runAutoScrollToBottomCheck,
171
+ ]);
123
172
 
124
173
  return {
125
174
  checkBounds,
@@ -2,6 +2,13 @@ import { useState, useCallback } from "react";
2
2
 
3
3
  import { useRecyclerViewContext } from "../RecyclerViewContextProvider";
4
4
 
5
+ export type LayoutStateSetter<T> = (
6
+ newValue: T | ((prevValue: T) => T),
7
+ skipParentLayout?: boolean
8
+ ) => void;
9
+
10
+ export type LayoutStateInitialValue<T> = T | (() => T);
11
+
5
12
  /**
6
13
  * Custom hook that combines state management with RecyclerView layout updates.
7
14
  * This hook provides a way to manage state that affects the layout of the RecyclerView,
@@ -13,8 +20,8 @@ import { useRecyclerViewContext } from "../RecyclerViewContextProvider";
13
20
  * - A setter function that updates the state and triggers a layout recalculation
14
21
  */
15
22
  export function useLayoutState<T>(
16
- initialState: T | (() => T)
17
- ): [T, (newValue: T | ((prevValue: T) => T)) => void] {
23
+ initialState: LayoutStateInitialValue<T>
24
+ ): [T, LayoutStateSetter<T>] {
18
25
  // Initialize state with the provided initial value
19
26
  const [state, setState] = useState<T>(initialState);
20
27
  // Get the RecyclerView context for layout management
@@ -28,16 +35,18 @@ export function useLayoutState<T>(
28
35
  * @param newValue - Either a new state value or a function that receives the previous state
29
36
  * and returns the new state
30
37
  */
31
- const setLayoutState = useCallback(
32
- (newValue: T | ((prevValue: T) => T)) => {
38
+ const setLayoutState: LayoutStateSetter<T> = useCallback(
39
+ (newValue, skipParentLayout) => {
33
40
  // Update the state using either the new value or the result of the updater function
34
41
  setState((prevValue) =>
35
42
  typeof newValue === "function"
36
43
  ? (newValue as (prevValue: T) => T)(prevValue)
37
44
  : newValue
38
45
  );
39
- // Trigger a layout recalculation in the RecyclerView
40
- recyclerViewContext?.layout();
46
+ if (!skipParentLayout) {
47
+ // Trigger a layout recalculation in the RecyclerView
48
+ recyclerViewContext?.layout();
49
+ }
41
50
  },
42
51
  [recyclerViewContext]
43
52
  );
@@ -0,0 +1,20 @@
1
+ import { useCallback } from "react";
2
+
3
+ import { useRecyclerViewContext } from "../RecyclerViewContextProvider";
4
+
5
+ /**
6
+ * Returns a function that can help create a mapping key for the items.
7
+ * Useful when doing .map on items to create a list of components.
8
+ * Using this ensures that performance is optimal for FlashList
9
+ */
10
+ export const useMappingHelper = () => {
11
+ const recyclerViewContext = useRecyclerViewContext();
12
+ const getMappingKey = useCallback(
13
+ (itemKey: string | number | bigint, index: number) => {
14
+ return recyclerViewContext ? index : itemKey;
15
+ },
16
+ [recyclerViewContext]
17
+ );
18
+
19
+ return { getMappingKey };
20
+ };
@@ -1,7 +1,9 @@
1
1
  import { useEffect, useMemo, useRef, useState } from "react";
2
+
2
3
  import { RecyclerViewManager } from "../RecyclerViewManager";
3
- import { useUnmountFlag } from "./useUnmountFlag";
4
- //import { ToastAndroid } from "react-native";
4
+
5
+ import { useUnmountAwareAnimationFrame } from "./useUnmountAwareCallbacks";
6
+ // import { ToastAndroid } from "react-native";
5
7
 
6
8
  /**
7
9
  * Hook to track when the RecyclerView has loaded its items and notify when loading is complete.
@@ -19,8 +21,8 @@ export const useOnListLoad = <T>(
19
21
  const loadStartTimeRef = useRef<number>(Date.now());
20
22
  const [isLoaded, setIsLoaded] = useState<boolean>(false);
21
23
  const dataLength = recyclerViewManager.getDataLength();
22
- //const dataCollector = useRef<number[]>([]);
23
- const isUnmounted = useUnmountFlag();
24
+ // const dataCollector = useRef<number[]>([]);
25
+ const { requestAnimationFrame } = useUnmountAwareAnimationFrame();
24
26
  // Track render cycles by collecting elapsed time on each render
25
27
  // useEffect(() => {
26
28
  // const elapsedTimeInMs = Date.now() - loadStartTimeRef.current;
@@ -29,6 +31,7 @@ export const useOnListLoad = <T>(
29
31
 
30
32
  useMemo(() => {
31
33
  loadStartTimeRef.current = Date.now();
34
+ // eslint-disable-next-line react-hooks/exhaustive-deps
32
35
  }, [dataLength]);
33
36
 
34
37
  useOnLoad(recyclerViewManager, () => {
@@ -42,13 +45,11 @@ export const useOnListLoad = <T>(
42
45
  // `onLoad called after ${dataCollectorString}`,
43
46
  // ToastAndroid.SHORT
44
47
  // );
45
- //console.log("----------> dataCollector", dataCollectorString);
46
- //console.log("----------> elapsedTimeInMs", elapsedTimeInMs);
48
+ // console.log("----------> dataCollector", dataCollectorString);
49
+ // console.log("----------> FlashList v2 load in", `${elapsedTimeInMs} ms`);
47
50
  requestAnimationFrame(() => {
48
- if (!isUnmounted.current) {
49
- onLoad?.({ elapsedTimeInMs });
50
- setIsLoaded(true);
51
- }
51
+ onLoad?.({ elapsedTimeInMs });
52
+ setIsLoaded(true);
52
53
  });
53
54
  });
54
55