@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,252 @@
1
+ import { horizontalStackLayout, useHorizontalStackLayout, verticalStackLayout } from "./stack";
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
+ // Mock react
25
+ jest.mock("react", () => ({
26
+ useMemo: jest.fn((fn) => fn()),
27
+ }));
28
+
29
+ // Mock Dimensions
30
+ jest.mock("react-native", () => ({
31
+ Dimensions: {
32
+ get: jest.fn(() => ({ width: 375, height: 812 })),
33
+ },
34
+ }));
35
+
36
+ describe("horizontalStackLayout", () => {
37
+ it("should make the rotateZDeg works properly when it is passed in horizontal-stack mode through modeConfig", () => {
38
+ const screenWidth = 375;
39
+
40
+ const calculator = horizontalStackLayout({
41
+ showLength: 3,
42
+ snapDirection: "left",
43
+ moveSize: screenWidth,
44
+ stackInterval: 18,
45
+ scaleInterval: 0.04,
46
+ opacityInterval: 0.1,
47
+ rotateZDeg: 30,
48
+ });
49
+
50
+ const result1 = calculator(-0.5);
51
+ expect(result1).toHaveProperty("transform");
52
+ expect(result1).toHaveProperty("zIndex");
53
+ expect(result1).toHaveProperty("opacity");
54
+ expect(result1.transform).toHaveLength(3);
55
+
56
+ const result2 = calculator(-1);
57
+ expect(result2).toHaveProperty("transform");
58
+ expect(result2).toHaveProperty("zIndex");
59
+ expect(result2).toHaveProperty("opacity");
60
+ expect(result2.transform).toHaveLength(3);
61
+ });
62
+
63
+ it("should handle right snap direction", () => {
64
+ const calculator = horizontalStackLayout({
65
+ showLength: 3,
66
+ snapDirection: "right",
67
+ moveSize: 375,
68
+ stackInterval: 18,
69
+ scaleInterval: 0.04,
70
+ opacityInterval: 0.1,
71
+ rotateZDeg: 30,
72
+ });
73
+
74
+ const result = calculator(0);
75
+ expect(result).toHaveProperty("transform");
76
+ expect(result).toHaveProperty("zIndex");
77
+ expect(result).toHaveProperty("opacity");
78
+ expect(result.transform).toHaveLength(3);
79
+ });
80
+
81
+ it("should handle default config", () => {
82
+ const calculator = horizontalStackLayout();
83
+ const result = calculator(0);
84
+
85
+ expect(result).toHaveProperty("transform");
86
+ expect(result).toHaveProperty("zIndex");
87
+ expect(result).toHaveProperty("opacity");
88
+ });
89
+
90
+ it("should handle edge values", () => {
91
+ const calculator = horizontalStackLayout({
92
+ showLength: 5,
93
+ snapDirection: "left",
94
+ });
95
+
96
+ const extremeLeftResult = calculator(-2);
97
+ const extremeRightResult = calculator(4);
98
+
99
+ expect(extremeLeftResult).toHaveProperty("transform");
100
+ expect(extremeRightResult).toHaveProperty("transform");
101
+ });
102
+
103
+ it("should handle custom parameters", () => {
104
+ const calculator = horizontalStackLayout({
105
+ showLength: 4,
106
+ snapDirection: "right",
107
+ moveSize: 400,
108
+ stackInterval: 25,
109
+ scaleInterval: 0.06,
110
+ opacityInterval: 0.15,
111
+ rotateZDeg: 45,
112
+ });
113
+
114
+ const result = calculator(1);
115
+ expect(result).toHaveProperty("transform");
116
+ expect(result.transform).toHaveLength(3);
117
+ expect(result.transform?.[2]).toHaveProperty("rotateZ");
118
+ });
119
+ });
120
+
121
+ describe("verticalStackLayout", () => {
122
+ it("should handle left snap direction", () => {
123
+ const calculator = verticalStackLayout({
124
+ showLength: 3,
125
+ snapDirection: "left",
126
+ moveSize: 375,
127
+ stackInterval: 18,
128
+ scaleInterval: 0.04,
129
+ opacityInterval: 0.1,
130
+ rotateZDeg: 30,
131
+ });
132
+
133
+ const result = calculator(0);
134
+ expect(result).toHaveProperty("transform");
135
+ expect(result).toHaveProperty("zIndex");
136
+ expect(result).toHaveProperty("opacity");
137
+ expect(result.transform).toHaveLength(4); // includesTranslateY
138
+ expect(result.transform?.[3]).toHaveProperty("translateY");
139
+ });
140
+
141
+ it("should handle right snap direction", () => {
142
+ const calculator = verticalStackLayout({
143
+ showLength: 3,
144
+ snapDirection: "right",
145
+ moveSize: 375,
146
+ stackInterval: 18,
147
+ scaleInterval: 0.04,
148
+ opacityInterval: 0.1,
149
+ rotateZDeg: 30,
150
+ });
151
+
152
+ const result = calculator(0);
153
+ expect(result).toHaveProperty("transform");
154
+ expect(result.transform).toHaveLength(4);
155
+ expect(result.transform?.[3]).toHaveProperty("translateY");
156
+ });
157
+
158
+ it("should handle default config", () => {
159
+ const calculator = verticalStackLayout();
160
+ const result = calculator(0);
161
+
162
+ expect(result).toHaveProperty("transform");
163
+ expect(result).toHaveProperty("zIndex");
164
+ expect(result).toHaveProperty("opacity");
165
+ expect(result.transform).toHaveLength(4);
166
+ });
167
+
168
+ it("should handle different values", () => {
169
+ const calculator = verticalStackLayout({
170
+ showLength: 4,
171
+ snapDirection: "left",
172
+ });
173
+
174
+ const leftResult = calculator(-1);
175
+ const centerResult = calculator(0);
176
+ const rightResult = calculator(1);
177
+
178
+ expect(leftResult).toHaveProperty("transform");
179
+ expect(centerResult).toHaveProperty("transform");
180
+ expect(rightResult).toHaveProperty("transform");
181
+ });
182
+
183
+ it("should handle fractional values", () => {
184
+ const calculator = verticalStackLayout({
185
+ showLength: 3,
186
+ snapDirection: "right",
187
+ });
188
+
189
+ const result = calculator(0.5);
190
+ expect(result).toHaveProperty("transform");
191
+ expect(result.transform).toHaveLength(4);
192
+ });
193
+ });
194
+
195
+ describe("useHorizontalStackLayout", () => {
196
+ it("should return layout and config for left snap direction", () => {
197
+ const customAnimationConfig = {
198
+ snapDirection: "left" as const,
199
+ showLength: 3,
200
+ };
201
+
202
+ const result = useHorizontalStackLayout(customAnimationConfig);
203
+
204
+ expect(result).toHaveProperty("layout");
205
+ expect(result).toHaveProperty("config");
206
+ expect(typeof result.layout).toBe("function");
207
+ expect(result.config.type).toBe("positive");
208
+ expect(result.config.viewCount).toBe(3);
209
+ });
210
+
211
+ it("should return layout and config for right snap direction", () => {
212
+ const customAnimationConfig = {
213
+ snapDirection: "right" as const,
214
+ showLength: 4,
215
+ };
216
+
217
+ const result = useHorizontalStackLayout(customAnimationConfig);
218
+
219
+ expect(result).toHaveProperty("layout");
220
+ expect(result).toHaveProperty("config");
221
+ expect(result.config.type).toBe("negative");
222
+ expect(result.config.viewCount).toBe(4);
223
+ });
224
+
225
+ it("should handle default config", () => {
226
+ const result = useHorizontalStackLayout();
227
+
228
+ expect(result).toHaveProperty("layout");
229
+ expect(result).toHaveProperty("config");
230
+ expect(typeof result.layout).toBe("function");
231
+ expect(result.config.type).toBe("positive"); // Default snapDirection is "left"
232
+ });
233
+
234
+ it("should handle empty custom config", () => {
235
+ const result = useHorizontalStackLayout({}, {});
236
+
237
+ expect(result).toHaveProperty("layout");
238
+ expect(result).toHaveProperty("config");
239
+ });
240
+
241
+ it("should merge custom config correctly", () => {
242
+ const customAnimationConfig = {
243
+ snapDirection: "right" as const,
244
+ showLength: 2,
245
+ };
246
+
247
+ const result = useHorizontalStackLayout(customAnimationConfig);
248
+
249
+ expect(result.config.type).toBe("negative");
250
+ expect(result.config.viewCount).toBe(2);
251
+ });
252
+ });
@@ -0,0 +1,306 @@
1
+ import { useMemo } from "react";
2
+ import type { TransformsStyle, ViewStyle } from "react-native";
3
+ import { Dimensions } from "react-native";
4
+ import { Extrapolation, interpolate } from "react-native-reanimated";
5
+
6
+ import type { CustomConfig, IComputedDirectionTypes } from "../types";
7
+
8
+ const screen = Dimensions.get("window");
9
+
10
+ export interface ILayoutConfig {
11
+ showLength?: number;
12
+ moveSize?: number;
13
+ stackInterval?: number;
14
+ scaleInterval?: number;
15
+ opacityInterval?: number;
16
+ rotateZDeg?: number;
17
+ snapDirection?: "left" | "right";
18
+ }
19
+
20
+ export type TStackModeProps = IComputedDirectionTypes<{
21
+ /**
22
+ * Carousel Animated transitions.
23
+ */
24
+ mode?: "horizontal-stack" | "vertical-stack";
25
+ /**
26
+ * Stack animation style.
27
+ * @default
28
+ * snapDirection: 'right',
29
+ * moveSize: window.width,
30
+ * stackInterval: 30,
31
+ * scaleInterval: 0.08,
32
+ * rotateZDeg: 135,
33
+ * opacityInterval: 0.1,
34
+ */
35
+ modeConfig?: ILayoutConfig;
36
+ }>;
37
+
38
+ export function horizontalStackLayout(modeConfig: ILayoutConfig = {}) {
39
+ return (_value: number) => {
40
+ "worklet";
41
+
42
+ const {
43
+ showLength,
44
+ snapDirection = "left",
45
+ moveSize = screen.width,
46
+ stackInterval = 18,
47
+ scaleInterval = 0.04,
48
+ opacityInterval = 0.1,
49
+ rotateZDeg = 30,
50
+ } = modeConfig;
51
+
52
+ const { validLength, value, inputRange } = getCommonVariables({
53
+ showLength: showLength!,
54
+ value: _value,
55
+ snapDirection,
56
+ });
57
+ const { zIndex, opacity } = getCommonStyles({
58
+ validLength,
59
+ value,
60
+ opacityInterval,
61
+ snapDirection,
62
+ });
63
+
64
+ let translateX: number;
65
+ let scale: number;
66
+ let rotateZ: string;
67
+
68
+ if (snapDirection === "left") {
69
+ translateX = interpolate(
70
+ value,
71
+ inputRange,
72
+ [-moveSize, 0, validLength * stackInterval],
73
+ Extrapolation.CLAMP
74
+ );
75
+ scale = interpolate(
76
+ value,
77
+ inputRange,
78
+ [1, 1, 1 - validLength * scaleInterval],
79
+ Extrapolation.CLAMP
80
+ );
81
+ rotateZ = `${interpolate(value, inputRange, [-rotateZDeg, 0, 0], Extrapolation.CLAMP)}deg`;
82
+ } else if (snapDirection === "right") {
83
+ translateX = interpolate(
84
+ value,
85
+ inputRange,
86
+ [-validLength * stackInterval, 0, moveSize],
87
+ Extrapolation.CLAMP
88
+ );
89
+ scale = interpolate(
90
+ value,
91
+ inputRange,
92
+ [1 - validLength * scaleInterval, 1, 1],
93
+ Extrapolation.CLAMP
94
+ );
95
+ rotateZ = `${interpolate(value, inputRange, [0, 0, rotateZDeg], Extrapolation.CLAMP)}deg`;
96
+ }
97
+
98
+ const transform: TransformsStyle["transform"] = [
99
+ {
100
+ translateX: translateX!,
101
+ },
102
+ {
103
+ scale: scale!,
104
+ },
105
+ {
106
+ rotateZ: rotateZ!,
107
+ },
108
+ ];
109
+
110
+ const styles: ViewStyle = {
111
+ transform,
112
+ zIndex,
113
+ opacity,
114
+ };
115
+
116
+ return styles;
117
+ };
118
+ }
119
+
120
+ export function useHorizontalStackLayout(
121
+ customAnimationConfig: ILayoutConfig = {},
122
+ customConfig: CustomConfig = {}
123
+ ) {
124
+ const config = useMemo(
125
+ () => ({
126
+ type: customAnimationConfig.snapDirection === "right" ? "negative" : "positive",
127
+ viewCount: customAnimationConfig.showLength,
128
+ ...customConfig,
129
+ }),
130
+ [customAnimationConfig, customConfig]
131
+ );
132
+
133
+ return {
134
+ layout: horizontalStackLayout(customAnimationConfig),
135
+ config,
136
+ };
137
+ }
138
+
139
+ export function verticalStackLayout(modeConfig: ILayoutConfig = {}) {
140
+ return (_value: number) => {
141
+ "worklet";
142
+
143
+ const {
144
+ showLength,
145
+ snapDirection = "left",
146
+ moveSize = screen.width,
147
+ stackInterval = 18,
148
+ scaleInterval = 0.04,
149
+ opacityInterval = 0.1,
150
+ rotateZDeg = 30,
151
+ } = modeConfig;
152
+
153
+ const { validLength, value, inputRange } = getCommonVariables({
154
+ showLength: showLength!,
155
+ value: _value,
156
+ snapDirection,
157
+ });
158
+ const { zIndex, opacity } = getCommonStyles({
159
+ validLength,
160
+ value,
161
+ opacityInterval,
162
+ snapDirection,
163
+ });
164
+
165
+ let translateX: number;
166
+ let scale: number;
167
+ let rotateZ: string;
168
+ let translateY: number;
169
+
170
+ if (snapDirection === "left") {
171
+ translateX = interpolate(value, inputRange, [-moveSize, 0, 0], Extrapolation.CLAMP);
172
+ scale = interpolate(
173
+ value,
174
+ inputRange,
175
+ [1, 1, 1 - validLength * scaleInterval],
176
+ Extrapolation.CLAMP
177
+ );
178
+ rotateZ = `${interpolate(value, inputRange, [-rotateZDeg, 0, 0], Extrapolation.CLAMP)}deg`;
179
+ translateY = interpolate(
180
+ value,
181
+ inputRange,
182
+ [0, 0, validLength * stackInterval],
183
+ Extrapolation.CLAMP
184
+ );
185
+ } else if (snapDirection === "right") {
186
+ translateX = interpolate(value, inputRange, [0, 0, moveSize], Extrapolation.CLAMP);
187
+ scale = interpolate(
188
+ value,
189
+ inputRange,
190
+ [1 - validLength * scaleInterval, 1, 1],
191
+ Extrapolation.CLAMP
192
+ );
193
+ rotateZ = `${interpolate(value, inputRange, [0, 0, rotateZDeg], Extrapolation.CLAMP)}deg`;
194
+ translateY = interpolate(
195
+ value,
196
+ inputRange,
197
+ [validLength * stackInterval, 0, 0],
198
+ Extrapolation.CLAMP
199
+ );
200
+ }
201
+
202
+ const transform: TransformsStyle["transform"] = [
203
+ {
204
+ translateX: translateX!,
205
+ },
206
+ {
207
+ scale: scale!,
208
+ },
209
+ {
210
+ rotateZ: rotateZ!,
211
+ },
212
+ {
213
+ translateY: translateY!,
214
+ },
215
+ ];
216
+
217
+ const styles: ViewStyle = {
218
+ transform,
219
+ zIndex,
220
+ opacity,
221
+ };
222
+
223
+ return styles;
224
+ };
225
+ }
226
+
227
+ function getCommonVariables(opts: {
228
+ value: number;
229
+ showLength: number;
230
+ snapDirection: "left" | "right";
231
+ }) {
232
+ "worklet";
233
+
234
+ const { showLength, value: _value, snapDirection } = opts;
235
+ function easeInOutCubic(v: number): number {
236
+ return v < 0.5 ? 4 * v * v * v : 1 - (-2 * v + 2) ** 3 / 2;
237
+ }
238
+ const page = Math.floor(Math.abs(_value));
239
+ const diff = Math.abs(_value) % 1;
240
+ const value = _value < 0 ? -(page + easeInOutCubic(diff)) : page + easeInOutCubic(diff);
241
+ const validLength = showLength! - 1;
242
+
243
+ let inputRange: [number, number, number];
244
+
245
+ if (snapDirection === "left") inputRange = [-1, 0, validLength];
246
+ else if (snapDirection === "right") inputRange = [-validLength, 0, 1];
247
+ else throw new Error("snapDirection must be set to either left or right");
248
+
249
+ return {
250
+ inputRange,
251
+ validLength,
252
+ value,
253
+ };
254
+ }
255
+
256
+ function getCommonStyles(opts: {
257
+ value: number;
258
+ validLength: number;
259
+ opacityInterval: number;
260
+ snapDirection: "left" | "right";
261
+ }) {
262
+ "worklet";
263
+
264
+ const { snapDirection, validLength, value, opacityInterval } = opts;
265
+
266
+ let zIndex: number;
267
+ let opacity: number;
268
+
269
+ if (snapDirection === "left") {
270
+ zIndex =
271
+ Math.floor(
272
+ interpolate(
273
+ value,
274
+ [-1.5, -1, -1 + Number.MIN_VALUE, 0, validLength],
275
+ [Number.MIN_VALUE, validLength, validLength, validLength - 1, -1]
276
+ ) * 10000
277
+ ) / 100;
278
+
279
+ opacity = interpolate(
280
+ value,
281
+ [-1, 0, validLength - 1, validLength],
282
+ [0.25, 1, 1 - (validLength - 1) * opacityInterval, 0.25]
283
+ );
284
+ } else if (snapDirection === "right") {
285
+ zIndex =
286
+ Math.floor(
287
+ interpolate(
288
+ value,
289
+ [-validLength, 0, 1 - Number.MIN_VALUE, 1, 1.5],
290
+ [1, validLength - 1, validLength, validLength, Number.MIN_VALUE]
291
+ ) * 10000
292
+ ) / 100;
293
+ opacity = interpolate(
294
+ value,
295
+ [-validLength, 1 - validLength, 0, 1],
296
+ [0.25, 1 - (validLength - 1) * opacityInterval, 1, 0.25]
297
+ );
298
+ } else {
299
+ throw new Error("snapDirection must be set to either left or right");
300
+ }
301
+
302
+ return {
303
+ zIndex: Math.round(zIndex),
304
+ opacity,
305
+ };
306
+ }