@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,134 @@
1
+ import React from "react";
2
+ import { Text } from "react-native";
3
+
4
+ import { renderHook } from "@testing-library/react-hooks";
5
+
6
+ import { useInitProps } from "./useInitProps";
7
+
8
+ import type { TCarouselProps } from "../types";
9
+
10
+ describe("useInitProps", () => {
11
+ const defaultData = [1, 2, 3, 4];
12
+ const defaultProps: TCarouselProps<number> = {
13
+ data: defaultData,
14
+ width: 300,
15
+ height: 200,
16
+ renderItem: ({ item: _item }) => <Text>Item</Text>,
17
+ };
18
+
19
+ it("should initialize with default values", () => {
20
+ const { result } = renderHook(() => useInitProps(defaultProps));
21
+
22
+ expect(result.current).toEqual(
23
+ expect.objectContaining({
24
+ defaultIndex: 0,
25
+ loop: true,
26
+ autoPlayInterval: 1000,
27
+ scrollAnimationDuration: 500,
28
+ width: 300,
29
+ height: 200,
30
+ enabled: true,
31
+ autoFillData: true,
32
+ pagingEnabled: true,
33
+ snapEnabled: true,
34
+ overscrollEnabled: true,
35
+ data: defaultData,
36
+ rawData: defaultData,
37
+ dataLength: 4,
38
+ rawDataLength: 4,
39
+ })
40
+ );
41
+ });
42
+
43
+ it("should handle custom values", () => {
44
+ const customProps: TCarouselProps<number> = {
45
+ ...defaultProps,
46
+ defaultIndex: 2,
47
+ loop: false,
48
+ autoPlayInterval: 2000,
49
+ scrollAnimationDuration: 300,
50
+ enabled: false,
51
+ autoFillData: false,
52
+ pagingEnabled: false,
53
+ snapEnabled: false,
54
+ overscrollEnabled: false,
55
+ };
56
+
57
+ const { result } = renderHook(() => useInitProps(customProps));
58
+
59
+ expect(result.current).toEqual(
60
+ expect.objectContaining({
61
+ ...customProps,
62
+ data: defaultData,
63
+ rawData: defaultData,
64
+ dataLength: 4,
65
+ rawDataLength: 4,
66
+ })
67
+ );
68
+ });
69
+ it("should handle stack mode configuration", () => {
70
+ const stackProps: TCarouselProps<number> = {
71
+ ...defaultProps,
72
+ mode: "horizontal-stack",
73
+ modeConfig: {
74
+ showLength: 3,
75
+ },
76
+ };
77
+
78
+ const { result } = renderHook(() => useInitProps(stackProps));
79
+
80
+ expect(result.current.modeConfig).toBeDefined();
81
+ if (result.current.modeConfig && "showLength" in result.current.modeConfig)
82
+ expect(result.current.modeConfig.showLength).toBe(3); // dataLength - 1
83
+ });
84
+
85
+ it("should handle empty data array", () => {
86
+ const props: TCarouselProps<number> = {
87
+ ...defaultProps,
88
+ data: [],
89
+ };
90
+
91
+ const { result } = renderHook(() => useInitProps(props));
92
+
93
+ expect(result.current.dataLength).toBe(0);
94
+ expect(result.current.rawDataLength).toBe(0);
95
+ });
96
+
97
+ it("should round width and height values", () => {
98
+ const props: TCarouselProps<number> = {
99
+ ...defaultProps,
100
+ width: 300.6,
101
+ height: 200.4,
102
+ };
103
+
104
+ const { result } = renderHook(() => useInitProps(props));
105
+
106
+ expect(result.current.width).toBe(301);
107
+ expect(result.current.height).toBe(200);
108
+ });
109
+
110
+ it("should handle enableSnap property", () => {
111
+ const props: TCarouselProps<number> = {
112
+ ...defaultProps,
113
+ enableSnap: false,
114
+ };
115
+
116
+ const { result } = renderHook(() => useInitProps(props));
117
+
118
+ expect(result.current.snapEnabled).toBe(false);
119
+ });
120
+ it("should handle vertical-stack mode", () => {
121
+ const props: TCarouselProps<number> = {
122
+ ...defaultProps,
123
+ mode: "vertical-stack",
124
+ modeConfig: {
125
+ showLength: 3,
126
+ },
127
+ };
128
+
129
+ const { result } = renderHook(() => useInitProps(props));
130
+ expect(result.current.modeConfig).toBeDefined();
131
+ if (result.current.modeConfig && "showLength" in result.current.modeConfig)
132
+ expect(result.current.modeConfig.showLength).toBe(3); // dataLength - 1
133
+ });
134
+ });
@@ -0,0 +1,111 @@
1
+ import React from "react";
2
+
3
+ import type { TCarouselProps } from "../types";
4
+ import { computedFillDataWithAutoFillData } from "../utils/computed-with-auto-fill-data";
5
+
6
+ type TGetRequiredProps<P extends keyof TCarouselProps> = Record<P, Required<TCarouselProps>[P]>;
7
+
8
+ export type TInitializeCarouselProps<T> = TCarouselProps<T> &
9
+ TGetRequiredProps<
10
+ "defaultIndex" | "loop" | "scrollAnimationDuration" | "autoPlayInterval" | "autoFillData"
11
+ > & {
12
+ // Raw data that has not been processed
13
+ rawData: T[];
14
+ dataLength: number;
15
+ rawDataLength: number;
16
+ /**
17
+ * Axis-aware item-size getter — `getItemHeight` when vertical, otherwise
18
+ * `getItemWidth`. Undefined unless the user supplied the matching prop.
19
+ */
20
+ getItemSize?: (index: number) => number;
21
+ /** `true` when variable-size mode is active (`getItemSize` is set). */
22
+ variableSize: boolean;
23
+ };
24
+
25
+ export function useInitProps<T>(props: TCarouselProps<T>): TInitializeCarouselProps<T> {
26
+ const {
27
+ defaultIndex = 0,
28
+ data: rawData = [],
29
+ loop = true,
30
+ autoPlayInterval: _autoPlayInterval = 1000,
31
+ scrollAnimationDuration = 500,
32
+ style = {},
33
+ autoFillData = true,
34
+ // switchers
35
+ enabled = true,
36
+ pagingEnabled = true,
37
+ overscrollEnabled = true,
38
+ snapEnabled = props.enableSnap ?? true,
39
+ width: _width,
40
+ height: _height,
41
+ itemWidth: _itemWidth,
42
+ itemHeight: _itemHeight,
43
+ getItemWidth,
44
+ getItemHeight,
45
+ vertical,
46
+ } = props;
47
+
48
+ const width = typeof _width === "number" ? Math.round(_width) : undefined;
49
+ const height = typeof _height === "number" ? Math.round(_height) : undefined;
50
+ const itemWidth = typeof _itemWidth === "number" && _itemWidth > 0 ? _itemWidth : undefined;
51
+ const itemHeight = typeof _itemHeight === "number" && _itemHeight > 0 ? _itemHeight : undefined;
52
+ const autoPlayInterval = Math.max(_autoPlayInterval, 0);
53
+
54
+ // Axis-aware variable-size getter. When `getItemWidth`/`getItemHeight` is
55
+ // provided for the active axis, variable-size mode is enabled downstream.
56
+ const getItemSize = vertical ? getItemHeight : getItemWidth;
57
+ const variableSize = typeof getItemSize === "function";
58
+
59
+ // autoFillData duplicates data assuming a single page size; it produces
60
+ // incorrect totals once items differ in size. Disable it silently in
61
+ // variable-size mode (`usePropsErrorBoundary` warns the user).
62
+ const effectiveAutoFillData = variableSize ? false : autoFillData;
63
+
64
+ const data = React.useMemo<T[]>(() => {
65
+ return computedFillDataWithAutoFillData<T>({
66
+ loop,
67
+ autoFillData: effectiveAutoFillData,
68
+ data: rawData,
69
+ dataLength: rawData.length,
70
+ });
71
+ }, [rawData, loop, effectiveAutoFillData]);
72
+
73
+ const dataLength = data.length;
74
+ const rawDataLength = rawData.length;
75
+
76
+ if (props.mode === "vertical-stack" || props.mode === "horizontal-stack") {
77
+ if (!props.modeConfig) props.modeConfig = {};
78
+
79
+ props.modeConfig.showLength = props.modeConfig?.showLength ?? dataLength - 1;
80
+ }
81
+
82
+ return {
83
+ ...props,
84
+ defaultIndex,
85
+ autoFillData: effectiveAutoFillData,
86
+ // Fill data with autoFillData
87
+ data,
88
+ // Length of fill data
89
+ dataLength,
90
+ // Raw data that has not been processed
91
+ rawData,
92
+ // Length of raw data
93
+ rawDataLength,
94
+ loop,
95
+ enabled,
96
+ autoPlayInterval,
97
+ scrollAnimationDuration,
98
+ style,
99
+ pagingEnabled,
100
+ snapEnabled,
101
+ overscrollEnabled,
102
+ width,
103
+ height,
104
+ itemWidth,
105
+ itemHeight,
106
+ getItemWidth,
107
+ getItemHeight,
108
+ getItemSize,
109
+ variableSize,
110
+ };
111
+ }
@@ -0,0 +1,247 @@
1
+ import React from "react";
2
+ import { View } from "react-native";
3
+
4
+ import { renderHook } from "@testing-library/react-hooks";
5
+
6
+ import { useLayoutConfig } from "./useLayoutConfig";
7
+
8
+ describe("useLayoutConfig", () => {
9
+ const defaultProps = {
10
+ size: 300,
11
+ vertical: false,
12
+ };
13
+ it("should return normal layout by default", () => {
14
+ const { result } = renderHook(() =>
15
+ useLayoutConfig({
16
+ ...defaultProps,
17
+ data: [],
18
+ renderItem: () => <View />,
19
+ loop: false,
20
+ autoFillData: false,
21
+ defaultIndex: 0,
22
+ autoPlayInterval: 0,
23
+ scrollAnimationDuration: 0,
24
+ width: 0,
25
+ height: 0,
26
+ rawData: [],
27
+ dataLength: 0,
28
+ rawDataLength: 0,
29
+ })
30
+ );
31
+
32
+ expect(result.current).toBeDefined();
33
+ expect(typeof result.current).toBe("function");
34
+ });
35
+
36
+ it("should handle parallax mode", () => {
37
+ const props = {
38
+ ...defaultProps,
39
+ mode: "parallax" as const,
40
+ modeConfig: {
41
+ parallaxScrollingScale: 0.9,
42
+ parallaxScrollingOffset: 50,
43
+ parallaxAdjacentItemScale: 0.8,
44
+ },
45
+ };
46
+
47
+ const { result } = renderHook(() =>
48
+ useLayoutConfig({
49
+ ...props,
50
+ data: [],
51
+ renderItem: () => <View />,
52
+ loop: false,
53
+ autoFillData: false,
54
+ defaultIndex: 0,
55
+ autoPlayInterval: 0,
56
+ scrollAnimationDuration: 0,
57
+ width: 0,
58
+ height: 0,
59
+ rawData: [],
60
+ dataLength: 0,
61
+ rawDataLength: 0,
62
+ })
63
+ );
64
+ const style = result.current(0); // Test with offset 0
65
+
66
+ expect(style.transform).toBeDefined();
67
+ expect(style.transform).toContainEqual({ translateX: 0 });
68
+ expect(style.transform).toContainEqual({ scale: 0.9 });
69
+ });
70
+
71
+ it("should handle horizontal-stack mode", () => {
72
+ const props = {
73
+ ...defaultProps,
74
+ mode: "horizontal-stack" as const,
75
+ modeConfig: {
76
+ snapDirection: "left" as const,
77
+ showLength: 3,
78
+ },
79
+ };
80
+
81
+ const { result } = renderHook(() =>
82
+ useLayoutConfig({
83
+ ...props,
84
+ data: [],
85
+ renderItem: () => <View />,
86
+ loop: false,
87
+ autoFillData: false,
88
+ defaultIndex: 0,
89
+ autoPlayInterval: 0,
90
+ scrollAnimationDuration: 0,
91
+ width: 0,
92
+ height: 0,
93
+ rawData: [],
94
+ dataLength: 0,
95
+ rawDataLength: 0,
96
+ })
97
+ );
98
+ const style = result.current(0); // Test with offset 0
99
+
100
+ expect(style.transform).toBeDefined();
101
+ expect(style.zIndex).toBeDefined();
102
+ expect(style.opacity).toBeDefined();
103
+ });
104
+
105
+ it("should handle vertical-stack mode", () => {
106
+ const props = {
107
+ ...defaultProps,
108
+ mode: "vertical-stack" as const,
109
+ modeConfig: {
110
+ snapDirection: "left" as const,
111
+ showLength: 3,
112
+ },
113
+ };
114
+
115
+ const { result } = renderHook(() =>
116
+ useLayoutConfig({
117
+ ...props,
118
+ data: [],
119
+ renderItem: () => <View />,
120
+ loop: false,
121
+ autoFillData: false,
122
+ defaultIndex: 0,
123
+ autoPlayInterval: 0,
124
+ scrollAnimationDuration: 0,
125
+ width: 0,
126
+ height: 0,
127
+ rawData: [],
128
+ dataLength: 0,
129
+ rawDataLength: 0,
130
+ })
131
+ );
132
+ const style = result.current(0); // Test with offset 0
133
+
134
+ expect(style.transform).toBeDefined();
135
+ expect(style.zIndex).toBeDefined();
136
+ expect(style.opacity).toBeDefined();
137
+ });
138
+
139
+ it("should handle vertical orientation", () => {
140
+ const props = {
141
+ ...defaultProps,
142
+ vertical: true,
143
+ };
144
+
145
+ const { result } = renderHook(() =>
146
+ useLayoutConfig({
147
+ ...props,
148
+ data: [],
149
+ renderItem: () => <View />,
150
+ loop: false,
151
+ autoFillData: false,
152
+ defaultIndex: 0,
153
+ autoPlayInterval: 0,
154
+ scrollAnimationDuration: 0,
155
+ width: 0,
156
+ height: 0,
157
+ rawData: [],
158
+ dataLength: 0,
159
+ rawDataLength: 0,
160
+ })
161
+ );
162
+ const style = result.current(0); // Test with offset 0
163
+
164
+ expect(style.transform).toBeDefined();
165
+ expect(style.transform).toContainEqual({ translateY: 0 });
166
+ });
167
+
168
+ it("should handle different offsets", () => {
169
+ const { result } = renderHook(() =>
170
+ useLayoutConfig({
171
+ ...defaultProps,
172
+ data: [],
173
+ renderItem: () => <View />,
174
+ loop: false,
175
+ autoFillData: false,
176
+ defaultIndex: 0,
177
+ autoPlayInterval: 0,
178
+ scrollAnimationDuration: 0,
179
+ width: 0,
180
+ height: 0,
181
+ rawData: [],
182
+ dataLength: 0,
183
+ rawDataLength: 0,
184
+ })
185
+ );
186
+
187
+ const style1 = result.current(-1); // Previous item
188
+ const style2 = result.current(0); // Current item
189
+ const style3 = result.current(1); // Next item
190
+
191
+ expect(style1.transform).toContainEqual({ translateX: -300 });
192
+ expect(style2.transform).toContainEqual({ translateX: 0 });
193
+ expect(style3.transform).toContainEqual({ translateX: 300 });
194
+ });
195
+
196
+ it("should memoize layout function", () => {
197
+ const { result, rerender } = renderHook(() =>
198
+ useLayoutConfig({
199
+ ...defaultProps,
200
+ data: [],
201
+ renderItem: () => <View />,
202
+ loop: false,
203
+ autoFillData: false,
204
+ defaultIndex: 0,
205
+ autoPlayInterval: 0,
206
+ scrollAnimationDuration: 0,
207
+ width: 0,
208
+ height: 0,
209
+ rawData: [],
210
+ dataLength: 0,
211
+ rawDataLength: 0,
212
+ })
213
+ );
214
+ const firstResult = result.current;
215
+
216
+ rerender();
217
+ expect(result.current).toBe(firstResult);
218
+ });
219
+
220
+ it("should update layout when props change", () => {
221
+ const { result, rerender } = renderHook(
222
+ (props) =>
223
+ useLayoutConfig({
224
+ ...props,
225
+ data: [],
226
+ renderItem: () => <View />,
227
+ loop: false,
228
+ autoFillData: false,
229
+ defaultIndex: 0,
230
+ autoPlayInterval: 0,
231
+ scrollAnimationDuration: 0,
232
+ width: 0,
233
+ height: 0,
234
+ rawData: [],
235
+ dataLength: 0,
236
+ rawDataLength: 0,
237
+ }),
238
+ {
239
+ initialProps: defaultProps,
240
+ }
241
+ );
242
+ const firstResult = result.current;
243
+
244
+ rerender({ ...defaultProps, size: 400 });
245
+ expect(result.current).not.toBe(firstResult);
246
+ });
247
+ });
@@ -0,0 +1,30 @@
1
+ import React from "react";
2
+
3
+ import type { TInitializeCarouselProps } from "./useInitProps";
4
+
5
+ import type { TAnimationStyle } from "../components/ItemLayout";
6
+ import { Layouts } from "../layouts";
7
+ import type { SizeResolver } from "../utils/size-resolver";
8
+
9
+ type TLayoutConfigOpts<T> = TInitializeCarouselProps<T> & {
10
+ size: number;
11
+ sizeResolver?: SizeResolver;
12
+ };
13
+
14
+ export function useLayoutConfig<T>(opts: TLayoutConfigOpts<T>): TAnimationStyle {
15
+ const { size, vertical, sizeResolver } = opts as Required<TLayoutConfigOpts<T>>;
16
+
17
+ return React.useMemo(() => {
18
+ const baseConfig = { size, vertical, sizeResolver };
19
+ switch (opts.mode) {
20
+ case "parallax":
21
+ return Layouts.parallax(baseConfig, opts.modeConfig);
22
+ case "horizontal-stack":
23
+ return Layouts.horizontalStack(opts.modeConfig);
24
+ case "vertical-stack":
25
+ return Layouts.verticalStack(opts.modeConfig);
26
+ default:
27
+ return Layouts.normal(baseConfig);
28
+ }
29
+ }, [opts.mode, opts.modeConfig, size, vertical, sizeResolver]);
30
+ }
@@ -0,0 +1,110 @@
1
+ import { useSharedValue } from "react-native-reanimated";
2
+
3
+ import { renderHook } from "@testing-library/react-hooks";
4
+
5
+ import { buildPrefixSum, createVariableSizeResolver } from "../utils/size-resolver";
6
+
7
+ import type { IOpts } from "./useOffsetX";
8
+ import { useOffsetX } from "./useOffsetX";
9
+ import type { IVisibleRanges } from "./useVisibleRanges";
10
+
11
+ describe("useSharedValue", () => {
12
+ it("should return the correct values", async () => {
13
+ const hook = renderHook(() => {
14
+ const range = useSharedValue({
15
+ negativeRange: [7, 9],
16
+ positiveRange: [0, 3],
17
+ }) as IVisibleRanges;
18
+ const inputs: Array<{
19
+ config: IOpts;
20
+ range: IVisibleRanges;
21
+ }> = Array.from({ length: 10 }).map((_, index) => ({
22
+ config: {
23
+ dataLength: 10,
24
+ handlerOffset: useSharedValue(-0),
25
+ index,
26
+ loop: false,
27
+ size: 393,
28
+ },
29
+ range,
30
+ }));
31
+
32
+ return inputs.map((input) => {
33
+ const { config, range } = input;
34
+
35
+ return useOffsetX(config, range);
36
+ });
37
+ });
38
+
39
+ const expected = hook.result.current.map((v) => v.value).slice();
40
+
41
+ expect(expected).toMatchInlineSnapshot(`
42
+ [
43
+ 0,
44
+ 393,
45
+ 786,
46
+ 1179,
47
+ 9007199254740991,
48
+ 9007199254740991,
49
+ 9007199254740991,
50
+ 2751,
51
+ 3144,
52
+ 3537,
53
+ ]
54
+ `);
55
+ });
56
+ });
57
+
58
+ describe("useOffsetX (variable size)", () => {
59
+ it("returns cumulative offsets in non-loop mode when resolver is supplied", () => {
60
+ const widths = [80, 150, 220, 100, 300, 100, 120, 200, 90, 180];
61
+ const built = buildPrefixSum(widths.length, (i) => widths[i]);
62
+
63
+ const hook = renderHook(() => {
64
+ const range = useSharedValue({
65
+ negativeRange: [7, 9],
66
+ positiveRange: [0, 3],
67
+ }) as IVisibleRanges;
68
+ const sizes = useSharedValue(built.sizes);
69
+ const prefix = useSharedValue(built.prefix);
70
+ const total = useSharedValue(built.total);
71
+ const count = useSharedValue(widths.length);
72
+ const resolver = createVariableSizeResolver({ sizes, prefix, total, count });
73
+
74
+ const inputs: Array<{ config: IOpts; range: IVisibleRanges }> = Array.from({
75
+ length: 10,
76
+ }).map((_, index) => ({
77
+ config: {
78
+ dataLength: 10,
79
+ handlerOffset: useSharedValue(-0),
80
+ index,
81
+ loop: false,
82
+ size: 0, // unused once resolver is supplied
83
+ resolver,
84
+ },
85
+ range,
86
+ }));
87
+
88
+ return inputs.map(({ config, range }) => useOffsetX(config, range));
89
+ });
90
+
91
+ const expected = hook.result.current.map((v) => v.value);
92
+
93
+ // Items 0..3 are in the positive range, so they get their cumulative
94
+ // offsets. Items 4..6 are out of the visible window — sentinel.
95
+ // Items 7..9 are in the negative range, so they get their cumulative
96
+ // offsets too.
97
+ expect(expected).toEqual([
98
+ 0,
99
+ 80,
100
+ 230,
101
+ 450,
102
+ Number.MAX_SAFE_INTEGER,
103
+ Number.MAX_SAFE_INTEGER,
104
+ Number.MAX_SAFE_INTEGER,
105
+ built.prefix[7],
106
+ built.prefix[8],
107
+ built.prefix[9],
108
+ ]);
109
+ });
110
+ });