@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,123 @@
1
+ import { useRef } from "react";
2
+ import type { SharedValue } from "react-native-reanimated";
3
+ import { useDerivedValue } from "react-native-reanimated";
4
+
5
+ import type { SizeResolver } from "../utils/size-resolver";
6
+
7
+ type Range = [number, number];
8
+
9
+ export interface VisibleRanges {
10
+ negativeRange: Range;
11
+ positiveRange: Range;
12
+ }
13
+
14
+ export type IVisibleRanges = SharedValue<VisibleRanges>;
15
+
16
+ export function useVisibleRanges(options: {
17
+ total: number;
18
+ viewSize: number;
19
+ windowSize?: number;
20
+ translation: SharedValue<number>;
21
+ loop?: boolean;
22
+ /**
23
+ * Optional resolver. When supplied the hook locates `currentIndex` via
24
+ * `resolver.indexAt(-translation)` instead of `round(-translation / viewSize)`,
25
+ * which is what makes variable-size virtualization work without blanks.
26
+ */
27
+ resolver?: SizeResolver;
28
+ }): IVisibleRanges {
29
+ const { total = 0, viewSize, translation, windowSize: _windowSize, loop, resolver } = options;
30
+
31
+ const windowSize =
32
+ typeof _windowSize === "number" && Number.isFinite(_windowSize) && _windowSize > 0
33
+ ? _windowSize
34
+ : total;
35
+ const cachedRanges = useRef<VisibleRanges | null>(null);
36
+
37
+ const ranges = useDerivedValue(() => {
38
+ if (total <= 0) {
39
+ return {
40
+ negativeRange: [0, 0] as Range,
41
+ positiveRange: [0, -1] as Range,
42
+ };
43
+ }
44
+
45
+ // When a resolver is supplied, "ready" means the prefix table has been
46
+ // built (total > 0). Otherwise we need a positive viewSize to divide by.
47
+ const resolverReady = !!resolver?.variable && resolver.total.value > 0;
48
+ const uniformReady = Number.isFinite(viewSize) && viewSize > 0;
49
+ if (!resolverReady && !uniformReady) {
50
+ return {
51
+ negativeRange: [0, 0] as Range,
52
+ positiveRange: [0, Math.min(total - 1, windowSize - 1)] as Range,
53
+ };
54
+ }
55
+
56
+ const positiveCount = Math.round(windowSize / 2);
57
+ const negativeCount = windowSize - positiveCount;
58
+
59
+ let currentIndex = resolverReady
60
+ ? resolver!.indexAt(-translation.value)
61
+ : Math.round(-translation.value / viewSize);
62
+ if (!Number.isFinite(currentIndex)) currentIndex = 0;
63
+
64
+ let newRanges: VisibleRanges;
65
+
66
+ if (!loop) {
67
+ // Clamp currentIndex to valid range [0, total-1] for non-loop mode
68
+ // When overdragging right, translation.value becomes positive, making currentIndex negative
69
+ currentIndex = Math.max(0, Math.min(total - 1, currentIndex));
70
+
71
+ // Adjusting negative range if the carousel is not loopable.
72
+ // So, It will be only displayed the positive items.
73
+ newRanges = {
74
+ negativeRange: [Math.max(0, currentIndex - (windowSize - 1)), currentIndex],
75
+ positiveRange: [currentIndex, Math.min(total - 1, currentIndex + (windowSize - 1))],
76
+ };
77
+ } else {
78
+ currentIndex = currentIndex < 0 ? (currentIndex % total) + total : currentIndex;
79
+
80
+ const negativeRange: Range = [
81
+ (currentIndex - negativeCount + total) % total,
82
+ (currentIndex - 1 + total) % total,
83
+ ];
84
+
85
+ const positiveRange: Range = [
86
+ (currentIndex + total) % total,
87
+ (currentIndex + positiveCount + total) % total,
88
+ ];
89
+
90
+ if (negativeRange[0] < total && negativeRange[0] > negativeRange[1]) {
91
+ negativeRange[1] = total - 1;
92
+ positiveRange[0] = 0;
93
+ }
94
+ if (positiveRange[0] > positiveRange[1]) {
95
+ negativeRange[1] = total - 1;
96
+ positiveRange[0] = 0;
97
+ }
98
+
99
+ // console.log({ negativeRange, positiveRange ,total,windowSize,a:total <= _windowSize})
100
+ newRanges = { negativeRange, positiveRange };
101
+ }
102
+
103
+ if (
104
+ cachedRanges.current &&
105
+ isArraysEqual(cachedRanges.current.negativeRange, newRanges.negativeRange) &&
106
+ isArraysEqual(cachedRanges.current.positiveRange, newRanges.positiveRange)
107
+ ) {
108
+ return cachedRanges.current;
109
+ }
110
+
111
+ cachedRanges.current = newRanges;
112
+ return newRanges;
113
+ }, [loop, total, windowSize, translation, viewSize, resolver]);
114
+
115
+ return ranges;
116
+ }
117
+
118
+ function isArraysEqual(a: number[], b: number[]): boolean {
119
+ "worklet";
120
+ if (a.length !== b.length) return false;
121
+
122
+ return a.every((value, index) => value === b[index]);
123
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,13 @@
1
+ import Carousel from "./components/Carousel";
2
+ export { Pagination } from "./components/Pagination";
3
+
4
+ export type {
5
+ TCarouselProps,
6
+ ICarouselInstance,
7
+ IComputedDirectionTypes,
8
+ CarouselRenderItem,
9
+ } from "./types";
10
+ export type { TAnimationStyle } from "./components/ItemLayout";
11
+ export type { ILayoutConfig } from "./layouts/stack";
12
+
13
+ export default Carousel;
@@ -0,0 +1,12 @@
1
+ import { normalLayout } from "./normal";
2
+ import { parallaxLayout } from "./parallax";
3
+ import { horizontalStackLayout, verticalStackLayout } from "./stack";
4
+
5
+ export type TMode = "parallax" | "horizontal-stack" | "vertical-stack";
6
+
7
+ export const Layouts = {
8
+ normal: normalLayout,
9
+ parallax: parallaxLayout,
10
+ horizontalStack: horizontalStackLayout,
11
+ verticalStack: verticalStackLayout,
12
+ };
@@ -0,0 +1,32 @@
1
+ import { interpolate } from "react-native-reanimated";
2
+
3
+ import type { SizeResolver } from "../utils/size-resolver";
4
+
5
+ export function normalLayout(opts: {
6
+ size: number;
7
+ vertical: boolean;
8
+ /** When supplied, per-item translations use `resolver.itemSize(index)`. */
9
+ sizeResolver?: SizeResolver;
10
+ }) {
11
+ const { size, vertical, sizeResolver } = opts;
12
+
13
+ return (value: number, index: number) => {
14
+ "worklet";
15
+ // Use the per-item size in variable mode so non-uniform items keep their
16
+ // animation `value` semantics (-1 means one item-width to the left).
17
+ const itemSize = sizeResolver?.variable ? sizeResolver.itemSize(index) : size;
18
+ const translate = interpolate(value, [-1, 0, 1], [-itemSize, 0, itemSize]);
19
+
20
+ return {
21
+ transform: [
22
+ vertical
23
+ ? {
24
+ translateY: translate,
25
+ }
26
+ : {
27
+ translateX: translate,
28
+ },
29
+ ],
30
+ };
31
+ };
32
+ }
@@ -0,0 +1,239 @@
1
+ import { parallaxLayout } from "./parallax";
2
+
3
+ // Mock react-native-reanimated
4
+ jest.mock("react-native-reanimated", () => ({
5
+ interpolate: jest.fn((value, inputRange, outputRange) => {
6
+ // Simple linear interpolation mock for testing
7
+ const inputMin = inputRange[0];
8
+ const inputMax = inputRange[inputRange.length - 1];
9
+ const outputMin = outputRange[0];
10
+ const outputMax = outputRange[outputRange.length - 1];
11
+
12
+ if (value <= inputMin) return outputMin;
13
+ if (value >= inputMax) return outputMax;
14
+
15
+ // Linear interpolation
16
+ const progress = (value - inputMin) / (inputMax - inputMin);
17
+ return outputMin + progress * (outputMax - outputMin);
18
+ }),
19
+ Extrapolation: {
20
+ CLAMP: "clamp",
21
+ },
22
+ }));
23
+
24
+ describe("parallaxLayout", () => {
25
+ const baseConfig = {
26
+ size: 300,
27
+ vertical: false,
28
+ };
29
+
30
+ it("should create layout function with default config", () => {
31
+ const layout = parallaxLayout(baseConfig);
32
+ expect(typeof layout).toBe("function");
33
+ });
34
+
35
+ it("should return transform object for horizontal layout", () => {
36
+ const layout = parallaxLayout(baseConfig);
37
+ const result = layout(0);
38
+
39
+ expect(result).toHaveProperty("transform");
40
+ expect(result).toHaveProperty("zIndex");
41
+ expect(result.transform).toHaveLength(2);
42
+ expect(result.transform[0]).toHaveProperty("translateX");
43
+ expect(result.transform[1]).toHaveProperty("scale");
44
+ });
45
+
46
+ it("should return transform object for vertical layout", () => {
47
+ const verticalConfig = { ...baseConfig, vertical: true };
48
+ const layout = parallaxLayout(verticalConfig);
49
+ const result = layout(0);
50
+
51
+ expect(result).toHaveProperty("transform");
52
+ expect(result).toHaveProperty("zIndex");
53
+ expect(result.transform).toHaveLength(2);
54
+ expect(result.transform[0]).toHaveProperty("translateY");
55
+ expect(result.transform[1]).toHaveProperty("scale");
56
+ });
57
+
58
+ it("should handle center position (value = 0)", () => {
59
+ const layout = parallaxLayout(baseConfig);
60
+ const result = layout(0);
61
+
62
+ // At center position, translateX should be 0
63
+ expect(result.transform[0].translateX).toBe(0);
64
+ // Scale should be a number (parallax logic applied)
65
+ expect(typeof result.transform[1].scale).toBe("number");
66
+ });
67
+
68
+ it("should handle left position (value = -1)", () => {
69
+ const layout = parallaxLayout(baseConfig);
70
+ const result = layout(-1);
71
+
72
+ // At left position, translateX should be -size + parallaxScrollingOffset
73
+ expect(result.transform[0].translateX).toBe(-200); // -300 + 100
74
+ // Scale should be a number
75
+ expect(typeof result.transform[1].scale).toBe("number");
76
+ });
77
+
78
+ it("should handle right position (value = 1)", () => {
79
+ const layout = parallaxLayout(baseConfig);
80
+ const result = layout(1);
81
+
82
+ // At right position, translateX should be size - parallaxScrollingOffset
83
+ expect(result.transform[0].translateX).toBe(200); // 300 - 100
84
+ // Scale should be a number
85
+ expect(typeof result.transform[1].scale).toBe("number");
86
+ });
87
+
88
+ it("should handle custom parallaxScrollingOffset", () => {
89
+ const modeConfig = { parallaxScrollingOffset: 50 };
90
+ const layout = parallaxLayout(baseConfig, modeConfig);
91
+
92
+ const leftResult = layout(-1);
93
+ const rightResult = layout(1);
94
+
95
+ expect(leftResult.transform[0].translateX).toBe(-250); // -300 + 50
96
+ expect(rightResult.transform[0].translateX).toBe(250); // 300 - 50
97
+ });
98
+
99
+ it("should handle custom parallaxScrollingScale", () => {
100
+ const modeConfig = { parallaxScrollingScale: 0.9 };
101
+ const layout = parallaxLayout(baseConfig, modeConfig);
102
+
103
+ const centerResult = layout(0);
104
+ const sideResult = layout(-1);
105
+
106
+ // Verify the structure and that scale values are calculated
107
+ expect(typeof centerResult.transform[1].scale).toBe("number");
108
+ expect(typeof sideResult.transform[1].scale).toBe("number");
109
+ expect(centerResult.transform[1].scale).toBeGreaterThan(0);
110
+ expect(sideResult.transform[1].scale).toBeGreaterThan(0);
111
+ });
112
+
113
+ it("should handle custom parallaxAdjacentItemScale", () => {
114
+ const modeConfig = {
115
+ parallaxScrollingScale: 0.9,
116
+ parallaxAdjacentItemScale: 0.7,
117
+ };
118
+ const layout = parallaxLayout(baseConfig, modeConfig);
119
+
120
+ const centerResult = layout(0);
121
+ const sideResult = layout(-1);
122
+
123
+ // Verify the structure and that scale values are calculated
124
+ expect(typeof centerResult.transform[1].scale).toBe("number");
125
+ expect(typeof sideResult.transform[1].scale).toBe("number");
126
+ expect(centerResult.transform[1].scale).toBeGreaterThan(0);
127
+ expect(sideResult.transform[1].scale).toBeGreaterThan(0);
128
+ });
129
+
130
+ it("should handle vertical layout with custom config", () => {
131
+ const verticalConfig = { ...baseConfig, vertical: true };
132
+ const modeConfig = { parallaxScrollingOffset: 80 };
133
+ const layout = parallaxLayout(verticalConfig, modeConfig);
134
+
135
+ const leftResult = layout(-1);
136
+ const centerResult = layout(0);
137
+ const rightResult = layout(1);
138
+
139
+ expect(leftResult.transform[0].translateY).toBe(-220); // -300 + 80
140
+ expect(centerResult.transform[0].translateY).toBe(0);
141
+ expect(rightResult.transform[0].translateY).toBe(220); // 300 - 80
142
+ });
143
+
144
+ it("should handle edge case values", () => {
145
+ const layout = parallaxLayout(baseConfig);
146
+
147
+ // Test with values beyond the normal range
148
+ const farLeftResult = layout(-2);
149
+ const farRightResult = layout(2);
150
+
151
+ expect(typeof farLeftResult.transform[0].translateX).toBe("number");
152
+ expect(typeof farLeftResult.transform[1].scale).toBe("number");
153
+ expect(typeof farRightResult.transform[0].translateX).toBe("number");
154
+ expect(typeof farRightResult.transform[1].scale).toBe("number");
155
+ });
156
+
157
+ it("should handle fractional values", () => {
158
+ const layout = parallaxLayout(baseConfig);
159
+
160
+ const halfwayResult = layout(0.5);
161
+ const quarterResult = layout(-0.25);
162
+
163
+ expect(typeof halfwayResult.transform[0].translateX).toBe("number");
164
+ expect(typeof halfwayResult.transform[1].scale).toBe("number");
165
+ expect(typeof quarterResult.transform[0].translateX).toBe("number");
166
+ expect(typeof quarterResult.transform[1].scale).toBe("number");
167
+ });
168
+
169
+ it("should handle zero size", () => {
170
+ const zeroSizeConfig = { ...baseConfig, size: 0 };
171
+ const layout = parallaxLayout(zeroSizeConfig);
172
+ const result = layout(0);
173
+
174
+ expect(result).toHaveProperty("transform");
175
+ expect(result).toHaveProperty("zIndex");
176
+ });
177
+
178
+ it("should handle negative size", () => {
179
+ const negativeSizeConfig = { ...baseConfig, size: -100 };
180
+ const layout = parallaxLayout(negativeSizeConfig);
181
+ const result = layout(0);
182
+
183
+ expect(result).toHaveProperty("transform");
184
+ expect(result).toHaveProperty("zIndex");
185
+ });
186
+
187
+ it("should handle all config properties at once", () => {
188
+ const fullModeConfig = {
189
+ parallaxScrollingOffset: 75,
190
+ parallaxScrollingScale: 0.85,
191
+ parallaxAdjacentItemScale: 0.6,
192
+ };
193
+ const layout = parallaxLayout(baseConfig, fullModeConfig);
194
+
195
+ const centerResult = layout(0);
196
+ const sideResult = layout(-1);
197
+
198
+ // Verify the structure and that values are calculated correctly
199
+ expect(typeof centerResult.transform[1].scale).toBe("number");
200
+ expect(typeof sideResult.transform[1].scale).toBe("number");
201
+ expect(sideResult.transform[0].translateX).toBe(-225); // -300 + 75
202
+ });
203
+
204
+ it("should handle empty mode config", () => {
205
+ const layout = parallaxLayout(baseConfig, {});
206
+ const result = layout(0);
207
+
208
+ // At center (value = 0), scale should be a number (default parallax behavior)
209
+ expect(typeof result.transform[1].scale).toBe("number");
210
+ expect(result.transform[1].scale).toBeGreaterThan(0);
211
+ expect(result.transform[1].scale).toBeLessThanOrEqual(1);
212
+ });
213
+
214
+ it("should handle undefined mode config", () => {
215
+ const layout = parallaxLayout(baseConfig, undefined);
216
+ const result = layout(0);
217
+
218
+ // At center (value = 0), scale should be a number (default parallax behavior)
219
+ expect(typeof result.transform[1].scale).toBe("number");
220
+ expect(result.transform[1].scale).toBeGreaterThan(0);
221
+ expect(result.transform[1].scale).toBeLessThanOrEqual(1);
222
+ });
223
+
224
+ it("should maintain consistent zIndex calculation", () => {
225
+ const layout = parallaxLayout(baseConfig);
226
+
227
+ const leftResult = layout(-1);
228
+ const centerResult = layout(0);
229
+ const rightResult = layout(1);
230
+
231
+ expect(typeof leftResult.zIndex).toBe("number");
232
+ expect(typeof centerResult.zIndex).toBe("number");
233
+ expect(typeof rightResult.zIndex).toBe("number");
234
+
235
+ // Center should have highest zIndex
236
+ expect(centerResult.zIndex).toBeGreaterThanOrEqual(leftResult.zIndex);
237
+ expect(centerResult.zIndex).toBeGreaterThanOrEqual(rightResult.zIndex);
238
+ });
239
+ });
@@ -0,0 +1,83 @@
1
+ import { Extrapolation, interpolate } from "react-native-reanimated";
2
+
3
+ import type { IComputedDirectionTypes } from "../types";
4
+ import type { SizeResolver } from "../utils/size-resolver";
5
+
6
+ interface TBaseConfig {
7
+ size: number;
8
+ vertical: boolean;
9
+ /** When supplied, per-item translations and zIndex use the resolver. */
10
+ sizeResolver?: SizeResolver;
11
+ }
12
+
13
+ export interface ILayoutConfig {
14
+ /**
15
+ * control prev/next item offset.
16
+ * @default 100
17
+ */
18
+ parallaxScrollingOffset?: number;
19
+ /**
20
+ * control prev/current/next item offset.
21
+ * @default 0.8
22
+ */
23
+ parallaxScrollingScale?: number;
24
+ /**
25
+ * control prev/next item offset.
26
+ * @default Math.pow(parallaxScrollingScale, 2)
27
+ */
28
+ parallaxAdjacentItemScale?: number;
29
+ }
30
+
31
+ export type TParallaxModeProps = IComputedDirectionTypes<{
32
+ /**
33
+ * Carousel Animated transitions.
34
+ */
35
+ mode?: "parallax";
36
+ modeConfig?: ILayoutConfig;
37
+ }>;
38
+
39
+ export function parallaxLayout(baseConfig: TBaseConfig, modeConfig: ILayoutConfig = {}) {
40
+ const { size, vertical, sizeResolver } = baseConfig;
41
+ const {
42
+ parallaxScrollingOffset = 100,
43
+ parallaxScrollingScale = 0.8,
44
+ parallaxAdjacentItemScale = parallaxScrollingScale ** 2,
45
+ } = modeConfig;
46
+
47
+ return (value: number, index: number) => {
48
+ "worklet";
49
+ const itemSize = sizeResolver?.variable ? sizeResolver.itemSize(index) : size;
50
+ const translate = interpolate(
51
+ value,
52
+ [-1, 0, 1],
53
+ [-itemSize + parallaxScrollingOffset, 0, itemSize - parallaxScrollingOffset]
54
+ );
55
+
56
+ const zIndex = Math.round(
57
+ interpolate(value, [-1, 0, 1], [0, itemSize, 0], Extrapolation.CLAMP)
58
+ );
59
+
60
+ const scale = interpolate(
61
+ value,
62
+ [-1, 0, 1],
63
+ [parallaxAdjacentItemScale, parallaxScrollingScale, parallaxAdjacentItemScale],
64
+ Extrapolation.CLAMP
65
+ );
66
+
67
+ return {
68
+ transform: [
69
+ vertical
70
+ ? {
71
+ translateY: translate,
72
+ }
73
+ : {
74
+ translateX: translate,
75
+ },
76
+ {
77
+ scale,
78
+ },
79
+ ],
80
+ zIndex,
81
+ };
82
+ };
83
+ }