react-native-reanimated-carousel 5.0.0-beta.7 → 5.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 (428) hide show
  1. package/README.md +60 -28
  2. package/lib/commonjs/components/Carousel.js +1 -1
  3. package/lib/commonjs/components/Carousel.js.map +1 -1
  4. package/lib/commonjs/components/CarouselLayout.js +1 -1
  5. package/lib/commonjs/components/CarouselLayout.js.map +1 -1
  6. package/lib/commonjs/components/ItemLayout.js +1 -1
  7. package/lib/commonjs/components/ItemLayout.js.map +1 -1
  8. package/lib/commonjs/components/ItemRenderer.js +1 -1
  9. package/lib/commonjs/components/ItemRenderer.js.map +1 -1
  10. package/lib/commonjs/components/Pagination/PaginationItem.js +2 -0
  11. package/lib/commonjs/components/Pagination/PaginationItem.js.map +1 -0
  12. package/lib/commonjs/components/Pagination/index.js +1 -1
  13. package/lib/commonjs/components/Pagination/index.js.map +1 -1
  14. package/lib/commonjs/components/ScrollViewGesture.js +1 -1
  15. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
  16. package/lib/commonjs/hooks/useAutoPlay.js +1 -1
  17. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
  18. package/lib/commonjs/hooks/useCarouselController.js +1 -1
  19. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  20. package/lib/commonjs/hooks/useCommonVariables.js +1 -1
  21. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
  22. package/lib/commonjs/hooks/useInitProps.js +1 -1
  23. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  24. package/lib/commonjs/hooks/useLayoutConfig.js +1 -1
  25. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
  26. package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
  27. package/lib/commonjs/hooks/useOnProgressChange.js +1 -1
  28. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
  29. package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -1
  30. package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -1
  31. package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
  32. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -1
  33. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
  34. package/lib/commonjs/index.js +1 -1
  35. package/lib/commonjs/index.js.map +1 -1
  36. package/lib/commonjs/layouts/index.js.map +1 -1
  37. package/lib/commonjs/layouts/normal.js +1 -1
  38. package/lib/commonjs/layouts/normal.js.map +1 -1
  39. package/lib/commonjs/layouts/parallax.js +1 -1
  40. package/lib/commonjs/layouts/parallax.js.map +1 -1
  41. package/lib/commonjs/layouts/stack.js +1 -1
  42. package/lib/commonjs/layouts/stack.js.map +1 -1
  43. package/lib/commonjs/public-types.js +2 -0
  44. package/lib/commonjs/public-types.js.map +1 -0
  45. package/lib/commonjs/store/index.js.map +1 -1
  46. package/lib/commonjs/utils/carousel-direction.js +2 -0
  47. package/lib/commonjs/utils/carousel-direction.js.map +1 -0
  48. package/lib/commonjs/utils/carousel-math.js +2 -0
  49. package/lib/commonjs/utils/carousel-math.js.map +1 -0
  50. package/lib/commonjs/utils/deal-with-animation.js +1 -1
  51. package/lib/commonjs/utils/deal-with-animation.js.map +1 -1
  52. package/lib/module/components/Carousel.js +1 -1
  53. package/lib/module/components/Carousel.js.map +1 -1
  54. package/lib/module/components/CarouselLayout.js +1 -1
  55. package/lib/module/components/CarouselLayout.js.map +1 -1
  56. package/lib/module/components/ItemLayout.js +1 -1
  57. package/lib/module/components/ItemLayout.js.map +1 -1
  58. package/lib/module/components/ItemRenderer.js +1 -1
  59. package/lib/module/components/ItemRenderer.js.map +1 -1
  60. package/lib/module/components/LazyView.js +1 -1
  61. package/lib/module/components/LazyView.js.map +1 -1
  62. package/lib/module/components/Pagination/PaginationItem.js +2 -0
  63. package/lib/module/components/Pagination/PaginationItem.js.map +1 -0
  64. package/lib/module/components/Pagination/index.js +1 -1
  65. package/lib/module/components/Pagination/index.js.map +1 -1
  66. package/lib/module/components/ScrollViewGesture.js +1 -1
  67. package/lib/module/components/ScrollViewGesture.js.map +1 -1
  68. package/lib/module/constants/index.js +1 -1
  69. package/lib/module/constants/index.js.map +1 -1
  70. package/lib/module/hooks/useAutoPlay.js +1 -1
  71. package/lib/module/hooks/useAutoPlay.js.map +1 -1
  72. package/lib/module/hooks/useCarouselController.js +1 -1
  73. package/lib/module/hooks/useCarouselController.js.map +1 -1
  74. package/lib/module/hooks/useCheckMounted.js +1 -1
  75. package/lib/module/hooks/useCheckMounted.js.map +1 -1
  76. package/lib/module/hooks/useCommonVariables.js +1 -1
  77. package/lib/module/hooks/useCommonVariables.js.map +1 -1
  78. package/lib/module/hooks/useInitProps.js +1 -1
  79. package/lib/module/hooks/useInitProps.js.map +1 -1
  80. package/lib/module/hooks/useLayoutConfig.js +1 -1
  81. package/lib/module/hooks/useLayoutConfig.js.map +1 -1
  82. package/lib/module/hooks/useOffsetX.js +1 -1
  83. package/lib/module/hooks/useOffsetX.js.map +1 -1
  84. package/lib/module/hooks/useOnProgressChange.js +1 -1
  85. package/lib/module/hooks/useOnProgressChange.js.map +1 -1
  86. package/lib/module/hooks/usePanGestureProxy.js +1 -1
  87. package/lib/module/hooks/usePanGestureProxy.js.map +1 -1
  88. package/lib/module/hooks/usePropsErrorBoundary.js +1 -1
  89. package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -1
  90. package/lib/module/hooks/useUpdateGestureConfig.js +1 -1
  91. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -1
  92. package/lib/module/hooks/useVisibleRanges.js +1 -1
  93. package/lib/module/hooks/useVisibleRanges.js.map +1 -1
  94. package/lib/module/index.js +1 -1
  95. package/lib/module/index.js.map +1 -1
  96. package/lib/module/layouts/index.js +1 -1
  97. package/lib/module/layouts/index.js.map +1 -1
  98. package/lib/module/layouts/normal.js +1 -1
  99. package/lib/module/layouts/normal.js.map +1 -1
  100. package/lib/module/layouts/parallax.js +1 -1
  101. package/lib/module/layouts/parallax.js.map +1 -1
  102. package/lib/module/layouts/stack.js +1 -1
  103. package/lib/module/layouts/stack.js.map +1 -1
  104. package/lib/module/package.json +1 -0
  105. package/lib/module/public-types.js +2 -0
  106. package/lib/module/public-types.js.map +1 -0
  107. package/lib/module/store/index.js +1 -1
  108. package/lib/module/store/index.js.map +1 -1
  109. package/lib/module/types.js +1 -1
  110. package/lib/module/utils/carousel-direction.js +2 -0
  111. package/lib/module/utils/carousel-direction.js.map +1 -0
  112. package/lib/module/utils/carousel-math.js +2 -0
  113. package/lib/module/utils/carousel-math.js.map +1 -0
  114. package/lib/module/utils/compute-gesture-translation.js +1 -1
  115. package/lib/module/utils/compute-gesture-translation.js.map +1 -1
  116. package/lib/module/utils/compute-offset-if-size-changed.js +1 -1
  117. package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -1
  118. package/lib/module/utils/computed-with-auto-fill-data.js +1 -1
  119. package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -1
  120. package/lib/module/utils/deal-with-animation.js +1 -1
  121. package/lib/module/utils/deal-with-animation.js.map +1 -1
  122. package/lib/module/utils/log.js +1 -1
  123. package/lib/module/utils/log.js.map +1 -1
  124. package/lib/module/utils/sanitize-animation-style.js +1 -1
  125. package/lib/module/utils/sanitize-animation-style.js.map +1 -1
  126. package/lib/typescript/commonjs/components/Carousel.d.ts +8 -0
  127. package/lib/typescript/commonjs/components/Carousel.d.ts.map +1 -0
  128. package/lib/typescript/{components → commonjs/components}/CarouselLayout.d.ts +5 -8
  129. package/lib/typescript/commonjs/components/CarouselLayout.d.ts.map +1 -0
  130. package/lib/typescript/{components → commonjs/components}/ItemLayout.d.ts +7 -6
  131. package/lib/typescript/commonjs/components/ItemLayout.d.ts.map +1 -0
  132. package/lib/typescript/commonjs/components/ItemRenderer.d.ts +24 -0
  133. package/lib/typescript/commonjs/components/ItemRenderer.d.ts.map +1 -0
  134. package/lib/typescript/commonjs/components/LazyView.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/components/Pagination/PaginationItem.d.ts +14 -0
  136. package/lib/typescript/commonjs/components/Pagination/PaginationItem.d.ts.map +1 -0
  137. package/lib/typescript/commonjs/components/Pagination/index.d.ts +4 -0
  138. package/lib/typescript/commonjs/components/Pagination/index.d.ts.map +1 -0
  139. package/lib/typescript/{components → commonjs/components}/ScrollViewGesture.d.ts +3 -4
  140. package/lib/typescript/commonjs/components/ScrollViewGesture.d.ts.map +1 -0
  141. package/lib/typescript/commonjs/constants/index.d.ts.map +1 -0
  142. package/lib/typescript/commonjs/hooks/useAutoPlay.d.ts +12 -0
  143. package/lib/typescript/commonjs/hooks/useAutoPlay.d.ts.map +1 -0
  144. package/lib/typescript/commonjs/hooks/useCarouselController.d.ts +29 -0
  145. package/lib/typescript/commonjs/hooks/useCarouselController.d.ts.map +1 -0
  146. package/lib/typescript/commonjs/hooks/useCheckMounted.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/hooks/useCommonVariables.d.ts +18 -0
  148. package/lib/typescript/commonjs/hooks/useCommonVariables.d.ts.map +1 -0
  149. package/lib/typescript/commonjs/hooks/useInitProps.d.ts +25 -0
  150. package/lib/typescript/commonjs/hooks/useInitProps.d.ts.map +1 -0
  151. package/lib/typescript/commonjs/hooks/useLayoutConfig.d.ts +8 -0
  152. package/lib/typescript/commonjs/hooks/useLayoutConfig.d.ts.map +1 -0
  153. package/lib/typescript/commonjs/hooks/useOffsetX.d.ts +13 -0
  154. package/lib/typescript/commonjs/hooks/useOffsetX.d.ts.map +1 -0
  155. package/lib/typescript/commonjs/hooks/useOnProgressChange.d.ts +12 -0
  156. package/lib/typescript/commonjs/hooks/useOnProgressChange.d.ts.map +1 -0
  157. package/lib/typescript/{hooks → commonjs/hooks}/usePanGestureProxy.d.ts +3 -2
  158. package/lib/typescript/commonjs/hooks/usePanGestureProxy.d.ts.map +1 -0
  159. package/lib/typescript/commonjs/hooks/usePropsErrorBoundary.d.ts +3 -0
  160. package/lib/typescript/commonjs/hooks/usePropsErrorBoundary.d.ts.map +1 -0
  161. package/lib/typescript/commonjs/hooks/useUpdateGestureConfig.d.ts +9 -0
  162. package/lib/typescript/commonjs/hooks/useUpdateGestureConfig.d.ts.map +1 -0
  163. package/lib/typescript/{hooks → commonjs/hooks}/useVisibleRanges.d.ts +2 -2
  164. package/lib/typescript/commonjs/hooks/useVisibleRanges.d.ts.map +1 -0
  165. package/lib/typescript/commonjs/index.d.ts +4 -0
  166. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  167. package/lib/typescript/{layouts → commonjs/layouts}/index.d.ts +0 -1
  168. package/lib/typescript/commonjs/layouts/index.d.ts.map +1 -0
  169. package/lib/typescript/{layouts → commonjs/layouts}/normal.d.ts +3 -1
  170. package/lib/typescript/commonjs/layouts/normal.d.ts.map +1 -0
  171. package/lib/typescript/commonjs/layouts/parallax.d.ts +27 -0
  172. package/lib/typescript/commonjs/layouts/parallax.d.ts.map +1 -0
  173. package/lib/typescript/commonjs/layouts/stack.d.ts +10 -0
  174. package/lib/typescript/commonjs/layouts/stack.d.ts.map +1 -0
  175. package/lib/typescript/commonjs/package.json +1 -0
  176. package/lib/typescript/commonjs/public-types.d.ts +161 -0
  177. package/lib/typescript/commonjs/public-types.d.ts.map +1 -0
  178. package/lib/typescript/{store → commonjs/store}/index.d.ts +8 -8
  179. package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
  180. package/lib/typescript/commonjs/types.d.ts +15 -0
  181. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  182. package/lib/typescript/commonjs/utils/carousel-direction.d.ts +9 -0
  183. package/lib/typescript/commonjs/utils/carousel-direction.d.ts.map +1 -0
  184. package/lib/typescript/commonjs/utils/carousel-math.d.ts +28 -0
  185. package/lib/typescript/commonjs/utils/carousel-math.d.ts.map +1 -0
  186. package/lib/typescript/commonjs/utils/compute-gesture-translation.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/utils/compute-offset-if-size-changed.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/utils/computed-with-auto-fill-data.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/utils/deal-with-animation.d.ts +3 -0
  190. package/lib/typescript/commonjs/utils/deal-with-animation.d.ts.map +1 -0
  191. package/lib/typescript/commonjs/utils/log.d.ts.map +1 -0
  192. package/lib/typescript/commonjs/utils/sanitize-animation-style.d.ts.map +1 -0
  193. package/lib/typescript/module/components/Carousel.d.ts +8 -0
  194. package/lib/typescript/module/components/Carousel.d.ts.map +1 -0
  195. package/lib/typescript/module/components/CarouselLayout.d.ts +14 -0
  196. package/lib/typescript/module/components/CarouselLayout.d.ts.map +1 -0
  197. package/lib/typescript/module/components/ItemLayout.d.ts +21 -0
  198. package/lib/typescript/module/components/ItemLayout.d.ts.map +1 -0
  199. package/lib/typescript/module/components/ItemRenderer.d.ts +24 -0
  200. package/lib/typescript/module/components/ItemRenderer.d.ts.map +1 -0
  201. package/lib/typescript/module/components/LazyView.d.ts +8 -0
  202. package/lib/typescript/module/components/LazyView.d.ts.map +1 -0
  203. package/lib/typescript/module/components/Pagination/PaginationItem.d.ts +14 -0
  204. package/lib/typescript/module/components/Pagination/PaginationItem.d.ts.map +1 -0
  205. package/lib/typescript/module/components/Pagination/index.d.ts +4 -0
  206. package/lib/typescript/module/components/Pagination/index.d.ts.map +1 -0
  207. package/lib/typescript/module/components/ScrollViewGesture.d.ts +18 -0
  208. package/lib/typescript/module/components/ScrollViewGesture.d.ts.map +1 -0
  209. package/lib/typescript/module/constants/index.d.ts +9 -0
  210. package/lib/typescript/module/constants/index.d.ts.map +1 -0
  211. package/lib/typescript/module/hooks/useAutoPlay.d.ts +12 -0
  212. package/lib/typescript/module/hooks/useAutoPlay.d.ts.map +1 -0
  213. package/lib/typescript/module/hooks/useCarouselController.d.ts +29 -0
  214. package/lib/typescript/module/hooks/useCarouselController.d.ts.map +1 -0
  215. package/lib/typescript/module/hooks/useCheckMounted.d.ts +3 -0
  216. package/lib/typescript/module/hooks/useCheckMounted.d.ts.map +1 -0
  217. package/lib/typescript/module/hooks/useCommonVariables.d.ts +18 -0
  218. package/lib/typescript/module/hooks/useCommonVariables.d.ts.map +1 -0
  219. package/lib/typescript/module/hooks/useInitProps.d.ts +25 -0
  220. package/lib/typescript/module/hooks/useInitProps.d.ts.map +1 -0
  221. package/lib/typescript/module/hooks/useLayoutConfig.d.ts +8 -0
  222. package/lib/typescript/module/hooks/useLayoutConfig.d.ts.map +1 -0
  223. package/lib/typescript/module/hooks/useOffsetX.d.ts +13 -0
  224. package/lib/typescript/module/hooks/useOffsetX.d.ts.map +1 -0
  225. package/lib/typescript/module/hooks/useOnProgressChange.d.ts +12 -0
  226. package/lib/typescript/module/hooks/useOnProgressChange.d.ts.map +1 -0
  227. package/lib/typescript/module/hooks/usePanGestureProxy.d.ts +11 -0
  228. package/lib/typescript/module/hooks/usePanGestureProxy.d.ts.map +1 -0
  229. package/lib/typescript/module/hooks/usePropsErrorBoundary.d.ts +3 -0
  230. package/lib/typescript/module/hooks/usePropsErrorBoundary.d.ts.map +1 -0
  231. package/lib/typescript/module/hooks/useUpdateGestureConfig.d.ts +9 -0
  232. package/lib/typescript/module/hooks/useUpdateGestureConfig.d.ts.map +1 -0
  233. package/lib/typescript/module/hooks/useVisibleRanges.d.ts +22 -0
  234. package/lib/typescript/module/hooks/useVisibleRanges.d.ts.map +1 -0
  235. package/lib/typescript/module/index.d.ts +4 -0
  236. package/lib/typescript/module/index.d.ts.map +1 -0
  237. package/lib/typescript/module/layouts/index.d.ts +10 -0
  238. package/lib/typescript/module/layouts/index.d.ts.map +1 -0
  239. package/lib/typescript/module/layouts/normal.d.ts +15 -0
  240. package/lib/typescript/module/layouts/normal.d.ts.map +1 -0
  241. package/lib/typescript/module/layouts/parallax.d.ts +27 -0
  242. package/lib/typescript/module/layouts/parallax.d.ts.map +1 -0
  243. package/lib/typescript/module/layouts/stack.d.ts +10 -0
  244. package/lib/typescript/module/layouts/stack.d.ts.map +1 -0
  245. package/lib/typescript/module/package.json +1 -0
  246. package/lib/typescript/module/public-types.d.ts +161 -0
  247. package/lib/typescript/module/public-types.d.ts.map +1 -0
  248. package/lib/typescript/module/store/index.d.ts +35 -0
  249. package/lib/typescript/module/store/index.d.ts.map +1 -0
  250. package/lib/typescript/module/types.d.ts +15 -0
  251. package/lib/typescript/module/types.d.ts.map +1 -0
  252. package/lib/typescript/module/utils/carousel-direction.d.ts +9 -0
  253. package/lib/typescript/module/utils/carousel-direction.d.ts.map +1 -0
  254. package/lib/typescript/module/utils/carousel-math.d.ts +28 -0
  255. package/lib/typescript/module/utils/carousel-math.d.ts.map +1 -0
  256. package/lib/typescript/module/utils/compute-gesture-translation.d.ts +9 -0
  257. package/lib/typescript/module/utils/compute-gesture-translation.d.ts.map +1 -0
  258. package/lib/typescript/module/utils/compute-offset-if-size-changed.d.ts +6 -0
  259. package/lib/typescript/module/utils/compute-offset-if-size-changed.d.ts.map +1 -0
  260. package/lib/typescript/module/utils/computed-with-auto-fill-data.d.ts +23 -0
  261. package/lib/typescript/module/utils/computed-with-auto-fill-data.d.ts.map +1 -0
  262. package/lib/typescript/module/utils/deal-with-animation.d.ts +3 -0
  263. package/lib/typescript/module/utils/deal-with-animation.d.ts.map +1 -0
  264. package/lib/typescript/module/utils/log.d.ts +7 -0
  265. package/lib/typescript/module/utils/log.d.ts.map +1 -0
  266. package/lib/typescript/module/utils/sanitize-animation-style.d.ts +3 -0
  267. package/lib/typescript/module/utils/sanitize-animation-style.d.ts.map +1 -0
  268. package/package.json +34 -7
  269. package/scripts/codemods/v5.mjs +502 -0
  270. package/src/components/Carousel.tsx +5 -5
  271. package/src/components/CarouselLayout.tsx +53 -91
  272. package/src/components/ItemLayout.tsx +55 -46
  273. package/src/components/ItemRenderer.tsx +29 -18
  274. package/src/components/Pagination/PaginationItem.tsx +162 -0
  275. package/src/components/Pagination/index.tsx +105 -6
  276. package/src/components/ScrollViewGesture.tsx +92 -177
  277. package/src/hooks/useAutoPlay.ts +23 -18
  278. package/src/hooks/useCarouselController.tsx +194 -340
  279. package/src/hooks/useCommonVariables.ts +159 -71
  280. package/src/hooks/useInitProps.ts +161 -71
  281. package/src/hooks/useLayoutConfig.ts +21 -12
  282. package/src/hooks/useOffsetX.ts +3 -3
  283. package/src/hooks/useOnProgressChange.ts +23 -48
  284. package/src/hooks/usePanGestureProxy.ts +2 -2
  285. package/src/hooks/usePropsErrorBoundary.ts +32 -90
  286. package/src/hooks/useUpdateGestureConfig.ts +5 -2
  287. package/src/hooks/useVisibleRanges.tsx +2 -2
  288. package/src/index.tsx +14 -9
  289. package/src/layouts/index.tsx +0 -2
  290. package/src/layouts/normal.ts +14 -4
  291. package/src/layouts/parallax.ts +32 -59
  292. package/src/layouts/stack.ts +30 -70
  293. package/src/public-types.ts +198 -0
  294. package/src/store/index.tsx +7 -7
  295. package/src/types.ts +30 -322
  296. package/src/utils/carousel-direction.ts +39 -0
  297. package/src/utils/carousel-math.ts +156 -0
  298. package/src/utils/deal-with-animation.ts +11 -9
  299. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +0 -2
  300. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +0 -1
  301. package/lib/commonjs/components/Pagination/Basic/index.js +0 -2
  302. package/lib/commonjs/components/Pagination/Basic/index.js.map +0 -1
  303. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js +0 -2
  304. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js.map +0 -1
  305. package/lib/commonjs/components/Pagination/Custom/index.js +0 -2
  306. package/lib/commonjs/components/Pagination/Custom/index.js.map +0 -1
  307. package/lib/commonjs/utils/compute-offset-if-data-changed.js +0 -2
  308. package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +0 -1
  309. package/lib/commonjs/utils/handleroffset-direction.js +0 -2
  310. package/lib/commonjs/utils/handleroffset-direction.js.map +0 -1
  311. package/lib/module/components/Pagination/Basic/PaginationItem.js +0 -2
  312. package/lib/module/components/Pagination/Basic/PaginationItem.js.map +0 -1
  313. package/lib/module/components/Pagination/Basic/index.js +0 -2
  314. package/lib/module/components/Pagination/Basic/index.js.map +0 -1
  315. package/lib/module/components/Pagination/Custom/PaginationItem.js +0 -2
  316. package/lib/module/components/Pagination/Custom/PaginationItem.js.map +0 -1
  317. package/lib/module/components/Pagination/Custom/index.js +0 -2
  318. package/lib/module/components/Pagination/Custom/index.js.map +0 -1
  319. package/lib/module/utils/compute-offset-if-data-changed.js +0 -2
  320. package/lib/module/utils/compute-offset-if-data-changed.js.map +0 -1
  321. package/lib/module/utils/handleroffset-direction.js +0 -2
  322. package/lib/module/utils/handleroffset-direction.js.map +0 -1
  323. package/lib/typescript/components/Carousel.d.ts +0 -8
  324. package/lib/typescript/components/Carousel.d.ts.map +0 -1
  325. package/lib/typescript/components/CarouselLayout.d.ts.map +0 -1
  326. package/lib/typescript/components/ItemLayout.d.ts.map +0 -1
  327. package/lib/typescript/components/ItemRenderer.d.ts +0 -23
  328. package/lib/typescript/components/ItemRenderer.d.ts.map +0 -1
  329. package/lib/typescript/components/LazyView.d.ts.map +0 -1
  330. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +0 -29
  331. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts.map +0 -1
  332. package/lib/typescript/components/Pagination/Basic/index.d.ts +0 -23
  333. package/lib/typescript/components/Pagination/Basic/index.d.ts.map +0 -1
  334. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts +0 -35
  335. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts.map +0 -1
  336. package/lib/typescript/components/Pagination/Custom/index.d.ts +0 -26
  337. package/lib/typescript/components/Pagination/Custom/index.d.ts.map +0 -1
  338. package/lib/typescript/components/Pagination/index.d.ts +0 -5
  339. package/lib/typescript/components/Pagination/index.d.ts.map +0 -1
  340. package/lib/typescript/components/ScrollViewGesture.d.ts.map +0 -1
  341. package/lib/typescript/constants/index.d.ts.map +0 -1
  342. package/lib/typescript/hooks/useAutoPlay.d.ts +0 -12
  343. package/lib/typescript/hooks/useAutoPlay.d.ts.map +0 -1
  344. package/lib/typescript/hooks/useCarouselController.d.ts +0 -28
  345. package/lib/typescript/hooks/useCarouselController.d.ts.map +0 -1
  346. package/lib/typescript/hooks/useCheckMounted.d.ts.map +0 -1
  347. package/lib/typescript/hooks/useCommonVariables.d.ts +0 -13
  348. package/lib/typescript/hooks/useCommonVariables.d.ts.map +0 -1
  349. package/lib/typescript/hooks/useInitProps.d.ts +0 -10
  350. package/lib/typescript/hooks/useInitProps.d.ts.map +0 -1
  351. package/lib/typescript/hooks/useLayoutConfig.d.ts +0 -8
  352. package/lib/typescript/hooks/useLayoutConfig.d.ts.map +0 -1
  353. package/lib/typescript/hooks/useOffsetX.d.ts +0 -13
  354. package/lib/typescript/hooks/useOffsetX.d.ts.map +0 -1
  355. package/lib/typescript/hooks/useOnProgressChange.d.ts +0 -11
  356. package/lib/typescript/hooks/useOnProgressChange.d.ts.map +0 -1
  357. package/lib/typescript/hooks/usePanGestureProxy.d.ts.map +0 -1
  358. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +0 -5
  359. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +0 -1
  360. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +0 -6
  361. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts.map +0 -1
  362. package/lib/typescript/hooks/useVisibleRanges.d.ts.map +0 -1
  363. package/lib/typescript/index.d.ts +0 -7
  364. package/lib/typescript/index.d.ts.map +0 -1
  365. package/lib/typescript/layouts/index.d.ts.map +0 -1
  366. package/lib/typescript/layouts/normal.d.ts.map +0 -1
  367. package/lib/typescript/layouts/parallax.d.ts +0 -47
  368. package/lib/typescript/layouts/parallax.d.ts.map +0 -1
  369. package/lib/typescript/layouts/stack.d.ts +0 -38
  370. package/lib/typescript/layouts/stack.d.ts.map +0 -1
  371. package/lib/typescript/store/index.d.ts.map +0 -1
  372. package/lib/typescript/types.d.ts +0 -302
  373. package/lib/typescript/types.d.ts.map +0 -1
  374. package/lib/typescript/utils/compute-gesture-translation.d.ts.map +0 -1
  375. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts +0 -9
  376. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts.map +0 -1
  377. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts.map +0 -1
  378. package/lib/typescript/utils/computed-with-auto-fill-data.d.ts.map +0 -1
  379. package/lib/typescript/utils/deal-with-animation.d.ts +0 -3
  380. package/lib/typescript/utils/deal-with-animation.d.ts.map +0 -1
  381. package/lib/typescript/utils/handleroffset-direction.d.ts +0 -4
  382. package/lib/typescript/utils/handleroffset-direction.d.ts.map +0 -1
  383. package/lib/typescript/utils/log.d.ts.map +0 -1
  384. package/lib/typescript/utils/sanitize-animation-style.d.ts.map +0 -1
  385. package/src/components/Carousel.test.tsx +0 -1215
  386. package/src/components/LazyView.test.tsx +0 -61
  387. package/src/components/Pagination/Basic/PaginationItem.tsx +0 -149
  388. package/src/components/Pagination/Basic/index.tsx +0 -98
  389. package/src/components/Pagination/Custom/PaginationItem.tsx +0 -166
  390. package/src/components/Pagination/Custom/index.tsx +0 -111
  391. package/src/components/Pagination/Pagination.test.tsx +0 -178
  392. package/src/components/ScrollViewGesture.test.tsx +0 -155
  393. package/src/components/issue-899-parallax-reverse-loop.test.tsx +0 -131
  394. package/src/components/rnr-demo.test.tsx +0 -53
  395. package/src/hooks/useAutoPlay.test.ts +0 -194
  396. package/src/hooks/useCarouselController.test.tsx +0 -1158
  397. package/src/hooks/useCheckMounted.test.ts +0 -47
  398. package/src/hooks/useCommonVariables.test.tsx +0 -384
  399. package/src/hooks/useInitProps.test.tsx +0 -134
  400. package/src/hooks/useLayoutConfig.test.tsx +0 -247
  401. package/src/hooks/useOffsetX.test.ts +0 -54
  402. package/src/hooks/useOnProgressChange.test.tsx +0 -270
  403. package/src/hooks/usePanGestureProxy.test.tsx +0 -368
  404. package/src/hooks/usePropsErrorBoundary.test.tsx +0 -57
  405. package/src/hooks/useUpdateGestureConfig.test.ts +0 -89
  406. package/src/hooks/useVisibleRanges.test.tsx +0 -347
  407. package/src/layouts/parallax.test.ts +0 -239
  408. package/src/layouts/stack.test.ts +0 -252
  409. package/src/store/index.test.tsx +0 -314
  410. package/src/utils/compute-gesture-translation.test.ts +0 -70
  411. package/src/utils/compute-offset-if-data-changed.test.ts +0 -133
  412. package/src/utils/compute-offset-if-data-changed.ts +0 -44
  413. package/src/utils/compute-offset-if-size-changed.test.ts +0 -78
  414. package/src/utils/computed-with-auto-fill-data.test.ts +0 -298
  415. package/src/utils/deal-with-animation.test.ts +0 -181
  416. package/src/utils/handleroffset-direction.test.ts +0 -124
  417. package/src/utils/handleroffset-direction.ts +0 -18
  418. package/src/utils/index.test.ts +0 -90
  419. package/src/utils/log.test.ts +0 -134
  420. package/src/utils/sanitize-animation-style.test.ts +0 -40
  421. /package/lib/typescript/{components → commonjs/components}/LazyView.d.ts +0 -0
  422. /package/lib/typescript/{constants → commonjs/constants}/index.d.ts +0 -0
  423. /package/lib/typescript/{hooks → commonjs/hooks}/useCheckMounted.d.ts +0 -0
  424. /package/lib/typescript/{utils → commonjs/utils}/compute-gesture-translation.d.ts +0 -0
  425. /package/lib/typescript/{utils → commonjs/utils}/compute-offset-if-size-changed.d.ts +0 -0
  426. /package/lib/typescript/{utils → commonjs/utils}/computed-with-auto-fill-data.d.ts +0 -0
  427. /package/lib/typescript/{utils → commonjs/utils}/log.d.ts +0 -0
  428. /package/lib/typescript/{utils → commonjs/utils}/sanitize-animation-style.d.ts +0 -0
@@ -1,1215 +0,0 @@
1
- import type { FC } from "react";
2
- import React from "react";
3
- import type { PanGesture } from "react-native-gesture-handler";
4
- import { Gesture, State } from "react-native-gesture-handler";
5
- import type { SharedValue } from "react-native-reanimated";
6
- import Animated, { interpolate, useDerivedValue, useSharedValue } from "react-native-reanimated";
7
- import type { ReactTestInstance } from "react-test-renderer";
8
-
9
- import { act, render, waitFor } from "@testing-library/react-native";
10
- import { fireGestureHandler, getByGestureTestId } from "react-native-gesture-handler/jest-utils";
11
-
12
- import Carousel from "./Carousel";
13
- import { resolveCarouselLayoutStyle } from "./CarouselLayout";
14
- import { resolveItemMainAxisSize } from "./ItemLayout";
15
-
16
- import type { TCarouselProps } from "../types";
17
-
18
- // Suppress the "measure() cannot be used with Jest" warning from Reanimated.
19
- // The measure export is non-configurable so it cannot be spied on or mocked
20
- // at the module level. The code in ScrollViewGesture already handles the null
21
- // return gracefully (measurement?.width || 0). We filter at the Reanimated
22
- // logger level which is more reliable than intercepting console.warn.
23
- {
24
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
- const cfg = (global as any).__reanimatedLoggerConfig as
26
- | { logFunction: (data: { level: number; message: string }) => void }
27
- | undefined;
28
- if (cfg) {
29
- const _origLog = cfg.logFunction;
30
- cfg.logFunction = (data) => {
31
- if (data.message.includes("measure() cannot be used with Jest")) return;
32
- _origLog(data);
33
- };
34
- }
35
- }
36
-
37
- jest.setTimeout(1000 * 12);
38
-
39
- const mockPan = jest.fn();
40
- const realPan = Gesture.Pan();
41
- const gestureTestId = "rnrc-gesture-handler";
42
-
43
- jest.spyOn(Gesture, "Pan").mockImplementation(() => {
44
- mockPan();
45
- return realPan.withTestId(gestureTestId);
46
- });
47
-
48
- describe("Test the real swipe behavior of Carousel to ensure it's working as expected", () => {
49
- const slideWidth = 300;
50
- const slideHeight = 200;
51
- const slideCount = 4;
52
-
53
- beforeEach(() => {
54
- mockPan.mockClear();
55
- jest.useFakeTimers();
56
- });
57
-
58
- afterEach(() => {
59
- act(() => {
60
- jest.runOnlyPendingTimers();
61
- });
62
- jest.useRealTimers();
63
- jest.clearAllTimers();
64
- });
65
-
66
- // Helper function to create mock data
67
- const createMockData = (length: number = slideCount) =>
68
- Array.from({ length }, (_, i) => `Item ${i + 1}`);
69
-
70
- // Helper function to create default props with correct typing
71
- const createDefaultProps = (
72
- progressAnimVal: SharedValue<number>,
73
- customProps: Partial<TCarouselProps<string>> = {}
74
- ) => {
75
- const baseProps: Partial<TCarouselProps<string>> = {
76
- data: createMockData(),
77
- defaultIndex: 0,
78
- onProgressChange: (offsetProgress, absoluteProgress) => {
79
- progressAnimVal.value = absoluteProgress;
80
- },
81
- };
82
-
83
- return {
84
- ...baseProps,
85
- ...customProps,
86
- } as TCarouselProps<string>;
87
- };
88
-
89
- // Helper function to create test wrapper
90
- const createCarousel = (progress: { current: number }) => {
91
- const Wrapper: FC<Partial<TCarouselProps<string>>> = React.forwardRef((customProps, ref) => {
92
- const progressAnimVal = useSharedValue(progress.current);
93
- const defaultRenderItem = ({
94
- item,
95
- index,
96
- }: {
97
- item: string;
98
- index: number;
99
- }) => (
100
- <Animated.View
101
- testID={`carousel-item-${index}`}
102
- style={{ width: slideWidth, height: slideHeight, flex: 1 }}
103
- >
104
- {item}
105
- </Animated.View>
106
- );
107
- const { renderItem = defaultRenderItem, ...defaultProps } = createDefaultProps(
108
- progressAnimVal,
109
- customProps
110
- );
111
-
112
- useDerivedValue(() => {
113
- progress.current = progressAnimVal.value;
114
- }, [progressAnimVal]);
115
-
116
- return <Carousel {...defaultProps} renderItem={renderItem} ref={ref} />;
117
- });
118
-
119
- return Wrapper;
120
- };
121
-
122
- // Helper function to simulate swipe
123
- const swipeToLeftOnce = (
124
- options: {
125
- itemWidth?: number;
126
- velocityX?: number;
127
- } = {}
128
- ) => {
129
- const { itemWidth = slideWidth, velocityX = -slideWidth } = options;
130
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
131
- { state: State.BEGAN, translationX: 0, velocityX },
132
- { state: State.ACTIVE, translationX: -itemWidth * 0.25, velocityX },
133
- { state: State.ACTIVE, translationX: -itemWidth * 0.5, velocityX },
134
- { state: State.ACTIVE, translationX: -itemWidth * 0.75, velocityX },
135
- { state: State.END, translationX: -itemWidth, velocityX },
136
- ]);
137
- };
138
-
139
- // Helper function to verify initial render
140
- const verifyInitialRender = async (
141
- getByTestId: (testID: string | RegExp) => ReactTestInstance
142
- ) => {
143
- await waitFor(
144
- () => {
145
- const item = getByTestId("carousel-item-0");
146
- expect(item).toBeTruthy();
147
- },
148
- { timeout: 1000 * 3 }
149
- );
150
- };
151
-
152
- describe("TDD: Test upcoming refactoring for style props", () => {
153
- beforeEach(() => {
154
- jest.spyOn(console, "warn").mockImplementation(() => {});
155
- });
156
-
157
- afterEach(() => {
158
- (console.warn as jest.Mock).mockRestore();
159
- });
160
-
161
- it("should show a deprecation warning when using the `width` prop", () => {
162
- const progress = { current: 0 };
163
- const Wrapper = createCarousel(progress);
164
- render(<Wrapper width={300} style={{ height: 200 }} />);
165
- expect(console.warn).toHaveBeenCalledWith(expect.stringContaining("is deprecated"));
166
- });
167
-
168
- it("should take width from the new `style` prop", async () => {
169
- const progress = { current: 0 };
170
- const Wrapper = createCarousel(progress);
171
- const { getByTestId } = render(
172
- <Wrapper style={{ width: 450, height: 200 }} testID="carousel-container" />
173
- );
174
- await verifyInitialRender(getByTestId);
175
-
176
- const outerContainer = getByTestId("carousel-container");
177
- expect(outerContainer.props.style).toContainEqual({ width: 450, height: 200 });
178
- });
179
-
180
- it("should apply styles from the new `contentContainerStyle` prop", async () => {
181
- const progress = { current: 0 };
182
- const Wrapper = createCarousel(progress);
183
- const { getByTestId } = render(
184
- <Wrapper
185
- style={{ width: slideWidth, height: slideHeight }}
186
- contentContainerStyle={{ padding: 20 }}
187
- />
188
- );
189
- await verifyInitialRender(getByTestId);
190
-
191
- const contentContainer = getByTestId("carousel-content-container");
192
- expect(contentContainer.props.style).toContainEqual({ padding: 20 });
193
- });
194
-
195
- it("should warn when `contentContainerStyle` contains conflicting props", async () => {
196
- const progress = { current: 0 };
197
- const Wrapper = createCarousel(progress);
198
- const { getByTestId } = render(
199
- <Wrapper
200
- style={{ width: slideWidth, height: slideHeight }}
201
- contentContainerStyle={{ opacity: 0.5 }}
202
- />
203
- );
204
- await verifyInitialRender(getByTestId);
205
-
206
- expect(console.warn).toHaveBeenCalledWith(
207
- expect.stringContaining("conflict with animations")
208
- );
209
- });
210
-
211
- it("should auto-size when no width is provided in `style`", async () => {
212
- const progress = { current: 0 };
213
- const Wrapper = createCarousel(progress);
214
- const { getByTestId } = render(<Wrapper style={{ height: 200 }} />);
215
-
216
- const contentContainer = getByTestId("carousel-content-container");
217
-
218
- // Initially, width should be '100%'
219
- expect(contentContainer.props.style[1].width).toBe("100%");
220
- expect(typeof contentContainer.props.onLayout).toBe("function");
221
-
222
- // Simulate onLayout event
223
- act(() => {
224
- contentContainer.props.onLayout?.({
225
- nativeEvent: { layout: { width: 350, height: 200 } },
226
- } as any);
227
- });
228
-
229
- act(() => {
230
- jest.runOnlyPendingTimers();
231
- });
232
-
233
- // No assertions on rendered items because reanimated mock does not process animated updates.
234
- // Ensure invoking layout measurement does not throw and that the carousel exposes the expected
235
- // measurement callback for auto-sizing scenarios.
236
- });
237
-
238
- it("should use itemWidth for snapping size when provided", async () => {
239
- const progress = { current: 0 };
240
- const Wrapper = createCarousel(progress);
241
- const containerWidth = 700;
242
- const itemWidth = 350;
243
- const { getByTestId } = render(
244
- <Wrapper style={{ width: containerWidth, height: 200 }} itemWidth={itemWidth} />
245
- );
246
- await verifyInitialRender(getByTestId);
247
-
248
- // The carousel should use itemWidth (350) for snapping instead of container width (700)
249
- // Verify items render and content container is set up correctly
250
- const contentContainer = getByTestId("carousel-content-container");
251
- expect(contentContainer).toBeTruthy();
252
- expect(getByTestId("carousel-item-0")).toBeTruthy();
253
- expect(getByTestId("carousel-item-1")).toBeTruthy();
254
- });
255
-
256
- it("should use itemHeight for snapping size in vertical mode when provided", async () => {
257
- const progress = { current: 0 };
258
- const Wrapper = createCarousel(progress);
259
- const containerHeight = 700;
260
- const itemHeight = 350;
261
- const { getByTestId } = render(
262
- <Wrapper vertical style={{ width: 350, height: containerHeight }} itemHeight={itemHeight} />
263
- );
264
- await verifyInitialRender(getByTestId);
265
-
266
- // The carousel should use itemHeight (350) for snapping instead of container height (700)
267
- // Verify items render - vertical mode uses the same snap logic
268
- const contentContainer = getByTestId("carousel-content-container");
269
- expect(contentContainer).toBeTruthy();
270
- // Verify first item renders
271
- expect(getByTestId("carousel-item-0")).toBeTruthy();
272
- });
273
-
274
- it("should prioritize itemWidth over width prop", async () => {
275
- const progress = { current: 0 };
276
- const Wrapper = createCarousel(progress);
277
- const containerWidth = 700;
278
- const itemWidth = 350;
279
- const { getByTestId } = render(
280
- <Wrapper
281
- style={{ width: containerWidth, height: 200 }}
282
- width={containerWidth}
283
- itemWidth={itemWidth}
284
- />
285
- );
286
- await verifyInitialRender(getByTestId);
287
-
288
- // itemWidth (350) should take precedence over deprecated width prop
289
- // Verify items render correctly with multiple visible
290
- const contentContainer = getByTestId("carousel-content-container");
291
- expect(contentContainer).toBeTruthy();
292
- expect(getByTestId("carousel-item-0")).toBeTruthy();
293
- expect(getByTestId("carousel-item-1")).toBeTruthy();
294
- });
295
-
296
- it("should support itemWidth for multiple visible items scenario", async () => {
297
- const progress = { current: 0 };
298
- const Wrapper = createCarousel(progress);
299
- const containerWidth = 900;
300
- const itemWidth = 300;
301
- const { getByTestId } = render(
302
- <Wrapper
303
- style={{ width: containerWidth, height: 200 }}
304
- itemWidth={itemWidth}
305
- data={createMockData(6)}
306
- />
307
- );
308
- await verifyInitialRender(getByTestId);
309
-
310
- // Container is 900px, itemWidth is 300px, so 3 items should be visible
311
- // Verify multiple items are rendered (visible in the viewport)
312
- expect(getByTestId("carousel-item-0")).toBeTruthy();
313
- expect(getByTestId("carousel-item-1")).toBeTruthy();
314
- expect(getByTestId("carousel-item-2")).toBeTruthy();
315
- expect(getByTestId("carousel-item-3")).toBeTruthy();
316
- });
317
-
318
- it("should accept onLayout callback prop", async () => {
319
- const progress = { current: 0 };
320
- const onLayout = jest.fn();
321
- const Wrapper = createCarousel(progress);
322
- const { getByTestId } = render(
323
- <Wrapper style={{ width: 700, height: 200 }} onLayout={onLayout} />
324
- );
325
-
326
- const contentContainer = getByTestId("carousel-content-container");
327
-
328
- // Verify that onLayout handler is attached to the content container
329
- expect(typeof contentContainer.props.onLayout).toBe("function");
330
- });
331
- });
332
-
333
- it("`data` prop: should render correctly", async () => {
334
- const progress = { current: 0 };
335
- const Wrapper = createCarousel(progress);
336
- const { getByTestId } = render(
337
- <Wrapper style={{ width: slideWidth, height: slideHeight }} data={createMockData(6)} />
338
- );
339
-
340
- await verifyInitialRender(getByTestId);
341
-
342
- expect(getByTestId("carousel-item-0")).toBeTruthy();
343
- expect(getByTestId("carousel-item-1")).toBeTruthy();
344
- expect(getByTestId("carousel-item-2")).toBeTruthy();
345
- expect(getByTestId("carousel-item-3")).toBeTruthy();
346
- expect(getByTestId("carousel-item-4")).toBeTruthy();
347
- expect(getByTestId("carousel-item-5")).toBeTruthy();
348
- });
349
-
350
- it("`renderItem` prop: should render items correctly", async () => {
351
- const progress = { current: 0 };
352
- const Wrapper = createCarousel(progress);
353
- const { getByTestId } = render(
354
- <Wrapper
355
- style={{ width: slideWidth, height: slideHeight }}
356
- renderItem={({ item, index }) => (
357
- <Animated.Text testID={`item-${index}`}>{item}</Animated.Text>
358
- )}
359
- />
360
- );
361
-
362
- await waitFor(() => expect(getByTestId("item-0")).toBeTruthy());
363
- });
364
-
365
- it("should swipe to the left", async () => {
366
- const progress = { current: 0 };
367
- const Wrapper = createCarousel(progress);
368
- const { getByTestId } = render(<Wrapper style={{ width: slideWidth, height: slideHeight }} />);
369
- await verifyInitialRender(getByTestId);
370
-
371
- // Test swipe sequence
372
- for (let i = 1; i <= slideCount; i++) {
373
- swipeToLeftOnce();
374
- await waitFor(() => expect(progress.current).toBe(i % slideCount));
375
- }
376
- });
377
-
378
- it("`loop` prop: should swipe back to the first item when loop is true", async () => {
379
- const progress = { current: 0 };
380
- const Wrapper = createCarousel(progress);
381
- {
382
- const { getByTestId } = render(
383
- <Wrapper style={{ width: slideWidth, height: slideHeight }} loop />
384
- );
385
- await verifyInitialRender(getByTestId);
386
-
387
- // Test swipe sequence
388
- for (let i = 1; i <= slideCount; i++) {
389
- swipeToLeftOnce();
390
- await waitFor(() => expect(progress.current).toBe(i % slideCount));
391
- }
392
- }
393
-
394
- {
395
- const { getByTestId } = render(
396
- <Wrapper style={{ width: slideWidth, height: slideHeight }} loop={false} />
397
- );
398
- await verifyInitialRender(getByTestId);
399
-
400
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
401
- { state: State.BEGAN, translationX: 0 },
402
- { state: State.ACTIVE, translationX: slideWidth * 0.25 },
403
- { state: State.END, translationX: slideWidth * 0.5 },
404
- ]);
405
-
406
- // Because the loop is false, so the the carousel will swipe back to the first item
407
- await waitFor(() => expect(progress.current).toBe(0));
408
- }
409
- });
410
-
411
- it("`onSnapToItem` prop: should call the onSnapToItem callback", async () => {
412
- const progress = { current: 0 };
413
- const onSnapToItem = jest.fn();
414
- const Wrapper = createCarousel(progress);
415
- const { getByTestId } = render(
416
- <Wrapper style={{ width: slideWidth, height: slideHeight }} onSnapToItem={onSnapToItem} />
417
- );
418
- await verifyInitialRender(getByTestId);
419
- expect(onSnapToItem).not.toHaveBeenCalled();
420
-
421
- swipeToLeftOnce();
422
- await waitFor(() => expect(onSnapToItem).toHaveBeenCalledWith(1));
423
-
424
- swipeToLeftOnce();
425
- await waitFor(() => expect(onSnapToItem).toHaveBeenCalledWith(2));
426
-
427
- swipeToLeftOnce();
428
- await waitFor(() => expect(onSnapToItem).toHaveBeenCalledWith(3));
429
- });
430
-
431
- it("`autoPlay` prop: should swipe automatically when autoPlay is true", async () => {
432
- const progress = { current: 0 };
433
- const Wrapper = createCarousel(progress);
434
- const { getByTestId } = render(
435
- <Wrapper style={{ width: slideWidth, height: slideHeight }} autoPlay autoPlayInterval={300} />
436
- );
437
- await verifyInitialRender(getByTestId);
438
-
439
- await waitFor(() => expect(progress.current).toBe(1));
440
- await waitFor(() => expect(progress.current).toBe(2));
441
- await waitFor(() => expect(progress.current).toBe(3));
442
- await waitFor(() => expect(progress.current).toBe(0));
443
- });
444
-
445
- it("`autoPlayReverse` prop: should swipe automatically in reverse when autoPlayReverse is true", async () => {
446
- const progress = { current: 0 };
447
- const Wrapper = createCarousel(progress);
448
-
449
- render(
450
- <Wrapper
451
- style={{ width: slideWidth, height: slideHeight }}
452
- autoPlay
453
- autoPlayReverse
454
- autoPlayInterval={300}
455
- scrollAnimationDuration={250}
456
- />
457
- );
458
-
459
- const step = (expectedIndex: number) => {
460
- act(() => {
461
- jest.advanceTimersByTime(300 + 250 + 1);
462
- });
463
- expect(Math.round(((progress.current % 4) + 4) % 4)).toBe(expectedIndex);
464
- };
465
-
466
- step(3);
467
- step(2);
468
- step(1);
469
- step(0);
470
- });
471
-
472
- it("`defaultIndex` prop: should render the correct item with the defaultIndex props", async () => {
473
- const progress = { current: 0 };
474
- const Wrapper = createCarousel(progress);
475
- const { getByTestId } = render(
476
- <Wrapper style={{ width: slideWidth, height: slideHeight }} defaultIndex={2} />
477
- );
478
- await verifyInitialRender(getByTestId);
479
-
480
- await waitFor(() => expect(progress.current).toBe(2));
481
- });
482
-
483
- it("`defaultScrollOffsetValue` prop: should render the correct progress value with the defaultScrollOffsetValue props", async () => {
484
- const progress = { current: 0 };
485
- const Wrapper = createCarousel(progress);
486
- const WrapperWithCustomProps = () => {
487
- const defaultScrollOffsetValue = useSharedValue(-slideWidth);
488
-
489
- return (
490
- <Wrapper
491
- style={{ width: slideWidth, height: slideHeight }}
492
- defaultScrollOffsetValue={defaultScrollOffsetValue}
493
- />
494
- );
495
- };
496
-
497
- render(<WrapperWithCustomProps />);
498
-
499
- await waitFor(() => expect(progress.current).toBe(1));
500
- });
501
-
502
- it("`ref` prop: should handle the ref props", async () => {
503
- const Wrapper = createCarousel({ current: 0 });
504
- const fn = jest.fn();
505
- const WrapperWithCustomProps: FC<{
506
- refSetupCallback: (ref: boolean) => void;
507
- }> = ({ refSetupCallback }) => {
508
- return (
509
- <Wrapper
510
- style={{ width: slideWidth, height: slideHeight }}
511
- ref={(ref) => {
512
- refSetupCallback(!!ref);
513
- }}
514
- />
515
- );
516
- };
517
-
518
- render(<WrapperWithCustomProps refSetupCallback={fn} />);
519
-
520
- await waitFor(() => expect(fn).toHaveBeenCalledWith(true));
521
- });
522
-
523
- it("`autoFillData` prop: should auto fill data array to allow loop playback when the loop props is true", async () => {
524
- const progress = { current: 0 };
525
- const Wrapper = createCarousel(progress);
526
- {
527
- const { getAllByTestId } = render(
528
- <Wrapper
529
- style={{ width: slideWidth, height: slideHeight }}
530
- autoFillData
531
- data={createMockData(1)}
532
- />
533
- );
534
- await waitFor(() => {
535
- expect(getAllByTestId("carousel-item-0").length).toBe(3);
536
- });
537
- }
538
-
539
- {
540
- const { getAllByTestId } = render(
541
- <Wrapper
542
- style={{ width: slideWidth, height: slideHeight }}
543
- autoFillData={false}
544
- data={createMockData(1)}
545
- />
546
- );
547
- await waitFor(() => {
548
- expect(getAllByTestId("carousel-item-0").length).toBe(1);
549
- });
550
- }
551
- });
552
-
553
- it("`pagingEnabled` prop: should swipe to the next item when pagingEnabled is true", async () => {
554
- const progress = { current: 0 };
555
- const Wrapper = createCarousel(progress);
556
- {
557
- const { getByTestId } = render(
558
- <Wrapper style={{ width: slideWidth, height: slideHeight }} pagingEnabled={false} />
559
- );
560
- await verifyInitialRender(getByTestId);
561
-
562
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
563
- { state: State.BEGAN, translationX: 0, velocityX: -5 },
564
- {
565
- state: State.ACTIVE,
566
- translationX: -slideWidth * 0.15,
567
- velocityX: -5,
568
- },
569
- { state: State.END, translationX: -slideWidth * 0.25, velocityX: -5 },
570
- ]);
571
-
572
- await waitFor(() => expect(progress.current).toBe(0));
573
- }
574
-
575
- {
576
- const { getByTestId } = render(
577
- <Wrapper style={{ width: slideWidth, height: slideHeight }} pagingEnabled />
578
- );
579
- await verifyInitialRender(getByTestId);
580
-
581
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
582
- { state: State.BEGAN, translationX: 0, velocityX: -1000 },
583
- {
584
- state: State.ACTIVE,
585
- translationX: -slideWidth * 0.15,
586
- velocityX: -1000,
587
- },
588
- {
589
- state: State.END,
590
- translationX: -slideWidth * 0.25,
591
- velocityX: -1000,
592
- },
593
- ]);
594
-
595
- await waitFor(() => expect(progress.current).toBe(1));
596
- }
597
- });
598
-
599
- it("`onConfigurePanGesture` prop: should call the onConfigurePanGesture callback", async () => {
600
- const progress = { current: 0 };
601
- const Wrapper = createCarousel(progress);
602
- let _pan: PanGesture | null = null;
603
- render(
604
- <Wrapper
605
- style={{ width: slideWidth, height: slideHeight }}
606
- onConfigurePanGesture={(pan) => {
607
- _pan = pan;
608
- return pan;
609
- }}
610
- />
611
- );
612
-
613
- const { getByTestId } = render(
614
- <Wrapper style={{ width: slideWidth, height: slideHeight }} pagingEnabled={false} />
615
- );
616
- await verifyInitialRender(getByTestId);
617
- expect(_pan).not.toBeNull();
618
- });
619
-
620
- it("`onScrollStart` prop: should call the onScrollStart callback", async () => {
621
- const progress = { current: 0 };
622
- let startedProgress: number | undefined;
623
- const onScrollStart = () => {
624
- if (typeof startedProgress === "number") return;
625
-
626
- startedProgress = progress.current;
627
- };
628
- const Wrapper = createCarousel(progress);
629
- const { getByTestId } = render(
630
- <Wrapper style={{ width: slideWidth, height: slideHeight }} onScrollStart={onScrollStart} />
631
- );
632
- await verifyInitialRender(getByTestId);
633
-
634
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
635
- { state: State.BEGAN, translationX: 0, velocityX: 1000 },
636
- { state: State.ACTIVE, translationX: slideWidth / 2, velocityX: 1000 },
637
- { state: State.END, translationX: slideWidth, velocityX: 1000 },
638
- ]);
639
-
640
- await waitFor(() => {
641
- expect(startedProgress).toBe(0);
642
- });
643
- });
644
-
645
- it("`onScrollEnd` prop: should call the onScrollEnd callback", async () => {
646
- const progress = { current: 0 };
647
- let endedProgress: number | undefined;
648
- const onScrollEnd = jest.fn(() => {
649
- if (typeof endedProgress === "number") return;
650
-
651
- endedProgress = progress.current;
652
- });
653
- const Wrapper = createCarousel(progress);
654
- const { getByTestId } = render(
655
- <Wrapper style={{ width: slideWidth, height: slideHeight }} onScrollEnd={onScrollEnd} />
656
- );
657
- await verifyInitialRender(getByTestId);
658
-
659
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
660
- { state: State.BEGAN, translationX: 0, velocityX: 1000 },
661
- { state: State.ACTIVE, translationX: slideWidth / 2, velocityX: 1000 },
662
- { state: State.END, translationX: slideWidth, velocityX: 1000 },
663
- ]);
664
-
665
- await waitFor(() => {
666
- expect(endedProgress).toBe(3);
667
- expect(onScrollEnd).toHaveBeenCalledWith(3);
668
- });
669
- });
670
-
671
- it("`onProgressChange` prop: should call the onProgressChange callback", async () => {
672
- const offsetProgressVal = { current: 0 };
673
- const absoluteProgressVal = { current: 0 };
674
- const onProgressChange = jest.fn((offsetProgress, absoluteProgress) => {
675
- offsetProgressVal.current = offsetProgress;
676
- absoluteProgressVal.current = absoluteProgress;
677
- });
678
- const Wrapper = createCarousel(offsetProgressVal);
679
- const { getByTestId } = render(
680
- <Wrapper
681
- style={{ width: slideWidth, height: slideHeight }}
682
- onProgressChange={onProgressChange}
683
- defaultIndex={0}
684
- />
685
- );
686
- await verifyInitialRender(getByTestId);
687
-
688
- await waitFor(() => {
689
- expect(offsetProgressVal.current).toBe(0);
690
- expect(absoluteProgressVal.current).toBe(0);
691
- });
692
-
693
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
694
- { state: State.BEGAN, translationX: 0, velocityX: -1000 },
695
- { state: State.ACTIVE, translationX: -slideWidth / 2, velocityX: -1000 },
696
- { state: State.END, translationX: -slideWidth, velocityX: -1000 },
697
- ]);
698
-
699
- await waitFor(() => {
700
- expect(offsetProgressVal.current).toBe(-slideWidth);
701
- expect(absoluteProgressVal.current).toBe(1);
702
- });
703
- });
704
-
705
- it("`fixedDirection` prop: should swipe to the correct direction when fixedDirection is positive", async () => {
706
- {
707
- const progress = { current: 0 };
708
- const Wrapper = createCarousel(progress);
709
- const { getByTestId } = render(
710
- <Wrapper style={{ width: slideWidth, height: slideHeight }} fixedDirection="positive" />
711
- );
712
- await verifyInitialRender(getByTestId);
713
-
714
- swipeToLeftOnce({ velocityX: slideWidth });
715
- await waitFor(() => {
716
- expect(progress.current).toBe(3);
717
- });
718
- }
719
-
720
- {
721
- const progress = { current: 0 };
722
- const Wrapper = createCarousel(progress);
723
- const { getByTestId } = render(
724
- <Wrapper style={{ width: slideWidth, height: slideHeight }} fixedDirection="negative" />
725
- );
726
- await verifyInitialRender(getByTestId);
727
-
728
- swipeToLeftOnce({ velocityX: -slideWidth });
729
- await waitFor(() => expect(progress.current).toBe(1));
730
- }
731
- });
732
-
733
- it("`customAnimation` prop: should apply the custom animation", async () => {
734
- const progress = { current: 0 };
735
- const indexes: Record<number, number> = {};
736
- const Wrapper = createCarousel(progress);
737
- const { getByTestId } = render(
738
- <Wrapper
739
- style={{ width: slideWidth, height: slideHeight }}
740
- customAnimation={(value: number, index: number) => {
741
- "worklet";
742
-
743
- indexes[index] = index;
744
-
745
- const zIndex = interpolate(value, [-1, 0, 1], [10, 20, 30]);
746
- const translateX = interpolate(value, [-2, 0, 1], [-slideWidth, 0, slideWidth]);
747
-
748
- return {
749
- transform: [{ translateX }],
750
- zIndex,
751
- };
752
- }}
753
- />
754
- );
755
-
756
- await verifyInitialRender(getByTestId);
757
-
758
- swipeToLeftOnce();
759
- await waitFor(() => {
760
- expect(progress.current).toBe(1);
761
-
762
- expect(indexes).toMatchInlineSnapshot(`
763
- {
764
- "0": 0,
765
- "1": 1,
766
- "2": 2,
767
- "3": 3,
768
- }
769
- `);
770
- });
771
- });
772
-
773
- it("`overscrollEnabled` prop: should respect overscrollEnabled=false and prevent scrolling beyond bounds", async () => {
774
- const containerWidth = slideWidth;
775
- const containerHeight = containerWidth / 2;
776
-
777
- let nextSlide: (() => void) | undefined;
778
- const testId = "CarouselAnimatedView";
779
- const progress = { current: 0 };
780
- const CarouselW = createCarousel(progress);
781
-
782
- const SCROLL_MS = 250; // Make the animation duration controllable
783
- const TICK = (ms = SCROLL_MS + 10) =>
784
- act(() => {
785
- jest.advanceTimersByTime(ms);
786
- });
787
-
788
- const { getByTestId } = render(
789
- <CarouselW
790
- ref={(ref) => {
791
- if (ref) nextSlide = ref.next;
792
- }}
793
- vertical={false}
794
- style={{ width: containerWidth, height: containerHeight }}
795
- testID={testId}
796
- loop={false}
797
- overscrollEnabled={false}
798
- data={createMockData(6)}
799
- pagingEnabled={false}
800
- scrollAnimationDuration={SCROLL_MS}
801
- />
802
- );
803
-
804
- // Simulate layout
805
- act(() => {
806
- getByTestId("carousel-content-container").props.onLayout({
807
- nativeEvent: { layout: { width: containerWidth, height: containerHeight } },
808
- });
809
- });
810
-
811
- // Let the internal async initialization run
812
- TICK(1);
813
-
814
- const getProgress = () =>
815
- Math.round(((progress.current % slideCount) + slideCount) % slideCount);
816
- const captured: number[] = [];
817
- const pushExpect = (expected: number) => {
818
- captured.push(getProgress());
819
- expect(captured[captured.length - 1]).toBe(expected);
820
- };
821
-
822
- // Initial: At the 0th page
823
- pushExpect(0);
824
-
825
- // next -> 1st page
826
- nextSlide?.();
827
- TICK(); // Wait for the animation to end
828
- pushExpect(1);
829
-
830
- // next -> 2nd page
831
- nextSlide?.();
832
- TICK();
833
- pushExpect(2);
834
-
835
- // next -> 3rd page (still allowed; still enough content)
836
- nextSlide?.();
837
- TICK();
838
- pushExpect(3);
839
-
840
- // next -> 4th page
841
- nextSlide?.();
842
- TICK();
843
- pushExpect(0);
844
-
845
- // next -> 5th page (last item)
846
- nextSlide?.();
847
- TICK();
848
- pushExpect(1);
849
-
850
- // continue next(Already at the last page, and overscroll=false, should not move)
851
- nextSlide?.();
852
- TICK();
853
- pushExpect(1);
854
- });
855
-
856
- it("`overscrollEnabled` false should clamp right overdrag at the first page in non-loop mode", async () => {
857
- const handlerOffset = { current: 0 };
858
- const maxObservedPositiveOffset = { current: 0 };
859
-
860
- const Wrapper: FC<Partial<TCarouselProps<string>>> = React.forwardRef((customProps, ref) => {
861
- const progressAnimVal = useSharedValue(0);
862
- const mockHandlerOffset = useSharedValue(handlerOffset.current);
863
- const defaultRenderItem = ({
864
- item,
865
- index,
866
- }: {
867
- item: string;
868
- index: number;
869
- }) => (
870
- <Animated.View
871
- testID={`carousel-item-${index}`}
872
- style={{ width: slideWidth, height: slideHeight }}
873
- >
874
- {item}
875
- </Animated.View>
876
- );
877
- const { renderItem = defaultRenderItem, ...defaultProps } = createDefaultProps(
878
- progressAnimVal,
879
- customProps
880
- );
881
-
882
- useDerivedValue(() => {
883
- handlerOffset.current = mockHandlerOffset.value;
884
- maxObservedPositiveOffset.current = Math.max(
885
- maxObservedPositiveOffset.current,
886
- mockHandlerOffset.value
887
- );
888
- }, [mockHandlerOffset]);
889
-
890
- return (
891
- <Carousel
892
- {...defaultProps}
893
- defaultScrollOffsetValue={mockHandlerOffset}
894
- renderItem={renderItem}
895
- ref={ref}
896
- />
897
- );
898
- });
899
-
900
- const { getByTestId } = render(
901
- <Wrapper
902
- loop={false}
903
- overscrollEnabled={false}
904
- pagingEnabled={false}
905
- style={{ width: slideWidth, height: slideHeight }}
906
- />
907
- );
908
- await verifyInitialRender(getByTestId);
909
-
910
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
911
- { state: State.BEGAN, translationX: 0, velocityX: slideWidth },
912
- ]);
913
-
914
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
915
- { state: State.ACTIVE, translationX: slideWidth * 0.6, velocityX: slideWidth },
916
- ]);
917
-
918
- await waitFor(() => {
919
- expect(maxObservedPositiveOffset.current).toBe(0);
920
- });
921
- });
922
-
923
- it("should keep correct page after left overscroll at first page when calling next() or scrollTo()", async () => {
924
- const handlerOffset = { current: 0 };
925
- let nextSlide: ((opts?: { animated?: boolean }) => void) | undefined;
926
- let scrollToIndex: ((opts?: { index: number; animated?: boolean }) => void) | undefined;
927
-
928
- const Wrapper: FC<Partial<TCarouselProps<string>>> = React.forwardRef((customProps, ref) => {
929
- const progressAnimVal = useSharedValue(0);
930
- const mockHandlerOffset = useSharedValue(handlerOffset.current);
931
- const defaultRenderItem = ({
932
- item,
933
- index,
934
- }: {
935
- item: string;
936
- index: number;
937
- }) => (
938
- <Animated.View
939
- testID={`carousel-item-${index}`}
940
- style={{ width: slideWidth, height: slideHeight }}
941
- >
942
- {item}
943
- </Animated.View>
944
- );
945
- const { renderItem = defaultRenderItem, ...defaultProps } = createDefaultProps(
946
- progressAnimVal,
947
- customProps
948
- );
949
-
950
- useDerivedValue(() => {
951
- handlerOffset.current = mockHandlerOffset.value;
952
- }, [mockHandlerOffset]);
953
-
954
- return (
955
- <Carousel
956
- {...defaultProps}
957
- defaultScrollOffsetValue={mockHandlerOffset}
958
- renderItem={renderItem}
959
- ref={ref}
960
- />
961
- );
962
- });
963
-
964
- const { getByTestId } = render(
965
- <Wrapper
966
- ref={(ref) => {
967
- if (ref) {
968
- nextSlide = ref.next;
969
- scrollToIndex = ref.scrollTo;
970
- }
971
- }}
972
- loop={false}
973
- overscrollEnabled
974
- style={{ width: slideWidth, height: slideHeight }}
975
- />
976
- );
977
- await verifyInitialRender(getByTestId);
978
-
979
- // Simulate left overscroll at first page
980
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
981
- { state: State.BEGAN, translationX: 0, velocityX: 0 },
982
- { state: State.ACTIVE, translationX: slideWidth / 4, velocityX: slideWidth },
983
- { state: State.ACTIVE, translationX: 0.00003996, velocityX: slideWidth },
984
- { state: State.END, translationX: 0.00003996, velocityX: slideWidth },
985
- ]);
986
-
987
- nextSlide?.({ animated: false });
988
- await waitFor(() => {
989
- expect(handlerOffset.current).toBe(-slideWidth);
990
- });
991
-
992
- // Overscroll again, then call scrollTo()
993
- fireGestureHandler<PanGesture>(getByGestureTestId(gestureTestId), [
994
- { state: State.BEGAN, translationX: 0, velocityX: -slideWidth },
995
- { state: State.ACTIVE, translationX: slideWidth, velocityX: slideWidth },
996
- { state: State.ACTIVE, translationX: slideWidth + 0.00003996, velocityX: slideWidth },
997
- { state: State.END, translationX: slideWidth + 0.00003996, velocityX: slideWidth },
998
- ]);
999
-
1000
- scrollToIndex?.({ index: 1, animated: false });
1001
- await waitFor(() => {
1002
- expect(handlerOffset.current).toBe(-slideWidth);
1003
- });
1004
- });
1005
-
1006
- describe("Carousel sizing and measurement", () => {
1007
- it.each([
1008
- {
1009
- name: "horizontal",
1010
- vertical: false,
1011
- flattenedStyle: { height: slideHeight },
1012
- expected: { width: "100%", height: slideHeight },
1013
- },
1014
- {
1015
- name: "vertical",
1016
- vertical: true,
1017
- flattenedStyle: { width: slideWidth },
1018
- expected: { width: slideWidth, height: "100%" },
1019
- },
1020
- ])("issue #890: keeps an auto-sized $name main axis responsive", (scenario) => {
1021
- expect(
1022
- resolveCarouselLayoutStyle({
1023
- flattenedStyle: scenario.flattenedStyle,
1024
- vertical: scenario.vertical,
1025
- measuredSize: 350,
1026
- sizeExplicit: false,
1027
- })
1028
- ).toEqual(scenario.expected);
1029
- });
1030
-
1031
- it.each([
1032
- {
1033
- name: "legacy width",
1034
- vertical: false,
1035
- legacyWidth: 350,
1036
- legacyHeight: undefined,
1037
- expected: { width: 350, height: "100%" },
1038
- },
1039
- {
1040
- name: "legacy height",
1041
- vertical: true,
1042
- legacyWidth: undefined,
1043
- legacyHeight: 350,
1044
- expected: { width: "100%", height: 350 },
1045
- },
1046
- ])("issue #890: preserves $name behavior", (scenario) => {
1047
- expect(
1048
- resolveCarouselLayoutStyle({
1049
- flattenedStyle: {},
1050
- vertical: scenario.vertical,
1051
- measuredSize: 350,
1052
- sizeExplicit: false,
1053
- legacyWidth: scenario.legacyWidth,
1054
- legacyHeight: scenario.legacyHeight,
1055
- })
1056
- ).toEqual(scenario.expected);
1057
- });
1058
-
1059
- it("issue #890: preserves explicit item size behavior", () => {
1060
- expect(
1061
- resolveCarouselLayoutStyle({
1062
- flattenedStyle: { height: slideHeight },
1063
- vertical: false,
1064
- measuredSize: 350,
1065
- sizeExplicit: true,
1066
- })
1067
- ).toEqual({ width: 350, height: slideHeight });
1068
- });
1069
-
1070
- it("issue #890: prefers the latest page size over a stale item measurement", () => {
1071
- expect(
1072
- resolveItemMainAxisSize({
1073
- effectivePageSize: 516,
1074
- measuredSize: 316,
1075
- })
1076
- ).toBe(516);
1077
- });
1078
-
1079
- it("issue #890: preserves explicit and measured item-size fallbacks", () => {
1080
- expect(
1081
- resolveItemMainAxisSize({
1082
- explicitSize: 280,
1083
- effectivePageSize: 516,
1084
- measuredSize: 316,
1085
- })
1086
- ).toBe(280);
1087
- expect(resolveItemMainAxisSize({ measuredSize: 316 })).toBe(316);
1088
- });
1089
-
1090
- it("issue #890: keeps the active page aligned when an auto-sized layout changes", async () => {
1091
- const observedOffset = { current: 0 };
1092
- let nextSlide: ((opts?: { animated?: boolean }) => void) | undefined;
1093
-
1094
- const Wrapper: FC<Partial<TCarouselProps<string>>> = React.forwardRef((customProps, ref) => {
1095
- const progressAnimVal = useSharedValue(0);
1096
- const scrollOffsetValue = useSharedValue(0);
1097
- const defaultRenderItem = ({
1098
- item,
1099
- index,
1100
- }: {
1101
- item: string;
1102
- index: number;
1103
- }) => (
1104
- <Animated.View testID={`carousel-item-${index}`} style={{ flex: 1 }}>
1105
- {item}
1106
- </Animated.View>
1107
- );
1108
- const { renderItem = defaultRenderItem, ...defaultProps } = createDefaultProps(
1109
- progressAnimVal,
1110
- customProps
1111
- );
1112
-
1113
- useDerivedValue(() => {
1114
- observedOffset.current = scrollOffsetValue.value;
1115
- }, [scrollOffsetValue]);
1116
-
1117
- return (
1118
- <Carousel
1119
- {...defaultProps}
1120
- ref={ref}
1121
- renderItem={renderItem}
1122
- scrollOffsetValue={scrollOffsetValue}
1123
- />
1124
- );
1125
- });
1126
-
1127
- const { getByTestId } = render(
1128
- <Wrapper
1129
- ref={(instance) => {
1130
- if (instance) nextSlide = instance.next;
1131
- }}
1132
- style={{ height: slideHeight }}
1133
- />
1134
- );
1135
- const contentContainer = getByTestId("carousel-content-container");
1136
-
1137
- act(() => {
1138
- contentContainer.props.onLayout({
1139
- nativeEvent: { layout: { width: 320, height: slideHeight } },
1140
- });
1141
- jest.runOnlyPendingTimers();
1142
- });
1143
-
1144
- nextSlide?.({ animated: false });
1145
- await waitFor(() => expect(observedOffset.current).toBe(-320));
1146
-
1147
- act(() => {
1148
- contentContainer.props.onLayout({
1149
- nativeEvent: { layout: { width: 520, height: slideHeight } },
1150
- });
1151
- jest.runOnlyPendingTimers();
1152
- });
1153
-
1154
- await waitFor(() => expect(observedOffset.current).toBe(-520));
1155
- });
1156
-
1157
- it("should render items even before onLayout provides size (flex-based sizing)", async () => {
1158
- const progress = { current: 0 };
1159
- const Wrapper = createCarousel(progress);
1160
-
1161
- // Render with flex: 1 (no explicit width/height values)
1162
- const { queryByTestId } = render(<Wrapper style={{ flex: 1, height: 200 }} />);
1163
-
1164
- // Items should render immediately with initial visible ranges
1165
- // even if size measurement hasn't completed yet
1166
- await waitFor(
1167
- () => {
1168
- const item = queryByTestId("carousel-item-0");
1169
- expect(item).toBeTruthy();
1170
- },
1171
- { timeout: 1000 * 3 }
1172
- );
1173
- });
1174
-
1175
- it("should render items with explicit style dimensions", async () => {
1176
- const progress = { current: 0 };
1177
- const Wrapper = createCarousel(progress);
1178
-
1179
- const { queryByTestId } = render(<Wrapper style={{ width: 400, height: 250 }} />);
1180
-
1181
- // Items should render with explicit dimensions
1182
- await waitFor(
1183
- () => {
1184
- const item = queryByTestId("carousel-item-0");
1185
- expect(item).toBeTruthy();
1186
- },
1187
- { timeout: 1000 * 3 }
1188
- );
1189
- });
1190
-
1191
- it("should render items with itemWidth for custom snap distance", async () => {
1192
- const progress = { current: 0 };
1193
- const Wrapper = createCarousel(progress);
1194
- const containerWidth = 600;
1195
- const itemWidth = 200; // 3 items visible
1196
-
1197
- const { getByTestId } = render(
1198
- <Wrapper style={{ width: containerWidth, height: 200 }} itemWidth={itemWidth} />
1199
- );
1200
-
1201
- // Items should render with itemWidth configuration
1202
- await waitFor(
1203
- () => {
1204
- const item = getByTestId("carousel-item-0");
1205
- expect(item).toBeTruthy();
1206
- },
1207
- { timeout: 1000 * 3 }
1208
- );
1209
-
1210
- // Verify multiple items are visible due to smaller itemWidth
1211
- expect(getByTestId("carousel-item-1")).toBeTruthy();
1212
- expect(getByTestId("carousel-item-2")).toBeTruthy();
1213
- });
1214
- });
1215
- });