@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,314 @@
1
+ import { act, render } from "@testing-library/react-native";
2
+ import React from "react";
3
+ import { Text } from "react-native";
4
+
5
+ import { ICommonVariables } from "../hooks/useCommonVariables";
6
+ import { GlobalStateContext, GlobalStateProvider, IContext, useGlobalState } from "./index";
7
+
8
+ const createSharedValue = <T,>(initial: T) => ({ value: initial });
9
+
10
+ describe("GlobalStateProvider", () => {
11
+ const mockProps = {
12
+ width: 300,
13
+ height: 200,
14
+ data: [1, 2, 3],
15
+ renderItem: () => <Text>Item</Text>,
16
+ } as any;
17
+
18
+ const mockCommon = {
19
+ size: 300,
20
+ validLength: 3,
21
+ handlerOffset: createSharedValue(0),
22
+ resolvedSize: createSharedValue<number | null>(300),
23
+ sizePhase: createSharedValue("ready" as const),
24
+ } as ICommonVariables;
25
+
26
+ const mockValue: Pick<IContext, "props" | "common"> = {
27
+ props: mockProps,
28
+ common: mockCommon,
29
+ };
30
+
31
+ it("should render children correctly", () => {
32
+ const { getByText } = render(
33
+ <GlobalStateProvider value={mockValue}>
34
+ <Text>Test Child</Text>
35
+ </GlobalStateProvider>
36
+ );
37
+
38
+ expect(getByText("Test Child")).toBeTruthy();
39
+ });
40
+
41
+ it("should provide context value with layout methods", () => {
42
+ let contextValue: any;
43
+
44
+ const TestComponent = () => {
45
+ contextValue = React.useContext(GlobalStateContext);
46
+ return <Text>Test</Text>;
47
+ };
48
+
49
+ render(
50
+ <GlobalStateProvider value={mockValue}>
51
+ <TestComponent />
52
+ </GlobalStateProvider>
53
+ );
54
+
55
+ expect(contextValue).toHaveProperty("props");
56
+ expect(contextValue).toHaveProperty("common");
57
+ expect(contextValue).toHaveProperty("layout");
58
+ expect(contextValue.layout).toHaveProperty("containerSize");
59
+ expect(contextValue.layout).toHaveProperty("itemDimensions");
60
+ expect(contextValue.layout).toHaveProperty("updateItemDimensions");
61
+ expect(contextValue.layout).toHaveProperty("updateContainerSize");
62
+ });
63
+
64
+ it("should initialize containerSize with default values", () => {
65
+ let contextValue: any;
66
+
67
+ const TestComponent = () => {
68
+ contextValue = React.useContext(GlobalStateContext);
69
+ return <Text>Test</Text>;
70
+ };
71
+
72
+ render(
73
+ <GlobalStateProvider value={mockValue}>
74
+ <TestComponent />
75
+ </GlobalStateProvider>
76
+ );
77
+
78
+ expect(contextValue.layout.containerSize.value).toEqual({ width: 0, height: 0 });
79
+ });
80
+
81
+ it("should initialize itemDimensions with empty object", () => {
82
+ let contextValue: any;
83
+
84
+ const TestComponent = () => {
85
+ contextValue = React.useContext(GlobalStateContext);
86
+ return <Text>Test</Text>;
87
+ };
88
+
89
+ render(
90
+ <GlobalStateProvider value={mockValue}>
91
+ <TestComponent />
92
+ </GlobalStateProvider>
93
+ );
94
+
95
+ expect(contextValue.layout.itemDimensions.value).toEqual({});
96
+ });
97
+
98
+ it("should provide updateItemDimensions function", () => {
99
+ let contextValue: any;
100
+
101
+ const TestComponent = () => {
102
+ contextValue = React.useContext(GlobalStateContext);
103
+ return <Text>Test</Text>;
104
+ };
105
+
106
+ render(
107
+ <GlobalStateProvider value={mockValue}>
108
+ <TestComponent />
109
+ </GlobalStateProvider>
110
+ );
111
+
112
+ expect(typeof contextValue.layout.updateItemDimensions).toBe("function");
113
+
114
+ act(() => {
115
+ contextValue.layout.updateItemDimensions(0, { width: 100, height: 50 });
116
+ });
117
+
118
+ expect(contextValue.layout.itemDimensions.value).toEqual({
119
+ 0: { width: 100, height: 50 },
120
+ });
121
+ });
122
+
123
+ it("should provide updateContainerSize function", () => {
124
+ let contextValue: any;
125
+
126
+ const TestComponent = () => {
127
+ contextValue = React.useContext(GlobalStateContext);
128
+ return <Text>Test</Text>;
129
+ };
130
+
131
+ render(
132
+ <GlobalStateProvider value={mockValue}>
133
+ <TestComponent />
134
+ </GlobalStateProvider>
135
+ );
136
+
137
+ expect(typeof contextValue.layout.updateContainerSize).toBe("function");
138
+
139
+ act(() => {
140
+ contextValue.layout.updateContainerSize({ width: 400, height: 300 });
141
+ });
142
+
143
+ expect(contextValue.layout.containerSize.value).toEqual({ width: 400, height: 300 });
144
+ });
145
+
146
+ it("should merge props and common with layout", () => {
147
+ let contextValue: any;
148
+
149
+ const TestComponent = () => {
150
+ contextValue = React.useContext(GlobalStateContext);
151
+ return <Text>Test</Text>;
152
+ };
153
+
154
+ render(
155
+ <GlobalStateProvider value={mockValue}>
156
+ <TestComponent />
157
+ </GlobalStateProvider>
158
+ );
159
+
160
+ expect(contextValue.props).toEqual(mockProps);
161
+ expect(contextValue.common).toEqual(mockCommon);
162
+ });
163
+
164
+ it("should handle multiple children", () => {
165
+ const { getByText } = render(
166
+ <GlobalStateProvider value={mockValue}>
167
+ <Text>First Child</Text>
168
+ <Text>Second Child</Text>
169
+ </GlobalStateProvider>
170
+ );
171
+
172
+ expect(getByText("First Child")).toBeTruthy();
173
+ expect(getByText("Second Child")).toBeTruthy();
174
+ });
175
+
176
+ it("should handle updateItemDimensions with multiple items", () => {
177
+ let contextValue: any;
178
+
179
+ const TestComponent = () => {
180
+ contextValue = React.useContext(GlobalStateContext);
181
+ return <Text>Test</Text>;
182
+ };
183
+
184
+ render(
185
+ <GlobalStateProvider value={mockValue}>
186
+ <TestComponent />
187
+ </GlobalStateProvider>
188
+ );
189
+
190
+ act(() => {
191
+ contextValue.layout.updateItemDimensions(0, { width: 100, height: 50 });
192
+ contextValue.layout.updateItemDimensions(1, { width: 120, height: 60 });
193
+ contextValue.layout.updateItemDimensions(2, { width: 90, height: 45 });
194
+ });
195
+
196
+ expect(contextValue.layout.itemDimensions.value).toEqual({
197
+ 0: { width: 100, height: 50 },
198
+ 1: { width: 120, height: 60 },
199
+ 2: { width: 90, height: 45 },
200
+ });
201
+ });
202
+ });
203
+
204
+ describe("useGlobalState", () => {
205
+ const mockValue: Pick<IContext, "props" | "common"> = {
206
+ props: { width: 300, data: [1, 2, 3], renderItem: () => <Text>Item</Text> } as any,
207
+ common: {
208
+ size: 300,
209
+ validLength: 3,
210
+ handlerOffset: createSharedValue(0),
211
+ resolvedSize: createSharedValue<number | null>(300),
212
+ sizePhase: createSharedValue("ready" as const),
213
+ } as ICommonVariables,
214
+ };
215
+
216
+ it("should return context value when used within provider", () => {
217
+ let hookResult: any;
218
+
219
+ const TestComponent = () => {
220
+ hookResult = useGlobalState();
221
+ return <Text>Test</Text>;
222
+ };
223
+
224
+ render(
225
+ <GlobalStateProvider value={mockValue}>
226
+ <TestComponent />
227
+ </GlobalStateProvider>
228
+ );
229
+
230
+ expect(hookResult).toHaveProperty("props");
231
+ expect(hookResult).toHaveProperty("common");
232
+ expect(hookResult).toHaveProperty("layout");
233
+ });
234
+
235
+ it("should provide expected hook functionality", () => {
236
+ let hookResult: any;
237
+
238
+ const TestComponent = () => {
239
+ hookResult = useGlobalState();
240
+ return <Text>Test</Text>;
241
+ };
242
+
243
+ const mockValue: Pick<IContext, "props" | "common"> = {
244
+ props: { width: 300, data: [1, 2, 3], renderItem: () => <Text>Item</Text> } as any,
245
+ common: { size: 300, validLength: 3 } as ICommonVariables,
246
+ };
247
+
248
+ render(
249
+ <GlobalStateProvider value={mockValue}>
250
+ <TestComponent />
251
+ </GlobalStateProvider>
252
+ );
253
+
254
+ expect(hookResult).toHaveProperty("props");
255
+ expect(hookResult).toHaveProperty("common");
256
+ expect(hookResult).toHaveProperty("layout");
257
+ });
258
+
259
+ it("should return the same context value as directly accessing context", () => {
260
+ let hookResult: any;
261
+ let contextResult: any;
262
+
263
+ const TestComponent = () => {
264
+ hookResult = useGlobalState();
265
+ contextResult = React.useContext(GlobalStateContext);
266
+ return <Text>Test</Text>;
267
+ };
268
+
269
+ render(
270
+ <GlobalStateProvider value={mockValue}>
271
+ <TestComponent />
272
+ </GlobalStateProvider>
273
+ );
274
+
275
+ expect(hookResult).toBe(contextResult);
276
+ });
277
+
278
+ it("should provide all expected properties", () => {
279
+ let hookResult: any;
280
+
281
+ const TestComponent = () => {
282
+ hookResult = useGlobalState();
283
+ return <Text>Test</Text>;
284
+ };
285
+
286
+ render(
287
+ <GlobalStateProvider value={mockValue}>
288
+ <TestComponent />
289
+ </GlobalStateProvider>
290
+ );
291
+
292
+ expect(hookResult.props).toEqual(mockValue.props);
293
+ expect(hookResult.common).toEqual(mockValue.common);
294
+ expect(hookResult.layout).toHaveProperty("containerSize");
295
+ expect(hookResult.layout).toHaveProperty("itemDimensions");
296
+ expect(hookResult.layout).toHaveProperty("updateItemDimensions");
297
+ expect(hookResult.layout).toHaveProperty("updateContainerSize");
298
+ });
299
+ });
300
+
301
+ describe("GlobalStateContext", () => {
302
+ it("should have default empty context value", () => {
303
+ let contextValue: any;
304
+
305
+ const TestComponent = () => {
306
+ contextValue = React.useContext(GlobalStateContext);
307
+ return <Text>Test</Text>;
308
+ };
309
+
310
+ render(<TestComponent />);
311
+
312
+ expect(contextValue).toEqual({});
313
+ });
314
+ });
@@ -0,0 +1,66 @@
1
+ import React from "react";
2
+
3
+ import { SharedValue, useSharedValue } from "react-native-reanimated";
4
+ import type { ICommonVariables } from "../hooks/useCommonVariables";
5
+ import type { TInitializeCarouselProps } from "../hooks/useInitProps";
6
+ import type { SizeResolver } from "../utils/size-resolver";
7
+
8
+ type ItemDimensions = Record<number, { width: number; height: number }>;
9
+
10
+ export interface IContext {
11
+ props: TInitializeCarouselProps<any>;
12
+ common: ICommonVariables;
13
+ /** Per-item size resolver (uniform or variable). */
14
+ sizeResolver: SizeResolver;
15
+ layout: {
16
+ containerSize: SharedValue<{ width: number; height: number }>;
17
+ updateContainerSize: (dimensions: { width: number; height: number }) => void;
18
+ itemDimensions: SharedValue<ItemDimensions>;
19
+ updateItemDimensions: (index: number, dimensions: { width: number; height: number }) => void;
20
+ };
21
+ }
22
+
23
+ export const GlobalStateContext = React.createContext<IContext>({} as IContext);
24
+
25
+ export const GlobalStateProvider = ({
26
+ children,
27
+ value,
28
+ }: {
29
+ children: React.ReactNode;
30
+ value: Pick<IContext, "props" | "common" | "sizeResolver">;
31
+ }) => {
32
+ const containerSize = useSharedValue<{ width: number; height: number }>({ width: 0, height: 0 });
33
+ const itemDimensions = useSharedValue<ItemDimensions>({});
34
+
35
+ const updateItemDimensions = (index: number, dimensions: { width: number; height: number }) => {
36
+ "worklet";
37
+
38
+ itemDimensions.value = { ...itemDimensions.value, [index]: dimensions };
39
+ };
40
+
41
+ const updateContainerSize = (dimensions: { width: number; height: number }) => {
42
+ "worklet";
43
+ containerSize.value = dimensions;
44
+ };
45
+
46
+ return (
47
+ <GlobalStateContext.Provider
48
+ value={{
49
+ ...value,
50
+ layout: { containerSize, itemDimensions, updateItemDimensions, updateContainerSize },
51
+ }}
52
+ >
53
+ {children}
54
+ </GlobalStateContext.Provider>
55
+ );
56
+ };
57
+
58
+ export const useGlobalState = () => {
59
+ const context = React.useContext(GlobalStateContext);
60
+
61
+ if (!context) {
62
+ throw new Error("useGlobalState must be used within a GlobalStateProvider");
63
+ }
64
+
65
+ return context;
66
+ };