@leonsilicon/react-native-reanimated-carousel 0.0.0

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 (328) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +652 -0
  3. package/lib/commonjs/components/Carousel.js +2 -0
  4. package/lib/commonjs/components/Carousel.js.map +1 -0
  5. package/lib/commonjs/components/CarouselLayout.js +2 -0
  6. package/lib/commonjs/components/CarouselLayout.js.map +1 -0
  7. package/lib/commonjs/components/ItemLayout.js +2 -0
  8. package/lib/commonjs/components/ItemLayout.js.map +1 -0
  9. package/lib/commonjs/components/ItemRenderer.js +2 -0
  10. package/lib/commonjs/components/ItemRenderer.js.map +1 -0
  11. package/lib/commonjs/components/LazyView.js +2 -0
  12. package/lib/commonjs/components/LazyView.js.map +1 -0
  13. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +2 -0
  14. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +1 -0
  15. package/lib/commonjs/components/Pagination/Basic/index.js +2 -0
  16. package/lib/commonjs/components/Pagination/Basic/index.js.map +1 -0
  17. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js +2 -0
  18. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js.map +1 -0
  19. package/lib/commonjs/components/Pagination/Custom/index.js +2 -0
  20. package/lib/commonjs/components/Pagination/Custom/index.js.map +1 -0
  21. package/lib/commonjs/components/Pagination/index.js +2 -0
  22. package/lib/commonjs/components/Pagination/index.js.map +1 -0
  23. package/lib/commonjs/components/ScrollViewGesture.js +2 -0
  24. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
  25. package/lib/commonjs/constants/index.js +2 -0
  26. package/lib/commonjs/constants/index.js.map +1 -0
  27. package/lib/commonjs/hooks/useAutoPlay.js +2 -0
  28. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -0
  29. package/lib/commonjs/hooks/useCarouselController.js +2 -0
  30. package/lib/commonjs/hooks/useCarouselController.js.map +1 -0
  31. package/lib/commonjs/hooks/useCheckMounted.js +2 -0
  32. package/lib/commonjs/hooks/useCheckMounted.js.map +1 -0
  33. package/lib/commonjs/hooks/useCommonVariables.js +2 -0
  34. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -0
  35. package/lib/commonjs/hooks/useInitProps.js +2 -0
  36. package/lib/commonjs/hooks/useInitProps.js.map +1 -0
  37. package/lib/commonjs/hooks/useLayoutConfig.js +2 -0
  38. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -0
  39. package/lib/commonjs/hooks/useOffsetX.js +2 -0
  40. package/lib/commonjs/hooks/useOffsetX.js.map +1 -0
  41. package/lib/commonjs/hooks/useOnProgressChange.js +2 -0
  42. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -0
  43. package/lib/commonjs/hooks/usePanGestureProxy.js +2 -0
  44. package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
  45. package/lib/commonjs/hooks/usePropsErrorBoundary.js +2 -0
  46. package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -0
  47. package/lib/commonjs/hooks/useSizeResolver.js +2 -0
  48. package/lib/commonjs/hooks/useSizeResolver.js.map +1 -0
  49. package/lib/commonjs/hooks/useUpdateGestureConfig.js +2 -0
  50. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
  51. package/lib/commonjs/hooks/useVisibleRanges.js +2 -0
  52. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -0
  53. package/lib/commonjs/index.js +2 -0
  54. package/lib/commonjs/index.js.map +1 -0
  55. package/lib/commonjs/layouts/index.js +2 -0
  56. package/lib/commonjs/layouts/index.js.map +1 -0
  57. package/lib/commonjs/layouts/normal.js +2 -0
  58. package/lib/commonjs/layouts/normal.js.map +1 -0
  59. package/lib/commonjs/layouts/parallax.js +2 -0
  60. package/lib/commonjs/layouts/parallax.js.map +1 -0
  61. package/lib/commonjs/layouts/stack.js +2 -0
  62. package/lib/commonjs/layouts/stack.js.map +1 -0
  63. package/lib/commonjs/package.json +1 -0
  64. package/lib/commonjs/store/index.js +2 -0
  65. package/lib/commonjs/store/index.js.map +1 -0
  66. package/lib/commonjs/types.js +2 -0
  67. package/lib/commonjs/types.js.map +1 -0
  68. package/lib/commonjs/utils/compute-gesture-translation.js +2 -0
  69. package/lib/commonjs/utils/compute-gesture-translation.js.map +1 -0
  70. package/lib/commonjs/utils/compute-offset-if-data-changed.js +2 -0
  71. package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +1 -0
  72. package/lib/commonjs/utils/compute-offset-if-size-changed.js +2 -0
  73. package/lib/commonjs/utils/compute-offset-if-size-changed.js.map +1 -0
  74. package/lib/commonjs/utils/compute-offset-if-sizes-changed.js +2 -0
  75. package/lib/commonjs/utils/compute-offset-if-sizes-changed.js.map +1 -0
  76. package/lib/commonjs/utils/computed-with-auto-fill-data.js +2 -0
  77. package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
  78. package/lib/commonjs/utils/deal-with-animation.js +2 -0
  79. package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
  80. package/lib/commonjs/utils/handleroffset-direction.js +2 -0
  81. package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
  82. package/lib/commonjs/utils/log.js +2 -0
  83. package/lib/commonjs/utils/log.js.map +1 -0
  84. package/lib/commonjs/utils/sanitize-animation-style.js +2 -0
  85. package/lib/commonjs/utils/sanitize-animation-style.js.map +1 -0
  86. package/lib/commonjs/utils/size-resolver.js +2 -0
  87. package/lib/commonjs/utils/size-resolver.js.map +1 -0
  88. package/lib/module/components/Carousel.js +2 -0
  89. package/lib/module/components/Carousel.js.map +1 -0
  90. package/lib/module/components/CarouselLayout.js +2 -0
  91. package/lib/module/components/CarouselLayout.js.map +1 -0
  92. package/lib/module/components/ItemLayout.js +2 -0
  93. package/lib/module/components/ItemLayout.js.map +1 -0
  94. package/lib/module/components/ItemRenderer.js +2 -0
  95. package/lib/module/components/ItemRenderer.js.map +1 -0
  96. package/lib/module/components/LazyView.js +2 -0
  97. package/lib/module/components/LazyView.js.map +1 -0
  98. package/lib/module/components/Pagination/Basic/PaginationItem.js +2 -0
  99. package/lib/module/components/Pagination/Basic/PaginationItem.js.map +1 -0
  100. package/lib/module/components/Pagination/Basic/index.js +2 -0
  101. package/lib/module/components/Pagination/Basic/index.js.map +1 -0
  102. package/lib/module/components/Pagination/Custom/PaginationItem.js +2 -0
  103. package/lib/module/components/Pagination/Custom/PaginationItem.js.map +1 -0
  104. package/lib/module/components/Pagination/Custom/index.js +2 -0
  105. package/lib/module/components/Pagination/Custom/index.js.map +1 -0
  106. package/lib/module/components/Pagination/index.js +2 -0
  107. package/lib/module/components/Pagination/index.js.map +1 -0
  108. package/lib/module/components/ScrollViewGesture.js +2 -0
  109. package/lib/module/components/ScrollViewGesture.js.map +1 -0
  110. package/lib/module/constants/index.js +2 -0
  111. package/lib/module/constants/index.js.map +1 -0
  112. package/lib/module/hooks/useAutoPlay.js +2 -0
  113. package/lib/module/hooks/useAutoPlay.js.map +1 -0
  114. package/lib/module/hooks/useCarouselController.js +2 -0
  115. package/lib/module/hooks/useCarouselController.js.map +1 -0
  116. package/lib/module/hooks/useCheckMounted.js +2 -0
  117. package/lib/module/hooks/useCheckMounted.js.map +1 -0
  118. package/lib/module/hooks/useCommonVariables.js +2 -0
  119. package/lib/module/hooks/useCommonVariables.js.map +1 -0
  120. package/lib/module/hooks/useInitProps.js +2 -0
  121. package/lib/module/hooks/useInitProps.js.map +1 -0
  122. package/lib/module/hooks/useLayoutConfig.js +2 -0
  123. package/lib/module/hooks/useLayoutConfig.js.map +1 -0
  124. package/lib/module/hooks/useOffsetX.js +2 -0
  125. package/lib/module/hooks/useOffsetX.js.map +1 -0
  126. package/lib/module/hooks/useOnProgressChange.js +2 -0
  127. package/lib/module/hooks/useOnProgressChange.js.map +1 -0
  128. package/lib/module/hooks/usePanGestureProxy.js +2 -0
  129. package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
  130. package/lib/module/hooks/usePropsErrorBoundary.js +2 -0
  131. package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -0
  132. package/lib/module/hooks/useSizeResolver.js +2 -0
  133. package/lib/module/hooks/useSizeResolver.js.map +1 -0
  134. package/lib/module/hooks/useUpdateGestureConfig.js +2 -0
  135. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
  136. package/lib/module/hooks/useVisibleRanges.js +2 -0
  137. package/lib/module/hooks/useVisibleRanges.js.map +1 -0
  138. package/lib/module/index.js +2 -0
  139. package/lib/module/index.js.map +1 -0
  140. package/lib/module/layouts/index.js +2 -0
  141. package/lib/module/layouts/index.js.map +1 -0
  142. package/lib/module/layouts/normal.js +2 -0
  143. package/lib/module/layouts/normal.js.map +1 -0
  144. package/lib/module/layouts/parallax.js +2 -0
  145. package/lib/module/layouts/parallax.js.map +1 -0
  146. package/lib/module/layouts/stack.js +2 -0
  147. package/lib/module/layouts/stack.js.map +1 -0
  148. package/lib/module/store/index.js +2 -0
  149. package/lib/module/store/index.js.map +1 -0
  150. package/lib/module/types.js +2 -0
  151. package/lib/module/types.js.map +1 -0
  152. package/lib/module/utils/compute-gesture-translation.js +2 -0
  153. package/lib/module/utils/compute-gesture-translation.js.map +1 -0
  154. package/lib/module/utils/compute-offset-if-data-changed.js +2 -0
  155. package/lib/module/utils/compute-offset-if-data-changed.js.map +1 -0
  156. package/lib/module/utils/compute-offset-if-size-changed.js +2 -0
  157. package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -0
  158. package/lib/module/utils/compute-offset-if-sizes-changed.js +2 -0
  159. package/lib/module/utils/compute-offset-if-sizes-changed.js.map +1 -0
  160. package/lib/module/utils/computed-with-auto-fill-data.js +2 -0
  161. package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
  162. package/lib/module/utils/deal-with-animation.js +2 -0
  163. package/lib/module/utils/deal-with-animation.js.map +1 -0
  164. package/lib/module/utils/handleroffset-direction.js +2 -0
  165. package/lib/module/utils/handleroffset-direction.js.map +1 -0
  166. package/lib/module/utils/log.js +2 -0
  167. package/lib/module/utils/log.js.map +1 -0
  168. package/lib/module/utils/sanitize-animation-style.js +2 -0
  169. package/lib/module/utils/sanitize-animation-style.js.map +1 -0
  170. package/lib/module/utils/size-resolver.js +2 -0
  171. package/lib/module/utils/size-resolver.js.map +1 -0
  172. package/lib/typescript/components/Carousel.d.ts +8 -0
  173. package/lib/typescript/components/Carousel.d.ts.map +1 -0
  174. package/lib/typescript/components/CarouselLayout.d.ts +6 -0
  175. package/lib/typescript/components/CarouselLayout.d.ts.map +1 -0
  176. package/lib/typescript/components/ItemLayout.d.ts +15 -0
  177. package/lib/typescript/components/ItemLayout.d.ts.map +1 -0
  178. package/lib/typescript/components/ItemRenderer.d.ts +24 -0
  179. package/lib/typescript/components/ItemRenderer.d.ts.map +1 -0
  180. package/lib/typescript/components/LazyView.d.ts +8 -0
  181. package/lib/typescript/components/LazyView.d.ts.map +1 -0
  182. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +29 -0
  183. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts.map +1 -0
  184. package/lib/typescript/components/Pagination/Basic/index.d.ts +23 -0
  185. package/lib/typescript/components/Pagination/Basic/index.d.ts.map +1 -0
  186. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts +35 -0
  187. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts.map +1 -0
  188. package/lib/typescript/components/Pagination/Custom/index.d.ts +26 -0
  189. package/lib/typescript/components/Pagination/Custom/index.d.ts.map +1 -0
  190. package/lib/typescript/components/Pagination/index.d.ts +5 -0
  191. package/lib/typescript/components/Pagination/index.d.ts.map +1 -0
  192. package/lib/typescript/components/ScrollViewGesture.d.ts +19 -0
  193. package/lib/typescript/components/ScrollViewGesture.d.ts.map +1 -0
  194. package/lib/typescript/constants/index.d.ts +9 -0
  195. package/lib/typescript/constants/index.d.ts.map +1 -0
  196. package/lib/typescript/hooks/useAutoPlay.d.ts +12 -0
  197. package/lib/typescript/hooks/useAutoPlay.d.ts.map +1 -0
  198. package/lib/typescript/hooks/useCarouselController.d.ts +28 -0
  199. package/lib/typescript/hooks/useCarouselController.d.ts.map +1 -0
  200. package/lib/typescript/hooks/useCheckMounted.d.ts +3 -0
  201. package/lib/typescript/hooks/useCheckMounted.d.ts.map +1 -0
  202. package/lib/typescript/hooks/useCommonVariables.d.ts +13 -0
  203. package/lib/typescript/hooks/useCommonVariables.d.ts.map +1 -0
  204. package/lib/typescript/hooks/useInitProps.d.ts +17 -0
  205. package/lib/typescript/hooks/useInitProps.d.ts.map +1 -0
  206. package/lib/typescript/hooks/useLayoutConfig.d.ts +10 -0
  207. package/lib/typescript/hooks/useLayoutConfig.d.ts.map +1 -0
  208. package/lib/typescript/hooks/useOffsetX.d.ts +24 -0
  209. package/lib/typescript/hooks/useOffsetX.d.ts.map +1 -0
  210. package/lib/typescript/hooks/useOnProgressChange.d.ts +14 -0
  211. package/lib/typescript/hooks/useOnProgressChange.d.ts.map +1 -0
  212. package/lib/typescript/hooks/usePanGestureProxy.d.ts +10 -0
  213. package/lib/typescript/hooks/usePanGestureProxy.d.ts.map +1 -0
  214. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +5 -0
  215. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +1 -0
  216. package/lib/typescript/hooks/useSizeResolver.d.ts +27 -0
  217. package/lib/typescript/hooks/useSizeResolver.d.ts.map +1 -0
  218. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +6 -0
  219. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts.map +1 -0
  220. package/lib/typescript/hooks/useVisibleRanges.d.ts +23 -0
  221. package/lib/typescript/hooks/useVisibleRanges.d.ts.map +1 -0
  222. package/lib/typescript/index.d.ts +7 -0
  223. package/lib/typescript/index.d.ts.map +1 -0
  224. package/lib/typescript/layouts/index.d.ts +11 -0
  225. package/lib/typescript/layouts/index.d.ts.map +1 -0
  226. package/lib/typescript/layouts/normal.d.ts +16 -0
  227. package/lib/typescript/layouts/normal.d.ts.map +1 -0
  228. package/lib/typescript/layouts/parallax.d.ts +50 -0
  229. package/lib/typescript/layouts/parallax.d.ts.map +1 -0
  230. package/lib/typescript/layouts/stack.d.ts +38 -0
  231. package/lib/typescript/layouts/stack.d.ts.map +1 -0
  232. package/lib/typescript/store/index.d.ts +38 -0
  233. package/lib/typescript/store/index.d.ts.map +1 -0
  234. package/lib/typescript/types.d.ts +326 -0
  235. package/lib/typescript/types.d.ts.map +1 -0
  236. package/lib/typescript/utils/compute-gesture-translation.d.ts +9 -0
  237. package/lib/typescript/utils/compute-gesture-translation.d.ts.map +1 -0
  238. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts +9 -0
  239. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts.map +1 -0
  240. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts +6 -0
  241. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts.map +1 -0
  242. package/lib/typescript/utils/compute-offset-if-sizes-changed.d.ts +14 -0
  243. package/lib/typescript/utils/compute-offset-if-sizes-changed.d.ts.map +1 -0
  244. package/lib/typescript/utils/computed-with-auto-fill-data.d.ts +23 -0
  245. package/lib/typescript/utils/computed-with-auto-fill-data.d.ts.map +1 -0
  246. package/lib/typescript/utils/deal-with-animation.d.ts +3 -0
  247. package/lib/typescript/utils/deal-with-animation.d.ts.map +1 -0
  248. package/lib/typescript/utils/handleroffset-direction.d.ts +4 -0
  249. package/lib/typescript/utils/handleroffset-direction.d.ts.map +1 -0
  250. package/lib/typescript/utils/log.d.ts +7 -0
  251. package/lib/typescript/utils/log.d.ts.map +1 -0
  252. package/lib/typescript/utils/sanitize-animation-style.d.ts +3 -0
  253. package/lib/typescript/utils/sanitize-animation-style.d.ts.map +1 -0
  254. package/lib/typescript/utils/size-resolver.d.ts +87 -0
  255. package/lib/typescript/utils/size-resolver.d.ts.map +1 -0
  256. package/package.json +151 -0
  257. package/src/components/Carousel.test.tsx +1153 -0
  258. package/src/components/Carousel.tsx +35 -0
  259. package/src/components/CarouselLayout.tsx +231 -0
  260. package/src/components/ItemLayout.tsx +217 -0
  261. package/src/components/ItemRenderer.tsx +114 -0
  262. package/src/components/LazyView.test.tsx +61 -0
  263. package/src/components/LazyView.tsx +14 -0
  264. package/src/components/Pagination/Basic/PaginationItem.tsx +149 -0
  265. package/src/components/Pagination/Basic/index.tsx +98 -0
  266. package/src/components/Pagination/Custom/PaginationItem.tsx +166 -0
  267. package/src/components/Pagination/Custom/index.tsx +111 -0
  268. package/src/components/Pagination/Pagination.test.tsx +178 -0
  269. package/src/components/Pagination/index.tsx +7 -0
  270. package/src/components/ScrollViewGesture.tsx +577 -0
  271. package/src/components/rnr-demo.test.tsx +53 -0
  272. package/src/constants/index.ts +11 -0
  273. package/src/hooks/useAutoPlay.test.ts +194 -0
  274. package/src/hooks/useAutoPlay.ts +58 -0
  275. package/src/hooks/useCarouselController.test.tsx +1158 -0
  276. package/src/hooks/useCarouselController.tsx +525 -0
  277. package/src/hooks/useCheckMounted.test.ts +47 -0
  278. package/src/hooks/useCheckMounted.ts +14 -0
  279. package/src/hooks/useCommonVariables.test.tsx +384 -0
  280. package/src/hooks/useCommonVariables.ts +202 -0
  281. package/src/hooks/useInitProps.test.tsx +134 -0
  282. package/src/hooks/useInitProps.ts +111 -0
  283. package/src/hooks/useLayoutConfig.test.tsx +247 -0
  284. package/src/hooks/useLayoutConfig.ts +30 -0
  285. package/src/hooks/useOffsetX.test.ts +110 -0
  286. package/src/hooks/useOffsetX.ts +109 -0
  287. package/src/hooks/useOnProgressChange.test.tsx +207 -0
  288. package/src/hooks/useOnProgressChange.ts +105 -0
  289. package/src/hooks/usePanGestureProxy.test.tsx +368 -0
  290. package/src/hooks/usePanGestureProxy.ts +144 -0
  291. package/src/hooks/usePropsErrorBoundary.ts +138 -0
  292. package/src/hooks/useSizeResolver.test.tsx +112 -0
  293. package/src/hooks/useSizeResolver.ts +106 -0
  294. package/src/hooks/useUpdateGestureConfig.test.ts +89 -0
  295. package/src/hooks/useUpdateGestureConfig.ts +14 -0
  296. package/src/hooks/useVisibleRanges.test.tsx +366 -0
  297. package/src/hooks/useVisibleRanges.tsx +123 -0
  298. package/src/index.tsx +13 -0
  299. package/src/layouts/index.tsx +12 -0
  300. package/src/layouts/normal.ts +32 -0
  301. package/src/layouts/parallax.test.ts +239 -0
  302. package/src/layouts/parallax.ts +83 -0
  303. package/src/layouts/stack.test.ts +252 -0
  304. package/src/layouts/stack.ts +306 -0
  305. package/src/store/index.test.tsx +314 -0
  306. package/src/store/index.tsx +66 -0
  307. package/src/types.ts +348 -0
  308. package/src/utils/compute-gesture-translation.test.ts +70 -0
  309. package/src/utils/compute-gesture-translation.ts +29 -0
  310. package/src/utils/compute-offset-if-data-changed.test.ts +133 -0
  311. package/src/utils/compute-offset-if-data-changed.ts +44 -0
  312. package/src/utils/compute-offset-if-size-changed.test.ts +78 -0
  313. package/src/utils/compute-offset-if-size-changed.ts +14 -0
  314. package/src/utils/compute-offset-if-sizes-changed.test.ts +74 -0
  315. package/src/utils/compute-offset-if-sizes-changed.ts +44 -0
  316. package/src/utils/computed-with-auto-fill-data.test.ts +298 -0
  317. package/src/utils/computed-with-auto-fill-data.ts +92 -0
  318. package/src/utils/deal-with-animation.test.ts +181 -0
  319. package/src/utils/deal-with-animation.ts +17 -0
  320. package/src/utils/handleroffset-direction.test.ts +124 -0
  321. package/src/utils/handleroffset-direction.ts +18 -0
  322. package/src/utils/index.test.ts +90 -0
  323. package/src/utils/log.test.ts +134 -0
  324. package/src/utils/log.ts +12 -0
  325. package/src/utils/sanitize-animation-style.test.ts +40 -0
  326. package/src/utils/sanitize-animation-style.ts +20 -0
  327. package/src/utils/size-resolver.test.ts +193 -0
  328. package/src/utils/size-resolver.ts +216 -0
@@ -0,0 +1,14 @@
1
+ export function computeOffsetIfSizeChanged(params: {
2
+ handlerOffset: number;
3
+ prevSize: number;
4
+ size: number;
5
+ }) {
6
+ "worklet";
7
+ const { handlerOffset, prevSize, size } = params;
8
+
9
+ if (!prevSize) {
10
+ return handlerOffset;
11
+ }
12
+
13
+ return (handlerOffset / prevSize) * size;
14
+ }
@@ -0,0 +1,74 @@
1
+ import { computeOffsetIfSizesChanged } from "./compute-offset-if-sizes-changed";
2
+ import { buildPrefixSum } from "./size-resolver";
3
+
4
+ describe("computeOffsetIfSizesChanged", () => {
5
+ it("returns the same offset when the prefix table is identical", () => {
6
+ const prefix = buildPrefixSum(5, () => 100).prefix;
7
+ const result = computeOffsetIfSizesChanged({
8
+ handlerOffset: -200,
9
+ prevPrefix: prefix,
10
+ nextPrefix: prefix,
11
+ });
12
+ expect(result).toBe(-200);
13
+ });
14
+
15
+ it("re-maps a boundary offset to the same item in the new table", () => {
16
+ const prev = buildPrefixSum(4, () => 100).prefix; // [0,100,200,300,400]
17
+ const next = buildPrefixSum(4, () => 200).prefix; // [0,200,400,600,800]
18
+ // -200 sat at the start of item 2 in the old table → start of item 2 in
19
+ // the new table is -400.
20
+ const result = computeOffsetIfSizesChanged({
21
+ handlerOffset: -200,
22
+ prevPrefix: prev,
23
+ nextPrefix: next,
24
+ });
25
+ expect(result).toBe(-400);
26
+ });
27
+
28
+ it("preserves mid-item fractional progress across resizes", () => {
29
+ const prev = buildPrefixSum(4, () => 100).prefix; // [0,100,200,300,400]
30
+ const next = buildPrefixSum(4, () => 200).prefix; // [0,200,400,600,800]
31
+ // -150 = halfway through item 1 in old (size 100). In new (size 200),
32
+ // halfway through item 1 = -200 - 100 = -300.
33
+ const result = computeOffsetIfSizesChanged({
34
+ handlerOffset: -150,
35
+ prevPrefix: prev,
36
+ nextPrefix: next,
37
+ });
38
+ expect(result).toBe(-300);
39
+ });
40
+
41
+ it("clamps to last item when target index exceeds new table", () => {
42
+ const prev = buildPrefixSum(5, () => 100).prefix; // [0,100,200,300,400,500]
43
+ const next = buildPrefixSum(3, () => 100).prefix; // [0,100,200,300]
44
+ // -450 sat in item 4 of old. Item 4 doesn't exist in new → clamp to 2.
45
+ const result = computeOffsetIfSizesChanged({
46
+ handlerOffset: -450,
47
+ prevPrefix: prev,
48
+ nextPrefix: next,
49
+ });
50
+ expect(result).toBeLessThan(0);
51
+ expect(result).toBeGreaterThanOrEqual(-300);
52
+ });
53
+
54
+ it("returns 0 when next table is empty", () => {
55
+ const prev = buildPrefixSum(3, () => 100).prefix;
56
+ const result = computeOffsetIfSizesChanged({
57
+ handlerOffset: -150,
58
+ prevPrefix: prev,
59
+ nextPrefix: [0],
60
+ });
61
+ expect(result).toBe(-150); // degenerate case short-circuits to passthrough
62
+ });
63
+
64
+ it("respects sign when handlerOffset is positive", () => {
65
+ const prev = buildPrefixSum(4, () => 100).prefix;
66
+ const next = buildPrefixSum(4, () => 200).prefix;
67
+ const result = computeOffsetIfSizesChanged({
68
+ handlerOffset: 200,
69
+ prevPrefix: prev,
70
+ nextPrefix: next,
71
+ });
72
+ expect(result).toBe(400);
73
+ });
74
+ });
@@ -0,0 +1,44 @@
1
+ import { binarySearchPrefix } from "./size-resolver";
2
+
3
+ /**
4
+ * Variable-size analogue of `compute-offset-if-size-changed.ts`. Given the
5
+ * previous and next prefix-sum tables and the current `handlerOffset`, returns
6
+ * a new handlerOffset such that the same logical item index stays in view.
7
+ *
8
+ * Both `prevPrefix` and `nextPrefix` must include the leading 0 sentinel, so
9
+ * `prefix.length === itemCount + 1` and `prefix[itemCount]` is the total span.
10
+ */
11
+ export function computeOffsetIfSizesChanged(params: {
12
+ handlerOffset: number;
13
+ prevPrefix: number[];
14
+ nextPrefix: number[];
15
+ }): number {
16
+ "worklet";
17
+ const { handlerOffset, prevPrefix, nextPrefix } = params;
18
+
19
+ if (prevPrefix.length <= 1 || nextPrefix.length <= 1) return handlerOffset;
20
+
21
+ // Translation is stored as a negative offset (scroll right = more negative),
22
+ // so the absolute position of the current item is -handlerOffset.
23
+ const absOffset = -handlerOffset;
24
+ const sign = handlerOffset <= 0 ? -1 : 1;
25
+
26
+ // Locate which item the previous prefix table mapped this offset to, plus
27
+ // the fractional progress through that item. Carrying fractional progress
28
+ // forward keeps mid-scroll resizes smooth instead of snapping to a boundary.
29
+ const prevItemIndex = binarySearchPrefix(prevPrefix, Math.abs(absOffset));
30
+ const clampedPrev = Math.max(0, Math.min(prevPrefix.length - 2, prevItemIndex));
31
+ const prevStart = prevPrefix[clampedPrev];
32
+ const prevSize = prevPrefix[clampedPrev + 1] - prevStart;
33
+ const fractional = prevSize > 0 ? (Math.abs(absOffset) - prevStart) / prevSize : 0;
34
+
35
+ // Re-map to the new table. If the item no longer exists in the new prefix,
36
+ // clamp to the last available index.
37
+ const targetIndex = Math.min(clampedPrev, nextPrefix.length - 2);
38
+ if (targetIndex < 0) return 0;
39
+ const nextStart = nextPrefix[targetIndex];
40
+ const nextSize = nextPrefix[targetIndex + 1] - nextStart;
41
+ const newAbs = nextStart + fractional * nextSize;
42
+
43
+ return sign * newAbs;
44
+ }
@@ -0,0 +1,298 @@
1
+ import {
2
+ computedFillDataWithAutoFillData,
3
+ computedOffsetXValueWithAutoFillData,
4
+ computedRealIndexWithAutoFillData,
5
+ convertToSharedIndex,
6
+ } from "./computed-with-auto-fill-data";
7
+
8
+ import { DATA_LENGTH } from "../constants";
9
+
10
+ const { SINGLE_ITEM, DOUBLE_ITEM } = DATA_LENGTH;
11
+
12
+ describe("computed-with-auto-fill-data utilities", () => {
13
+ describe("computedFillDataWithAutoFillData", () => {
14
+ it("should handle single item", () => {
15
+ const data = [1];
16
+ const result = computedFillDataWithAutoFillData({
17
+ data,
18
+ loop: true,
19
+ autoFillData: true,
20
+ dataLength: SINGLE_ITEM,
21
+ });
22
+
23
+ expect(result).toEqual([1, 1, 1]);
24
+ });
25
+
26
+ it("should handle double items", () => {
27
+ const data = [1, 2];
28
+ const result = computedFillDataWithAutoFillData({
29
+ data,
30
+ loop: true,
31
+ autoFillData: true,
32
+ dataLength: DOUBLE_ITEM,
33
+ });
34
+
35
+ expect(result).toEqual([1, 2, 1, 2]);
36
+ });
37
+
38
+ it("should return original data when autoFillData is false", () => {
39
+ const data = [1, 2, 3];
40
+ const result = computedFillDataWithAutoFillData({
41
+ data,
42
+ loop: true,
43
+ autoFillData: false,
44
+ dataLength: 3,
45
+ });
46
+
47
+ expect(result).toEqual(data);
48
+ });
49
+
50
+ it("should return original data when loop is false", () => {
51
+ const data = [1, 2, 3];
52
+ const result = computedFillDataWithAutoFillData({
53
+ data,
54
+ loop: false,
55
+ autoFillData: true,
56
+ dataLength: 3,
57
+ });
58
+
59
+ expect(result).toEqual(data);
60
+ });
61
+
62
+ it("should handle empty data array", () => {
63
+ const data: any[] = [];
64
+ const result = computedFillDataWithAutoFillData({
65
+ data,
66
+ loop: true,
67
+ autoFillData: true,
68
+ dataLength: 0,
69
+ });
70
+
71
+ expect(result).toEqual([]);
72
+ });
73
+
74
+ it("should handle data length greater than 2", () => {
75
+ const data = [1, 2, 3, 4, 5];
76
+ const result = computedFillDataWithAutoFillData({
77
+ data,
78
+ loop: true,
79
+ autoFillData: true,
80
+ dataLength: 5,
81
+ });
82
+
83
+ expect(result).toEqual(data);
84
+ });
85
+
86
+ it("should handle both loop and autoFillData false", () => {
87
+ const data = [1];
88
+ const result = computedFillDataWithAutoFillData({
89
+ data,
90
+ loop: false,
91
+ autoFillData: false,
92
+ dataLength: SINGLE_ITEM,
93
+ });
94
+
95
+ expect(result).toEqual(data);
96
+ });
97
+ });
98
+
99
+ describe("computedOffsetXValueWithAutoFillData", () => {
100
+ const size = 300;
101
+
102
+ it("should handle single item", () => {
103
+ const result = computedOffsetXValueWithAutoFillData({
104
+ value: size * 2,
105
+ size,
106
+ rawDataLength: SINGLE_ITEM,
107
+ loop: true,
108
+ autoFillData: true,
109
+ });
110
+
111
+ expect(result).toBe(0); // value % size
112
+ });
113
+
114
+ it("should handle double items", () => {
115
+ const result = computedOffsetXValueWithAutoFillData({
116
+ value: size * 3,
117
+ size,
118
+ rawDataLength: DOUBLE_ITEM,
119
+ loop: true,
120
+ autoFillData: true,
121
+ });
122
+
123
+ expect(result).toBe(size * 1); // value % (size * 2)
124
+ });
125
+
126
+ it("should return original value when autoFillData is false", () => {
127
+ const value = size * 2;
128
+ const result = computedOffsetXValueWithAutoFillData({
129
+ value,
130
+ size,
131
+ rawDataLength: 3,
132
+ loop: true,
133
+ autoFillData: false,
134
+ });
135
+
136
+ expect(result).toBe(value);
137
+ });
138
+
139
+ it("should return original value when loop is false", () => {
140
+ const value = size * 2;
141
+ const result = computedOffsetXValueWithAutoFillData({
142
+ value,
143
+ size,
144
+ rawDataLength: 3,
145
+ loop: false,
146
+ autoFillData: true,
147
+ });
148
+
149
+ expect(result).toBe(value);
150
+ });
151
+
152
+ it("should handle zero value", () => {
153
+ const result = computedOffsetXValueWithAutoFillData({
154
+ value: 0,
155
+ size,
156
+ rawDataLength: SINGLE_ITEM,
157
+ loop: true,
158
+ autoFillData: true,
159
+ });
160
+
161
+ expect(result).toBe(0);
162
+ });
163
+
164
+ it("should handle negative values", () => {
165
+ const result = computedOffsetXValueWithAutoFillData({
166
+ value: -size,
167
+ size,
168
+ rawDataLength: SINGLE_ITEM,
169
+ loop: true,
170
+ autoFillData: true,
171
+ });
172
+
173
+ // JavaScript's modulo can return -0 for negative numbers
174
+ expect(result).toBe(-0); // -size % size = -0
175
+ });
176
+
177
+ it("should handle fractional values", () => {
178
+ const result = computedOffsetXValueWithAutoFillData({
179
+ value: size * 1.5,
180
+ size,
181
+ rawDataLength: DOUBLE_ITEM,
182
+ loop: true,
183
+ autoFillData: true,
184
+ });
185
+
186
+ expect(result).toBe(size * 1.5); // This should work with modulo
187
+ });
188
+
189
+ it("should handle both conditions false", () => {
190
+ const value = size * 3;
191
+ const result = computedOffsetXValueWithAutoFillData({
192
+ value,
193
+ size,
194
+ rawDataLength: 3,
195
+ loop: false,
196
+ autoFillData: false,
197
+ });
198
+
199
+ expect(result).toBe(value);
200
+ });
201
+ });
202
+
203
+ describe("computedRealIndexWithAutoFillData", () => {
204
+ it("should handle single item", () => {
205
+ const result = computedRealIndexWithAutoFillData({
206
+ index: 2,
207
+ dataLength: SINGLE_ITEM,
208
+ loop: true,
209
+ autoFillData: true,
210
+ });
211
+
212
+ expect(result).toBe(0); // index % 1
213
+ });
214
+
215
+ it("should handle double items", () => {
216
+ const result = computedRealIndexWithAutoFillData({
217
+ index: 3,
218
+ dataLength: DOUBLE_ITEM,
219
+ loop: true,
220
+ autoFillData: true,
221
+ });
222
+
223
+ expect(result).toBe(1); // index % 2
224
+ });
225
+
226
+ it("should return original index when autoFillData is false", () => {
227
+ const index = 2;
228
+ const result = computedRealIndexWithAutoFillData({
229
+ index,
230
+ dataLength: 3,
231
+ loop: true,
232
+ autoFillData: false,
233
+ });
234
+
235
+ expect(result).toBe(index);
236
+ });
237
+
238
+ it("should return original index when loop is false", () => {
239
+ const index = 2;
240
+ const result = computedRealIndexWithAutoFillData({
241
+ index,
242
+ dataLength: 3,
243
+ loop: false,
244
+ autoFillData: true,
245
+ });
246
+
247
+ expect(result).toBe(index);
248
+ });
249
+ });
250
+
251
+ describe("convertToSharedIndex", () => {
252
+ it("should handle single item", () => {
253
+ const result = convertToSharedIndex({
254
+ index: 2,
255
+ rawDataLength: SINGLE_ITEM,
256
+ loop: true,
257
+ autoFillData: true,
258
+ });
259
+
260
+ expect(result).toBe(0);
261
+ });
262
+
263
+ it("should handle double items", () => {
264
+ const result = convertToSharedIndex({
265
+ index: 3,
266
+ rawDataLength: DOUBLE_ITEM,
267
+ loop: true,
268
+ autoFillData: true,
269
+ });
270
+
271
+ expect(result).toBe(1); // index % 2
272
+ });
273
+
274
+ it("should return original index when autoFillData is false", () => {
275
+ const index = 2;
276
+ const result = convertToSharedIndex({
277
+ index,
278
+ rawDataLength: 3,
279
+ loop: true,
280
+ autoFillData: false,
281
+ });
282
+
283
+ expect(result).toBe(index);
284
+ });
285
+
286
+ it("should return original index when loop is false", () => {
287
+ const index = 2;
288
+ const result = convertToSharedIndex({
289
+ index,
290
+ rawDataLength: 3,
291
+ loop: false,
292
+ autoFillData: true,
293
+ });
294
+
295
+ expect(result).toBe(index);
296
+ });
297
+ });
298
+ });
@@ -0,0 +1,92 @@
1
+ import { DATA_LENGTH } from "../constants";
2
+
3
+ const { SINGLE_ITEM, DOUBLE_ITEM } = DATA_LENGTH;
4
+
5
+ function isAutoFillData(params: { autoFillData: boolean; loop: boolean }) {
6
+ "worklet";
7
+ return !!params.loop && !!params.autoFillData;
8
+ }
9
+
10
+ type BaseParams<T extends object> = {
11
+ autoFillData: boolean;
12
+ loop: boolean;
13
+ } & T;
14
+
15
+ export function convertToSharedIndex(params: BaseParams<{ index: number; rawDataLength: number }>) {
16
+ "worklet";
17
+ const { loop, rawDataLength, index, autoFillData } = params;
18
+
19
+ if (isAutoFillData({ loop, autoFillData })) {
20
+ switch (rawDataLength) {
21
+ case SINGLE_ITEM:
22
+ return 0;
23
+ case DOUBLE_ITEM:
24
+ return index % 2;
25
+ }
26
+ }
27
+
28
+ return index;
29
+ }
30
+
31
+ export function computedOffsetXValueWithAutoFillData(
32
+ params: BaseParams<{
33
+ rawDataLength: number;
34
+ value: number;
35
+ size: number;
36
+ }>
37
+ ) {
38
+ "worklet";
39
+
40
+ const { rawDataLength, value, size, loop, autoFillData } = params;
41
+
42
+ if (isAutoFillData({ loop, autoFillData })) {
43
+ switch (rawDataLength) {
44
+ case SINGLE_ITEM:
45
+ return value % size;
46
+ case DOUBLE_ITEM:
47
+ return value % (size * 2);
48
+ }
49
+ }
50
+
51
+ return value;
52
+ }
53
+
54
+ export function computedRealIndexWithAutoFillData(
55
+ params: BaseParams<{
56
+ index: number;
57
+ dataLength: number;
58
+ }>
59
+ ) {
60
+ const { index, dataLength, loop, autoFillData } = params;
61
+
62
+ if (isAutoFillData({ loop, autoFillData })) {
63
+ switch (dataLength) {
64
+ case SINGLE_ITEM:
65
+ return index % 1;
66
+ case DOUBLE_ITEM:
67
+ return index % 2;
68
+ }
69
+ }
70
+
71
+ return index;
72
+ }
73
+
74
+ export function computedFillDataWithAutoFillData<T>(
75
+ params: BaseParams<{
76
+ data: T[];
77
+ dataLength: number;
78
+ }>
79
+ ): T[] {
80
+ const { data, loop, autoFillData, dataLength } = params;
81
+
82
+ if (isAutoFillData({ loop, autoFillData })) {
83
+ switch (dataLength) {
84
+ case SINGLE_ITEM:
85
+ return [data[0], data[0], data[0]];
86
+ case DOUBLE_ITEM:
87
+ return [data[0], data[1], data[0], data[1]];
88
+ }
89
+ }
90
+
91
+ return data;
92
+ }
@@ -0,0 +1,181 @@
1
+ import { withSpring, withTiming } from "react-native-reanimated";
2
+
3
+ import { dealWithAnimation } from "./deal-with-animation";
4
+
5
+ // Mock Reanimated
6
+ jest.mock("react-native-reanimated", () => ({
7
+ withSpring: jest.fn((value, _config, callback) => {
8
+ callback?.(true);
9
+ return value;
10
+ }),
11
+ withTiming: jest.fn((value, _config, callback) => {
12
+ callback?.(true);
13
+ return value;
14
+ }),
15
+ }));
16
+
17
+ describe("dealWithAnimation", () => {
18
+ beforeEach(() => {
19
+ jest.clearAllMocks();
20
+ });
21
+
22
+ it("should handle spring animation", () => {
23
+ const callback = jest.fn();
24
+ const springConfig = {
25
+ damping: 20,
26
+ stiffness: 90,
27
+ };
28
+
29
+ const animation = dealWithAnimation({
30
+ type: "spring",
31
+ config: springConfig,
32
+ });
33
+
34
+ const result = animation(100, callback);
35
+
36
+ expect(withSpring).toHaveBeenCalledWith(100, springConfig, expect.any(Function));
37
+ expect(callback).toHaveBeenCalledWith(true);
38
+ expect(result).toBe(100);
39
+ });
40
+
41
+ it("should handle timing animation", () => {
42
+ const callback = jest.fn();
43
+ const timingConfig = {
44
+ duration: 300,
45
+ };
46
+
47
+ const animation = dealWithAnimation({
48
+ type: "timing",
49
+ config: timingConfig,
50
+ });
51
+
52
+ const result = animation(100, callback);
53
+
54
+ expect(withTiming).toHaveBeenCalledWith(100, timingConfig, expect.any(Function));
55
+ expect(callback).toHaveBeenCalledWith(true);
56
+ expect(result).toBe(100);
57
+ });
58
+
59
+ it("should pass animation config correctly", () => {
60
+ const springConfig = {
61
+ damping: 10,
62
+ mass: 1,
63
+ stiffness: 100,
64
+ };
65
+
66
+ const animation = dealWithAnimation({
67
+ type: "spring",
68
+ config: springConfig,
69
+ });
70
+
71
+ animation(100, jest.fn());
72
+
73
+ expect(withSpring).toHaveBeenCalledWith(
74
+ 100,
75
+ expect.objectContaining(springConfig),
76
+ expect.any(Function)
77
+ );
78
+ });
79
+
80
+ it("should handle animation completion", () => {
81
+ const callback = jest.fn();
82
+ const animation = dealWithAnimation({
83
+ type: "timing",
84
+ config: { duration: 300 },
85
+ });
86
+
87
+ animation(100, callback);
88
+
89
+ expect(callback).toHaveBeenCalledWith(true);
90
+ });
91
+
92
+ it("should handle spring animation with different values", () => {
93
+ const callback = jest.fn();
94
+ const animation = dealWithAnimation({
95
+ type: "spring",
96
+ config: { damping: 15 },
97
+ });
98
+
99
+ animation(0, callback);
100
+ animation(-100, callback);
101
+ animation(500, callback);
102
+
103
+ expect(withSpring).toHaveBeenCalledWith(0, { damping: 15 }, expect.any(Function));
104
+ expect(withSpring).toHaveBeenCalledWith(-100, { damping: 15 }, expect.any(Function));
105
+ expect(withSpring).toHaveBeenCalledWith(500, { damping: 15 }, expect.any(Function));
106
+ expect(callback).toHaveBeenCalledTimes(3);
107
+ });
108
+
109
+ it("should handle timing animation with different values", () => {
110
+ const callback = jest.fn();
111
+ const animation = dealWithAnimation({
112
+ type: "timing",
113
+ config: { duration: 500 },
114
+ });
115
+
116
+ animation(0, callback);
117
+ animation(-50, callback);
118
+ animation(1000, callback);
119
+
120
+ expect(withTiming).toHaveBeenCalledWith(0, { duration: 500 }, expect.any(Function));
121
+ expect(withTiming).toHaveBeenCalledWith(-50, { duration: 500 }, expect.any(Function));
122
+ expect(withTiming).toHaveBeenCalledWith(1000, { duration: 500 }, expect.any(Function));
123
+ expect(callback).toHaveBeenCalledTimes(3);
124
+ });
125
+
126
+ it("should handle empty spring config", () => {
127
+ const callback = jest.fn();
128
+ const animation = dealWithAnimation({
129
+ type: "spring",
130
+ config: {},
131
+ });
132
+
133
+ animation(100, callback);
134
+
135
+ expect(withSpring).toHaveBeenCalledWith(100, {}, expect.any(Function));
136
+ expect(callback).toHaveBeenCalledWith(true);
137
+ });
138
+
139
+ it("should handle empty timing config", () => {
140
+ const callback = jest.fn();
141
+ const animation = dealWithAnimation({
142
+ type: "timing",
143
+ config: {},
144
+ });
145
+
146
+ animation(100, callback);
147
+
148
+ expect(withTiming).toHaveBeenCalledWith(100, {}, expect.any(Function));
149
+ expect(callback).toHaveBeenCalledWith(true);
150
+ });
151
+
152
+ it("should handle fractional values", () => {
153
+ const callback = jest.fn();
154
+ const animation = dealWithAnimation({
155
+ type: "spring",
156
+ config: { damping: 10 },
157
+ });
158
+
159
+ animation(50.5, callback);
160
+ animation(-25.75, callback);
161
+
162
+ expect(withSpring).toHaveBeenCalledWith(50.5, { damping: 10 }, expect.any(Function));
163
+ expect(withSpring).toHaveBeenCalledWith(-25.75, { damping: 10 }, expect.any(Function));
164
+ });
165
+
166
+ it("should create different animation functions for different configs", () => {
167
+ const animation1 = dealWithAnimation({
168
+ type: "spring",
169
+ config: { damping: 10 },
170
+ });
171
+
172
+ const animation2 = dealWithAnimation({
173
+ type: "timing",
174
+ config: { duration: 200 },
175
+ });
176
+
177
+ expect(animation1).not.toBe(animation2);
178
+ expect(typeof animation1).toBe("function");
179
+ expect(typeof animation2).toBe("function");
180
+ });
181
+ });