react-native-reanimated-carousel 5.0.0-beta.8 → 5.1.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 (402) hide show
  1. package/README.md +31 -29
  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/computed-with-auto-fill-data.js.map +1 -1
  51. package/lib/commonjs/utils/deal-with-animation.js +1 -1
  52. package/lib/commonjs/utils/deal-with-animation.js.map +1 -1
  53. package/lib/module/components/Carousel.js +1 -1
  54. package/lib/module/components/Carousel.js.map +1 -1
  55. package/lib/module/components/CarouselLayout.js +1 -1
  56. package/lib/module/components/CarouselLayout.js.map +1 -1
  57. package/lib/module/components/ItemLayout.js +1 -1
  58. package/lib/module/components/ItemLayout.js.map +1 -1
  59. package/lib/module/components/ItemRenderer.js +1 -1
  60. package/lib/module/components/ItemRenderer.js.map +1 -1
  61. package/lib/module/components/LazyView.js +1 -1
  62. package/lib/module/components/LazyView.js.map +1 -1
  63. package/lib/module/components/Pagination/PaginationItem.js +2 -0
  64. package/lib/module/components/Pagination/PaginationItem.js.map +1 -0
  65. package/lib/module/components/Pagination/index.js +1 -1
  66. package/lib/module/components/Pagination/index.js.map +1 -1
  67. package/lib/module/components/ScrollViewGesture.js +1 -1
  68. package/lib/module/components/ScrollViewGesture.js.map +1 -1
  69. package/lib/module/constants/index.js +1 -1
  70. package/lib/module/constants/index.js.map +1 -1
  71. package/lib/module/hooks/useAutoPlay.js +1 -1
  72. package/lib/module/hooks/useAutoPlay.js.map +1 -1
  73. package/lib/module/hooks/useCarouselController.js +1 -1
  74. package/lib/module/hooks/useCarouselController.js.map +1 -1
  75. package/lib/module/hooks/useCheckMounted.js +1 -1
  76. package/lib/module/hooks/useCheckMounted.js.map +1 -1
  77. package/lib/module/hooks/useCommonVariables.js +1 -1
  78. package/lib/module/hooks/useCommonVariables.js.map +1 -1
  79. package/lib/module/hooks/useInitProps.js +1 -1
  80. package/lib/module/hooks/useInitProps.js.map +1 -1
  81. package/lib/module/hooks/useLayoutConfig.js +1 -1
  82. package/lib/module/hooks/useLayoutConfig.js.map +1 -1
  83. package/lib/module/hooks/useOffsetX.js +1 -1
  84. package/lib/module/hooks/useOffsetX.js.map +1 -1
  85. package/lib/module/hooks/useOnProgressChange.js +1 -1
  86. package/lib/module/hooks/useOnProgressChange.js.map +1 -1
  87. package/lib/module/hooks/usePanGestureProxy.js +1 -1
  88. package/lib/module/hooks/usePanGestureProxy.js.map +1 -1
  89. package/lib/module/hooks/usePropsErrorBoundary.js +1 -1
  90. package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -1
  91. package/lib/module/hooks/useUpdateGestureConfig.js +1 -1
  92. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -1
  93. package/lib/module/hooks/useVisibleRanges.js +1 -1
  94. package/lib/module/hooks/useVisibleRanges.js.map +1 -1
  95. package/lib/module/index.js +1 -1
  96. package/lib/module/index.js.map +1 -1
  97. package/lib/module/layouts/index.js +1 -1
  98. package/lib/module/layouts/index.js.map +1 -1
  99. package/lib/module/layouts/normal.js +1 -1
  100. package/lib/module/layouts/normal.js.map +1 -1
  101. package/lib/module/layouts/parallax.js +1 -1
  102. package/lib/module/layouts/parallax.js.map +1 -1
  103. package/lib/module/layouts/stack.js +1 -1
  104. package/lib/module/layouts/stack.js.map +1 -1
  105. package/lib/module/package.json +1 -0
  106. package/lib/module/public-types.js +2 -0
  107. package/lib/module/public-types.js.map +1 -0
  108. package/lib/module/store/index.js +1 -1
  109. package/lib/module/store/index.js.map +1 -1
  110. package/lib/module/types.js +1 -1
  111. package/lib/module/utils/carousel-direction.js +2 -0
  112. package/lib/module/utils/carousel-direction.js.map +1 -0
  113. package/lib/module/utils/carousel-math.js +2 -0
  114. package/lib/module/utils/carousel-math.js.map +1 -0
  115. package/lib/module/utils/compute-gesture-translation.js +1 -1
  116. package/lib/module/utils/compute-gesture-translation.js.map +1 -1
  117. package/lib/module/utils/compute-offset-if-size-changed.js +1 -1
  118. package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -1
  119. package/lib/module/utils/computed-with-auto-fill-data.js +1 -1
  120. package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -1
  121. package/lib/module/utils/deal-with-animation.js +1 -1
  122. package/lib/module/utils/deal-with-animation.js.map +1 -1
  123. package/lib/module/utils/log.js +1 -1
  124. package/lib/module/utils/log.js.map +1 -1
  125. package/lib/module/utils/sanitize-animation-style.js +1 -1
  126. package/lib/module/utils/sanitize-animation-style.js.map +1 -1
  127. package/lib/typescript/commonjs/components/Carousel.d.ts +8 -0
  128. package/lib/typescript/commonjs/components/Carousel.d.ts.map +1 -0
  129. package/lib/typescript/{components → commonjs/components}/CarouselLayout.d.ts +5 -8
  130. package/lib/typescript/commonjs/components/CarouselLayout.d.ts.map +1 -0
  131. package/lib/typescript/commonjs/components/ItemLayout.d.ts +21 -0
  132. package/lib/typescript/commonjs/components/ItemLayout.d.ts.map +1 -0
  133. package/lib/typescript/commonjs/components/ItemRenderer.d.ts +24 -0
  134. package/lib/typescript/commonjs/components/ItemRenderer.d.ts.map +1 -0
  135. package/lib/typescript/commonjs/components/LazyView.d.ts.map +1 -0
  136. package/lib/typescript/commonjs/components/Pagination/PaginationItem.d.ts +14 -0
  137. package/lib/typescript/commonjs/components/Pagination/PaginationItem.d.ts.map +1 -0
  138. package/lib/typescript/commonjs/components/Pagination/index.d.ts +4 -0
  139. package/lib/typescript/commonjs/components/Pagination/index.d.ts.map +1 -0
  140. package/lib/typescript/{components → commonjs/components}/ScrollViewGesture.d.ts +3 -4
  141. package/lib/typescript/commonjs/components/ScrollViewGesture.d.ts.map +1 -0
  142. package/lib/typescript/commonjs/constants/index.d.ts.map +1 -0
  143. package/lib/typescript/commonjs/hooks/useAutoPlay.d.ts +12 -0
  144. package/lib/typescript/commonjs/hooks/useAutoPlay.d.ts.map +1 -0
  145. package/lib/typescript/commonjs/hooks/useCarouselController.d.ts +29 -0
  146. package/lib/typescript/commonjs/hooks/useCarouselController.d.ts.map +1 -0
  147. package/lib/typescript/commonjs/hooks/useCheckMounted.d.ts.map +1 -0
  148. package/lib/typescript/commonjs/hooks/useCommonVariables.d.ts +18 -0
  149. package/lib/typescript/commonjs/hooks/useCommonVariables.d.ts.map +1 -0
  150. package/lib/typescript/commonjs/hooks/useInitProps.d.ts +25 -0
  151. package/lib/typescript/commonjs/hooks/useInitProps.d.ts.map +1 -0
  152. package/lib/typescript/commonjs/hooks/useLayoutConfig.d.ts +8 -0
  153. package/lib/typescript/commonjs/hooks/useLayoutConfig.d.ts.map +1 -0
  154. package/lib/typescript/commonjs/hooks/useOffsetX.d.ts +13 -0
  155. package/lib/typescript/commonjs/hooks/useOffsetX.d.ts.map +1 -0
  156. package/lib/typescript/commonjs/hooks/useOnProgressChange.d.ts +12 -0
  157. package/lib/typescript/commonjs/hooks/useOnProgressChange.d.ts.map +1 -0
  158. package/lib/typescript/{hooks → commonjs/hooks}/usePanGestureProxy.d.ts +4 -3
  159. package/lib/typescript/commonjs/hooks/usePanGestureProxy.d.ts.map +1 -0
  160. package/lib/typescript/commonjs/hooks/usePropsErrorBoundary.d.ts +3 -0
  161. package/lib/typescript/commonjs/hooks/usePropsErrorBoundary.d.ts.map +1 -0
  162. package/lib/typescript/commonjs/hooks/useUpdateGestureConfig.d.ts +9 -0
  163. package/lib/typescript/commonjs/hooks/useUpdateGestureConfig.d.ts.map +1 -0
  164. package/lib/typescript/{hooks → commonjs/hooks}/useVisibleRanges.d.ts +6 -6
  165. package/lib/typescript/commonjs/hooks/useVisibleRanges.d.ts.map +1 -0
  166. package/lib/typescript/commonjs/index.d.ts +4 -0
  167. package/lib/typescript/commonjs/index.d.ts.map +1 -0
  168. package/lib/typescript/{layouts → commonjs/layouts}/index.d.ts +0 -1
  169. package/lib/typescript/commonjs/layouts/index.d.ts.map +1 -0
  170. package/lib/typescript/commonjs/layouts/normal.d.ts +15 -0
  171. package/lib/typescript/commonjs/layouts/normal.d.ts.map +1 -0
  172. package/lib/typescript/commonjs/layouts/parallax.d.ts +27 -0
  173. package/lib/typescript/commonjs/layouts/parallax.d.ts.map +1 -0
  174. package/lib/typescript/commonjs/layouts/stack.d.ts +10 -0
  175. package/lib/typescript/commonjs/layouts/stack.d.ts.map +1 -0
  176. package/lib/typescript/commonjs/package.json +1 -0
  177. package/lib/typescript/commonjs/public-types.d.ts +171 -0
  178. package/lib/typescript/commonjs/public-types.d.ts.map +1 -0
  179. package/lib/typescript/{store → commonjs/store}/index.d.ts +8 -8
  180. package/lib/typescript/commonjs/store/index.d.ts.map +1 -0
  181. package/lib/typescript/commonjs/types.d.ts +15 -0
  182. package/lib/typescript/commonjs/types.d.ts.map +1 -0
  183. package/lib/typescript/commonjs/utils/carousel-direction.d.ts +9 -0
  184. package/lib/typescript/commonjs/utils/carousel-direction.d.ts.map +1 -0
  185. package/lib/typescript/commonjs/utils/carousel-math.d.ts +28 -0
  186. package/lib/typescript/commonjs/utils/carousel-math.d.ts.map +1 -0
  187. package/lib/typescript/commonjs/utils/compute-gesture-translation.d.ts.map +1 -0
  188. package/lib/typescript/commonjs/utils/compute-offset-if-size-changed.d.ts.map +1 -0
  189. package/lib/typescript/commonjs/utils/computed-with-auto-fill-data.d.ts.map +1 -0
  190. package/lib/typescript/commonjs/utils/deal-with-animation.d.ts +3 -0
  191. package/lib/typescript/commonjs/utils/deal-with-animation.d.ts.map +1 -0
  192. package/lib/typescript/commonjs/utils/log.d.ts.map +1 -0
  193. package/lib/typescript/commonjs/utils/sanitize-animation-style.d.ts.map +1 -0
  194. package/lib/typescript/module/components/Carousel.d.ts +8 -0
  195. package/lib/typescript/module/components/Carousel.d.ts.map +1 -0
  196. package/lib/typescript/module/components/CarouselLayout.d.ts +14 -0
  197. package/lib/typescript/module/components/CarouselLayout.d.ts.map +1 -0
  198. package/lib/typescript/module/components/ItemLayout.d.ts +21 -0
  199. package/lib/typescript/module/components/ItemLayout.d.ts.map +1 -0
  200. package/lib/typescript/module/components/ItemRenderer.d.ts +24 -0
  201. package/lib/typescript/module/components/ItemRenderer.d.ts.map +1 -0
  202. package/lib/typescript/module/components/LazyView.d.ts +8 -0
  203. package/lib/typescript/module/components/LazyView.d.ts.map +1 -0
  204. package/lib/typescript/module/components/Pagination/PaginationItem.d.ts +14 -0
  205. package/lib/typescript/module/components/Pagination/PaginationItem.d.ts.map +1 -0
  206. package/lib/typescript/module/components/Pagination/index.d.ts +4 -0
  207. package/lib/typescript/module/components/Pagination/index.d.ts.map +1 -0
  208. package/lib/typescript/module/components/ScrollViewGesture.d.ts +18 -0
  209. package/lib/typescript/module/components/ScrollViewGesture.d.ts.map +1 -0
  210. package/lib/typescript/module/constants/index.d.ts +9 -0
  211. package/lib/typescript/module/constants/index.d.ts.map +1 -0
  212. package/lib/typescript/module/hooks/useAutoPlay.d.ts +12 -0
  213. package/lib/typescript/module/hooks/useAutoPlay.d.ts.map +1 -0
  214. package/lib/typescript/module/hooks/useCarouselController.d.ts +29 -0
  215. package/lib/typescript/module/hooks/useCarouselController.d.ts.map +1 -0
  216. package/lib/typescript/module/hooks/useCheckMounted.d.ts +3 -0
  217. package/lib/typescript/module/hooks/useCheckMounted.d.ts.map +1 -0
  218. package/lib/typescript/module/hooks/useCommonVariables.d.ts +18 -0
  219. package/lib/typescript/module/hooks/useCommonVariables.d.ts.map +1 -0
  220. package/lib/typescript/module/hooks/useInitProps.d.ts +25 -0
  221. package/lib/typescript/module/hooks/useInitProps.d.ts.map +1 -0
  222. package/lib/typescript/module/hooks/useLayoutConfig.d.ts +8 -0
  223. package/lib/typescript/module/hooks/useLayoutConfig.d.ts.map +1 -0
  224. package/lib/typescript/module/hooks/useOffsetX.d.ts +13 -0
  225. package/lib/typescript/module/hooks/useOffsetX.d.ts.map +1 -0
  226. package/lib/typescript/module/hooks/useOnProgressChange.d.ts +12 -0
  227. package/lib/typescript/module/hooks/useOnProgressChange.d.ts.map +1 -0
  228. package/lib/typescript/module/hooks/usePanGestureProxy.d.ts +11 -0
  229. package/lib/typescript/module/hooks/usePanGestureProxy.d.ts.map +1 -0
  230. package/lib/typescript/module/hooks/usePropsErrorBoundary.d.ts +3 -0
  231. package/lib/typescript/module/hooks/usePropsErrorBoundary.d.ts.map +1 -0
  232. package/lib/typescript/module/hooks/useUpdateGestureConfig.d.ts +9 -0
  233. package/lib/typescript/module/hooks/useUpdateGestureConfig.d.ts.map +1 -0
  234. package/lib/typescript/module/hooks/useVisibleRanges.d.ts +22 -0
  235. package/lib/typescript/module/hooks/useVisibleRanges.d.ts.map +1 -0
  236. package/lib/typescript/module/index.d.ts +4 -0
  237. package/lib/typescript/module/index.d.ts.map +1 -0
  238. package/lib/typescript/module/layouts/index.d.ts +10 -0
  239. package/lib/typescript/module/layouts/index.d.ts.map +1 -0
  240. package/lib/typescript/module/layouts/normal.d.ts +15 -0
  241. package/lib/typescript/module/layouts/normal.d.ts.map +1 -0
  242. package/lib/typescript/module/layouts/parallax.d.ts +27 -0
  243. package/lib/typescript/module/layouts/parallax.d.ts.map +1 -0
  244. package/lib/typescript/module/layouts/stack.d.ts +10 -0
  245. package/lib/typescript/module/layouts/stack.d.ts.map +1 -0
  246. package/lib/typescript/module/package.json +1 -0
  247. package/lib/typescript/module/public-types.d.ts +171 -0
  248. package/lib/typescript/module/public-types.d.ts.map +1 -0
  249. package/lib/typescript/module/store/index.d.ts +35 -0
  250. package/lib/typescript/module/store/index.d.ts.map +1 -0
  251. package/lib/typescript/module/types.d.ts +15 -0
  252. package/lib/typescript/module/types.d.ts.map +1 -0
  253. package/lib/typescript/module/utils/carousel-direction.d.ts +9 -0
  254. package/lib/typescript/module/utils/carousel-direction.d.ts.map +1 -0
  255. package/lib/typescript/module/utils/carousel-math.d.ts +28 -0
  256. package/lib/typescript/module/utils/carousel-math.d.ts.map +1 -0
  257. package/lib/typescript/module/utils/compute-gesture-translation.d.ts +9 -0
  258. package/lib/typescript/module/utils/compute-gesture-translation.d.ts.map +1 -0
  259. package/lib/typescript/module/utils/compute-offset-if-size-changed.d.ts +6 -0
  260. package/lib/typescript/module/utils/compute-offset-if-size-changed.d.ts.map +1 -0
  261. package/lib/typescript/module/utils/computed-with-auto-fill-data.d.ts +23 -0
  262. package/lib/typescript/module/utils/computed-with-auto-fill-data.d.ts.map +1 -0
  263. package/lib/typescript/module/utils/deal-with-animation.d.ts +3 -0
  264. package/lib/typescript/module/utils/deal-with-animation.d.ts.map +1 -0
  265. package/lib/typescript/module/utils/log.d.ts +7 -0
  266. package/lib/typescript/module/utils/log.d.ts.map +1 -0
  267. package/lib/typescript/module/utils/sanitize-animation-style.d.ts +3 -0
  268. package/lib/typescript/module/utils/sanitize-animation-style.d.ts.map +1 -0
  269. package/package.json +31 -6
  270. package/scripts/codemods/v5.mjs +502 -0
  271. package/src/components/Carousel.tsx +5 -5
  272. package/src/components/CarouselLayout.tsx +52 -89
  273. package/src/components/ItemLayout.tsx +57 -48
  274. package/src/components/ItemRenderer.tsx +29 -18
  275. package/src/components/Pagination/PaginationItem.tsx +166 -0
  276. package/src/components/Pagination/index.tsx +105 -6
  277. package/src/components/ScrollViewGesture.tsx +92 -177
  278. package/src/hooks/useAutoPlay.ts +23 -18
  279. package/src/hooks/useCarouselController.tsx +196 -342
  280. package/src/hooks/useCommonVariables.ts +159 -71
  281. package/src/hooks/useInitProps.ts +161 -71
  282. package/src/hooks/useLayoutConfig.ts +21 -12
  283. package/src/hooks/useOffsetX.ts +6 -6
  284. package/src/hooks/useOnProgressChange.ts +23 -48
  285. package/src/hooks/usePanGestureProxy.ts +8 -8
  286. package/src/hooks/usePropsErrorBoundary.ts +32 -90
  287. package/src/hooks/useUpdateGestureConfig.ts +6 -3
  288. package/src/hooks/useVisibleRanges.tsx +6 -6
  289. package/src/index.tsx +14 -9
  290. package/src/layouts/index.tsx +0 -2
  291. package/src/layouts/normal.ts +14 -4
  292. package/src/layouts/parallax.ts +32 -59
  293. package/src/layouts/stack.ts +30 -70
  294. package/src/public-types.ts +209 -0
  295. package/src/store/index.tsx +7 -7
  296. package/src/types.ts +30 -322
  297. package/src/utils/carousel-direction.ts +39 -0
  298. package/src/utils/carousel-math.ts +156 -0
  299. package/src/utils/computed-with-auto-fill-data.ts +2 -2
  300. package/src/utils/deal-with-animation.ts +11 -9
  301. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +0 -2
  302. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +0 -1
  303. package/lib/commonjs/components/Pagination/Basic/index.js +0 -2
  304. package/lib/commonjs/components/Pagination/Basic/index.js.map +0 -1
  305. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js +0 -2
  306. package/lib/commonjs/components/Pagination/Custom/PaginationItem.js.map +0 -1
  307. package/lib/commonjs/components/Pagination/Custom/index.js +0 -2
  308. package/lib/commonjs/components/Pagination/Custom/index.js.map +0 -1
  309. package/lib/commonjs/utils/compute-offset-if-data-changed.js +0 -2
  310. package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +0 -1
  311. package/lib/commonjs/utils/handleroffset-direction.js +0 -2
  312. package/lib/commonjs/utils/handleroffset-direction.js.map +0 -1
  313. package/lib/module/components/Pagination/Basic/PaginationItem.js +0 -2
  314. package/lib/module/components/Pagination/Basic/PaginationItem.js.map +0 -1
  315. package/lib/module/components/Pagination/Basic/index.js +0 -2
  316. package/lib/module/components/Pagination/Basic/index.js.map +0 -1
  317. package/lib/module/components/Pagination/Custom/PaginationItem.js +0 -2
  318. package/lib/module/components/Pagination/Custom/PaginationItem.js.map +0 -1
  319. package/lib/module/components/Pagination/Custom/index.js +0 -2
  320. package/lib/module/components/Pagination/Custom/index.js.map +0 -1
  321. package/lib/module/utils/compute-offset-if-data-changed.js +0 -2
  322. package/lib/module/utils/compute-offset-if-data-changed.js.map +0 -1
  323. package/lib/module/utils/handleroffset-direction.js +0 -2
  324. package/lib/module/utils/handleroffset-direction.js.map +0 -1
  325. package/lib/typescript/components/Carousel.d.ts +0 -8
  326. package/lib/typescript/components/Carousel.d.ts.map +0 -1
  327. package/lib/typescript/components/CarouselLayout.d.ts.map +0 -1
  328. package/lib/typescript/components/ItemLayout.d.ts +0 -20
  329. package/lib/typescript/components/ItemLayout.d.ts.map +0 -1
  330. package/lib/typescript/components/ItemRenderer.d.ts +0 -23
  331. package/lib/typescript/components/ItemRenderer.d.ts.map +0 -1
  332. package/lib/typescript/components/LazyView.d.ts.map +0 -1
  333. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +0 -29
  334. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts.map +0 -1
  335. package/lib/typescript/components/Pagination/Basic/index.d.ts +0 -23
  336. package/lib/typescript/components/Pagination/Basic/index.d.ts.map +0 -1
  337. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts +0 -35
  338. package/lib/typescript/components/Pagination/Custom/PaginationItem.d.ts.map +0 -1
  339. package/lib/typescript/components/Pagination/Custom/index.d.ts +0 -26
  340. package/lib/typescript/components/Pagination/Custom/index.d.ts.map +0 -1
  341. package/lib/typescript/components/Pagination/index.d.ts +0 -5
  342. package/lib/typescript/components/Pagination/index.d.ts.map +0 -1
  343. package/lib/typescript/components/ScrollViewGesture.d.ts.map +0 -1
  344. package/lib/typescript/constants/index.d.ts.map +0 -1
  345. package/lib/typescript/hooks/useAutoPlay.d.ts +0 -12
  346. package/lib/typescript/hooks/useAutoPlay.d.ts.map +0 -1
  347. package/lib/typescript/hooks/useCarouselController.d.ts +0 -28
  348. package/lib/typescript/hooks/useCarouselController.d.ts.map +0 -1
  349. package/lib/typescript/hooks/useCheckMounted.d.ts.map +0 -1
  350. package/lib/typescript/hooks/useCommonVariables.d.ts +0 -13
  351. package/lib/typescript/hooks/useCommonVariables.d.ts.map +0 -1
  352. package/lib/typescript/hooks/useInitProps.d.ts +0 -10
  353. package/lib/typescript/hooks/useInitProps.d.ts.map +0 -1
  354. package/lib/typescript/hooks/useLayoutConfig.d.ts +0 -8
  355. package/lib/typescript/hooks/useLayoutConfig.d.ts.map +0 -1
  356. package/lib/typescript/hooks/useOffsetX.d.ts +0 -13
  357. package/lib/typescript/hooks/useOffsetX.d.ts.map +0 -1
  358. package/lib/typescript/hooks/useOnProgressChange.d.ts +0 -11
  359. package/lib/typescript/hooks/useOnProgressChange.d.ts.map +0 -1
  360. package/lib/typescript/hooks/usePanGestureProxy.d.ts.map +0 -1
  361. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts +0 -5
  362. package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +0 -1
  363. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +0 -6
  364. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts.map +0 -1
  365. package/lib/typescript/hooks/useVisibleRanges.d.ts.map +0 -1
  366. package/lib/typescript/index.d.ts +0 -7
  367. package/lib/typescript/index.d.ts.map +0 -1
  368. package/lib/typescript/layouts/index.d.ts.map +0 -1
  369. package/lib/typescript/layouts/normal.d.ts +0 -13
  370. package/lib/typescript/layouts/normal.d.ts.map +0 -1
  371. package/lib/typescript/layouts/parallax.d.ts +0 -47
  372. package/lib/typescript/layouts/parallax.d.ts.map +0 -1
  373. package/lib/typescript/layouts/stack.d.ts +0 -38
  374. package/lib/typescript/layouts/stack.d.ts.map +0 -1
  375. package/lib/typescript/store/index.d.ts.map +0 -1
  376. package/lib/typescript/types.d.ts +0 -302
  377. package/lib/typescript/types.d.ts.map +0 -1
  378. package/lib/typescript/utils/compute-gesture-translation.d.ts.map +0 -1
  379. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts +0 -9
  380. package/lib/typescript/utils/compute-offset-if-data-changed.d.ts.map +0 -1
  381. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts.map +0 -1
  382. package/lib/typescript/utils/computed-with-auto-fill-data.d.ts.map +0 -1
  383. package/lib/typescript/utils/deal-with-animation.d.ts +0 -3
  384. package/lib/typescript/utils/deal-with-animation.d.ts.map +0 -1
  385. package/lib/typescript/utils/handleroffset-direction.d.ts +0 -4
  386. package/lib/typescript/utils/handleroffset-direction.d.ts.map +0 -1
  387. package/lib/typescript/utils/log.d.ts.map +0 -1
  388. package/lib/typescript/utils/sanitize-animation-style.d.ts.map +0 -1
  389. package/src/components/Pagination/Basic/PaginationItem.tsx +0 -149
  390. package/src/components/Pagination/Basic/index.tsx +0 -98
  391. package/src/components/Pagination/Custom/PaginationItem.tsx +0 -166
  392. package/src/components/Pagination/Custom/index.tsx +0 -111
  393. package/src/utils/compute-offset-if-data-changed.ts +0 -44
  394. package/src/utils/handleroffset-direction.ts +0 -18
  395. /package/lib/typescript/{components → commonjs/components}/LazyView.d.ts +0 -0
  396. /package/lib/typescript/{constants → commonjs/constants}/index.d.ts +0 -0
  397. /package/lib/typescript/{hooks → commonjs/hooks}/useCheckMounted.d.ts +0 -0
  398. /package/lib/typescript/{utils → commonjs/utils}/compute-gesture-translation.d.ts +0 -0
  399. /package/lib/typescript/{utils → commonjs/utils}/compute-offset-if-size-changed.d.ts +0 -0
  400. /package/lib/typescript/{utils → commonjs/utils}/computed-with-auto-fill-data.d.ts +0 -0
  401. /package/lib/typescript/{utils → commonjs/utils}/log.d.ts +0 -0
  402. /package/lib/typescript/{utils → commonjs/utils}/sanitize-animation-style.d.ts +0 -0
@@ -4,74 +4,86 @@ import type { SharedValue } from "react-native-reanimated";
4
4
  import { useAnimatedReaction, useSharedValue } from "react-native-reanimated";
5
5
  import { scheduleOnRN } from "react-native-worklets";
6
6
 
7
- import type { TInitializeCarouselProps } from "./useInitProps";
7
+ import type { InitializedCarouselProps } from "./useInitProps";
8
8
 
9
- import { computeOffsetIfDataChanged } from "../utils/compute-offset-if-data-changed";
9
+ import {
10
+ getNearestLogicalPage,
11
+ positiveModulo,
12
+ reconcileOffsetAfterDataChange,
13
+ } from "../utils/carousel-math";
10
14
  import { computeOffsetIfSizeChanged } from "../utils/compute-offset-if-size-changed";
11
- import { handlerOffsetDirection } from "../utils/handleroffset-direction";
12
15
 
13
- export type TCarouselSizePhase = "pending" | "ready" | "updating";
16
+ export type CarouselSizePhase = "pending" | "ready" | "updating";
14
17
 
15
- export interface ICommonVariables {
18
+ export interface CarouselCommonVariables {
16
19
  size: number;
17
20
  validLength: number;
18
21
  handlerOffset: SharedValue<number>;
19
22
  resolvedSize: SharedValue<number | null>;
20
- sizePhase: SharedValue<TCarouselSizePhase>;
23
+ sizePhase: SharedValue<CarouselSizePhase>;
21
24
  sizeExplicit: boolean;
25
+ isMoving: SharedValue<boolean>;
26
+ dataRevision: number;
27
+ startMovement: () => void;
28
+ cancelMovement: () => void;
29
+ settleMovement: () => void;
22
30
  }
23
31
 
24
- export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommonVariables {
32
+ export function useCommonVariables(
33
+ props: InitializedCarouselProps<unknown>
34
+ ): CarouselCommonVariables {
25
35
  const {
26
- vertical,
36
+ orientation,
27
37
  style,
28
38
  dataLength,
29
39
  defaultIndex,
30
- defaultScrollOffsetValue,
40
+ keyExtractor,
31
41
  loop,
32
- width: explicitWidth,
33
- height: explicitHeight,
34
- itemWidth: explicitItemWidth,
35
- itemHeight: explicitItemHeight,
42
+ itemSize,
43
+ rawData,
44
+ rawDataLength,
36
45
  } = props;
46
+ const isVertical = orientation === "vertical";
37
47
 
38
48
  const manualSize = React.useMemo(() => {
39
- const explicitPageSize = vertical ? explicitItemHeight : explicitItemWidth;
40
- if (typeof explicitPageSize === "number" && explicitPageSize > 0) {
41
- return explicitPageSize;
49
+ if (typeof itemSize === "number" && itemSize > 0) {
50
+ return itemSize;
42
51
  }
43
52
 
44
53
  const { width, height } = StyleSheet.flatten(style) || {};
45
- const candidate = vertical ? height : width;
54
+ const candidate = isVertical ? height : width;
46
55
  if (typeof candidate === "number" && candidate > 0) {
47
56
  return candidate;
48
57
  }
49
58
 
50
- // NOTE: `width`/`height` props are deprecated in v5. They are still respected here to
51
- // maintain backwards compatibility with v4-style usage. Prefer using `style` when both exist.
52
- const explicitCandidate = vertical ? explicitHeight : explicitWidth;
53
- if (typeof explicitCandidate === "number" && explicitCandidate > 0) {
54
- return explicitCandidate;
55
- }
56
-
57
59
  return null;
58
- }, [vertical, style, explicitWidth, explicitHeight, explicitItemHeight, explicitItemWidth]);
60
+ }, [isVertical, itemSize, style]);
59
61
 
60
62
  const resolvedSize = useSharedValue<number | null>(manualSize);
61
- const sizePhase = useSharedValue<TCarouselSizePhase>(manualSize ? "ready" : "pending");
63
+ const sizePhase = useSharedValue<CarouselSizePhase>(manualSize ? "ready" : "pending");
62
64
 
63
- const defaultHandlerOffsetValue = manualSize ? -Math.abs(defaultIndex * manualSize) : 0;
65
+ const defaultHandlerOffsetValue =
66
+ manualSize && dataLength > 0 ? -Math.abs(defaultIndex * manualSize) : 0;
64
67
  const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);
65
- // Prefer the newer `scrollOffsetValue` name, but keep the legacy prop for compatibility.
66
- const handlerOffset = props.scrollOffsetValue ?? defaultScrollOffsetValue ?? _handlerOffset;
67
- const prevDataLength = useSharedValue(dataLength);
68
- const prevSize = useSharedValue(manualSize ?? 0);
69
- const sizeExplicit = React.useMemo(() => {
70
- const explicitPageSize = vertical ? explicitItemHeight : explicitItemWidth;
71
- return typeof explicitPageSize === "number" && explicitPageSize > 0;
72
- }, [explicitItemHeight, explicitItemWidth, vertical]);
68
+ const handlerOffset = props.scrollOffsetValue ?? _handlerOffset;
69
+ const prevDataLength = useSharedValue(rawDataLength);
70
+ const previousRawData = React.useRef(rawData);
71
+ const previousKeyExtractor = React.useRef(keyExtractor);
72
+ const isMoving = useSharedValue(false);
73
+ const pendingDataChange = useSharedValue<{
74
+ previousLength: number;
75
+ currentLength: number;
76
+ retainedIndex: number | null;
77
+ } | null>(null);
78
+ // Start at zero even when a synchronous item size is available. The first
79
+ // size reaction owns initialization and must write the default-index offset
80
+ // into consumer-provided SharedValues as well as the internal value.
81
+ const prevSize = useSharedValue(0);
82
+ const hasInitializedOffset = useSharedValue(false);
83
+ const sizeExplicit = typeof itemSize === "number" && itemSize > 0;
73
84
 
74
85
  const [size, setSize] = React.useState<number>(manualSize ?? 0);
86
+ const [dataRevision, setDataRevision] = React.useState(0);
75
87
 
76
88
  const syncSize = React.useCallback((next: number) => {
77
89
  setSize((current) => (current === next ? current : next));
@@ -95,43 +107,107 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
95
107
  }
96
108
  }, [manualSize, resolvedSize, sizePhase]);
97
109
 
110
+ React.useEffect(() => {
111
+ const currentSize = resolvedSize.value ?? 0;
112
+ if (currentSize <= 0 || dataLength <= 0 || hasInitializedOffset.value) return;
113
+
114
+ handlerOffset.value = -(defaultIndex * currentSize);
115
+ prevSize.value = currentSize;
116
+ hasInitializedOffset.value = true;
117
+ }, [dataLength, defaultIndex, handlerOffset, hasInitializedOffset, prevSize, resolvedSize]);
118
+
119
+ const reconcileDataChange = React.useCallback(
120
+ (previousLength: number, currentLength: number, retainedIndex?: number) => {
121
+ const currentSize = resolvedSize.value ?? 0;
122
+ if (currentSize <= 0) return;
123
+
124
+ handlerOffset.value = reconcileOffsetAfterDataChange({
125
+ offset: handlerOffset.value,
126
+ itemSize: currentSize,
127
+ previousCount: previousLength,
128
+ nextCount: currentLength,
129
+ defaultIndex,
130
+ loop,
131
+ retainedIndex,
132
+ });
133
+ setDataRevision((revision) => revision + 1);
134
+ },
135
+ [defaultIndex, handlerOffset, loop, resolvedSize]
136
+ );
137
+
138
+ const startMovement = React.useCallback(() => {
139
+ isMoving.value = true;
140
+ }, [isMoving]);
141
+
142
+ const finishMovement = React.useCallback(() => {
143
+ isMoving.value = false;
144
+ const pending = pendingDataChange.value;
145
+ if (!pending) return;
146
+
147
+ pendingDataChange.value = null;
148
+ reconcileDataChange(
149
+ pending.previousLength,
150
+ pending.currentLength,
151
+ pending.retainedIndex ?? undefined
152
+ );
153
+ }, [isMoving, pendingDataChange, reconcileDataChange]);
154
+
98
155
  /**
99
156
  * When data changes, we need to compute new index for handlerOffset
100
157
  */
101
- useAnimatedReaction(
102
- () => {
103
- const previousLength = prevDataLength.value;
104
- const currentLength = dataLength;
105
- const isLengthChanged = previousLength !== currentLength;
106
- const shouldComputed = isLengthChanged && loop;
107
-
108
- if (shouldComputed) prevDataLength.value = dataLength;
109
-
110
- return {
111
- shouldComputed,
112
- previousLength,
113
- currentLength,
114
- };
115
- },
116
- ({ shouldComputed, previousLength, currentLength }) => {
117
- if (shouldComputed) {
118
- // direction -> 1 | -1
119
- const direction = handlerOffsetDirection(handlerOffset);
120
-
121
- const _size = resolvedSize.value ?? 0;
122
- if (_size <= 0) return;
123
-
124
- handlerOffset.value = computeOffsetIfDataChanged({
125
- direction,
126
- previousLength,
127
- currentLength,
128
- size: _size,
129
- handlerOffset: handlerOffset.value,
130
- });
158
+ React.useEffect(() => {
159
+ const previousLength = prevDataLength.value;
160
+ const previousItems = previousRawData.current;
161
+ const dataChanged =
162
+ previousLength !== rawDataLength ||
163
+ previousItems.length !== rawData.length ||
164
+ previousItems.some((item, index) => !Object.is(item, rawData[index]));
165
+
166
+ previousRawData.current = rawData;
167
+ const extractorForPreviousData = previousKeyExtractor.current ?? keyExtractor;
168
+ previousKeyExtractor.current = keyExtractor;
169
+
170
+ if (!dataChanged) return;
171
+
172
+ let retainedIndex: number | undefined;
173
+ if (keyExtractor && extractorForPreviousData && previousLength > 0 && rawDataLength > 0) {
174
+ const currentSize = resolvedSize.value ?? 0;
175
+ const pendingIndex = pendingDataChange.value?.retainedIndex;
176
+ const previousIndex =
177
+ typeof pendingIndex === "number"
178
+ ? pendingIndex
179
+ : positiveModulo(getNearestLogicalPage(handlerOffset.value, currentSize), previousLength);
180
+ if (previousIndex < previousItems.length) {
181
+ const selectedKey = extractorForPreviousData(previousItems[previousIndex], previousIndex);
182
+ const matchingIndex = rawData.findIndex(
183
+ (item, index) => keyExtractor(item, index) === selectedKey
184
+ );
185
+ if (matchingIndex >= 0) retainedIndex = matchingIndex;
131
186
  }
132
- },
133
- [dataLength, loop, resolvedSize]
134
- );
187
+ }
188
+
189
+ prevDataLength.value = rawDataLength;
190
+ if (isMoving.value) {
191
+ pendingDataChange.value = {
192
+ previousLength: pendingDataChange.value?.previousLength ?? previousLength,
193
+ currentLength: rawDataLength,
194
+ retainedIndex: retainedIndex ?? null,
195
+ };
196
+ return;
197
+ }
198
+
199
+ reconcileDataChange(previousLength, rawDataLength, retainedIndex);
200
+ }, [
201
+ handlerOffset,
202
+ isMoving,
203
+ keyExtractor,
204
+ pendingDataChange,
205
+ prevDataLength,
206
+ rawData,
207
+ rawDataLength,
208
+ reconcileDataChange,
209
+ resolvedSize,
210
+ ]);
135
211
 
136
212
  /**
137
213
  * When size changes, we need to compute new index for handlerOffset
@@ -146,8 +222,15 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
146
222
 
147
223
  sizePhase.value = previousSize > 0 ? "updating" : sizePhase.value;
148
224
 
149
- if (previousSize <= 0) {
150
- handlerOffset.value = -Math.abs(defaultIndex * currentSize);
225
+ if (dataLength <= 0) {
226
+ prevSize.value = currentSize;
227
+ sizePhase.value = "ready";
228
+ return;
229
+ }
230
+
231
+ if (previousSize <= 0 || !hasInitializedOffset.value) {
232
+ handlerOffset.value = -(defaultIndex * currentSize);
233
+ hasInitializedOffset.value = true;
151
234
  } else {
152
235
  handlerOffset.value = computeOffsetIfSizeChanged({
153
236
  handlerOffset: handlerOffset.value,
@@ -159,7 +242,7 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
159
242
  prevSize.value = currentSize;
160
243
  sizePhase.value = "ready";
161
244
  },
162
- [defaultIndex, resolvedSize, sizePhase]
245
+ [dataLength, defaultIndex, hasInitializedOffset, resolvedSize, sizePhase]
163
246
  );
164
247
 
165
248
  return {
@@ -169,5 +252,10 @@ export function useCommonVariables(props: TInitializeCarouselProps<any>): ICommo
169
252
  resolvedSize,
170
253
  sizePhase,
171
254
  sizeExplicit,
255
+ isMoving,
256
+ dataRevision,
257
+ startMovement,
258
+ cancelMovement: finishMovement,
259
+ settleMovement: finishMovement,
172
260
  };
173
261
  }
@@ -1,87 +1,177 @@
1
1
  import React from "react";
2
+ import { I18nManager } from "react-native";
2
3
 
3
- import type { TCarouselProps } from "../types";
4
+ import { Easing } from "../constants";
5
+ import type { CarouselAnimation, CarouselProps } from "../types";
6
+ import { type CarouselDirectionSign, getCarouselDirectionSign } from "../utils/carousel-direction";
4
7
  import { computedFillDataWithAutoFillData } from "../utils/computed-with-auto-fill-data";
5
8
 
6
- type TGetRequiredProps<P extends keyof TCarouselProps> = Record<P, Required<TCarouselProps>[P]>;
9
+ type CarouselSnapMode = NonNullable<CarouselProps<unknown>["snapMode"]>;
7
10
 
8
- export type TInitializeCarouselProps<T> = TCarouselProps<T> &
9
- TGetRequiredProps<
10
- "defaultIndex" | "loop" | "scrollAnimationDuration" | "autoPlayInterval" | "autoFillData"
11
- > & {
12
- // Raw data that has not been processed
13
- rawData: T[];
14
- dataLength: number;
15
- rawDataLength: number;
11
+ export type InitializedCarouselProps<Item> = Omit<
12
+ CarouselProps<Item>,
13
+ | "autoplay"
14
+ | "autoplayDirection"
15
+ | "autoplayInterval"
16
+ | "data"
17
+ | "defaultIndex"
18
+ | "loop"
19
+ | "orientation"
20
+ | "overscrollEnabled"
21
+ | "scrollEnabled"
22
+ | "snapMode"
23
+ | "style"
24
+ > & {
25
+ autoplay: boolean;
26
+ autoplayDirection: "forward" | "backward";
27
+ autoplayInterval: number;
28
+ data: Item[];
29
+ defaultIndex: number;
30
+ loop: boolean;
31
+ orientation: "horizontal" | "vertical";
32
+ overscrollEnabled: boolean;
33
+ scrollEnabled: boolean;
34
+ snapMode: CarouselSnapMode;
35
+ style: NonNullable<CarouselProps<Item>["style"]>;
36
+ animation: CarouselAnimation;
37
+ rawData: Item[];
38
+ dataLength: number;
39
+ rawDataLength: number;
40
+ autoFillData: true;
41
+ directionSign: CarouselDirectionSign;
42
+ };
43
+
44
+ export function useInitProps<Item>(props: CarouselProps<Item>): InitializedCarouselProps<Item> {
45
+ validateStaticProps(props);
46
+
47
+ const rawData = props.data ?? [];
48
+ const requestedDefaultIndex = props.defaultIndex ?? 0;
49
+ const loop = props.loop ?? false;
50
+ const autoplay = props.autoplay ?? false;
51
+ const autoplayInterval = props.autoplayInterval ?? 3000;
52
+ const autoplayDirection = props.autoplayDirection ?? "forward";
53
+ const orientation = props.orientation ?? "horizontal";
54
+ const directionSign = getCarouselDirectionSign({
55
+ isRTL: I18nManager.isRTL,
56
+ orientation,
57
+ });
58
+ const scrollEnabled = props.scrollEnabled ?? true;
59
+ const snapMode = props.snapMode ?? "page";
60
+ const overscrollEnabled = props.overscrollEnabled ?? true;
61
+ const style = props.style ?? {};
62
+ const animation: CarouselAnimation = props.animation ?? {
63
+ type: "timing",
64
+ duration: 500,
65
+ easing: Easing.easeOutQuart,
16
66
  };
17
67
 
18
- export function useInitProps<T>(props: TCarouselProps<T>): TInitializeCarouselProps<T> {
19
- const {
20
- defaultIndex = 0,
21
- data: rawData = [],
22
- loop = true,
23
- autoPlayInterval: _autoPlayInterval = 1000,
24
- scrollAnimationDuration = 500,
25
- style = {},
26
- autoFillData = true,
27
- // switchers
28
- enabled = true,
29
- pagingEnabled = true,
30
- overscrollEnabled = true,
31
- snapEnabled = props.enableSnap ?? true,
32
- width: _width,
33
- height: _height,
34
- itemWidth: _itemWidth,
35
- itemHeight: _itemHeight,
36
- } = props;
37
-
38
- const width = typeof _width === "number" ? Math.round(_width) : undefined;
39
- const height = typeof _height === "number" ? Math.round(_height) : undefined;
40
- const itemWidth = typeof _itemWidth === "number" && _itemWidth > 0 ? _itemWidth : undefined;
41
- const itemHeight = typeof _itemHeight === "number" && _itemHeight > 0 ? _itemHeight : undefined;
42
- const autoPlayInterval = Math.max(_autoPlayInterval, 0);
43
-
44
- const data = React.useMemo<T[]>(() => {
45
- return computedFillDataWithAutoFillData<T>({
46
- loop,
47
- autoFillData,
48
- data: rawData,
49
- dataLength: rawData.length,
50
- });
51
- }, [rawData, loop, autoFillData]);
52
-
53
- const dataLength = data.length;
54
- const rawDataLength = rawData.length;
55
-
56
- if (props.mode === "vertical-stack" || props.mode === "horizontal-stack") {
57
- if (!props.modeConfig) props.modeConfig = {};
58
-
59
- props.modeConfig.showLength = props.modeConfig?.showLength ?? dataLength - 1;
68
+ const defaultIndexState = React.useRef<{
69
+ consumed: boolean;
70
+ requested: number;
71
+ resolved: number;
72
+ warned: boolean;
73
+ } | null>(null);
74
+
75
+ if (!defaultIndexState.current) {
76
+ if (rawData.length > 0) {
77
+ assertValidDefaultIndex(requestedDefaultIndex, rawData.length);
78
+ }
79
+
80
+ defaultIndexState.current = {
81
+ consumed: rawData.length > 0,
82
+ requested: requestedDefaultIndex,
83
+ resolved: rawData.length > 0 ? requestedDefaultIndex : 0,
84
+ warned: false,
85
+ };
86
+ } else if (!defaultIndexState.current.consumed && rawData.length > 0) {
87
+ const pendingIndex = defaultIndexState.current.requested;
88
+ defaultIndexState.current.consumed = true;
89
+
90
+ if (isValidDefaultIndex(pendingIndex, rawData.length)) {
91
+ defaultIndexState.current.resolved = pendingIndex;
92
+ } else {
93
+ defaultIndexState.current.resolved = 0;
94
+ if (__DEV__ && !defaultIndexState.current.warned) {
95
+ console.warn(
96
+ `[react-native-reanimated-carousel] Ignored defaultIndex ${pendingIndex} because it is outside the first non-empty data set.`
97
+ );
98
+ defaultIndexState.current.warned = true;
99
+ }
100
+ }
60
101
  }
61
102
 
103
+ const defaultIndex = defaultIndexState.current.resolved;
104
+ const data = React.useMemo(
105
+ () =>
106
+ computedFillDataWithAutoFillData({
107
+ loop,
108
+ autoFillData: true,
109
+ data: rawData,
110
+ dataLength: rawData.length,
111
+ }),
112
+ [loop, rawData]
113
+ );
114
+
62
115
  return {
63
116
  ...props,
117
+ autoplay,
118
+ autoplayDirection,
119
+ autoplayInterval,
64
120
  defaultIndex,
65
- autoFillData,
66
- // Fill data with autoFillData
67
- data,
68
- // Length of fill data
69
- dataLength,
70
- // Raw data that has not been processed
71
- rawData,
72
- // Length of raw data
73
- rawDataLength,
74
121
  loop,
75
- enabled,
76
- autoPlayInterval,
77
- scrollAnimationDuration,
78
- style,
79
- pagingEnabled,
80
- snapEnabled,
122
+ orientation,
81
123
  overscrollEnabled,
82
- width,
83
- height,
84
- itemWidth,
85
- itemHeight,
124
+ scrollEnabled,
125
+ snapMode,
126
+ style,
127
+ animation,
128
+ data,
129
+ rawData,
130
+ dataLength: data.length,
131
+ rawDataLength: rawData.length,
132
+ autoFillData: true,
133
+ directionSign,
86
134
  };
87
135
  }
136
+
137
+ function validateStaticProps<Item>(props: CarouselProps<Item>) {
138
+ if (props.layout && props.itemAnimation) {
139
+ throw new Error(
140
+ "[react-native-reanimated-carousel] `layout` and `itemAnimation` are mutually exclusive."
141
+ );
142
+ }
143
+
144
+ if (props.itemSize !== undefined && (!Number.isFinite(props.itemSize) || props.itemSize <= 0)) {
145
+ throw new Error("[react-native-reanimated-carousel] itemSize must be a positive number.");
146
+ }
147
+
148
+ if (
149
+ props.autoplayInterval !== undefined &&
150
+ (!Number.isFinite(props.autoplayInterval) || props.autoplayInterval < 0)
151
+ ) {
152
+ throw new Error(
153
+ "[react-native-reanimated-carousel] autoplayInterval must be a non-negative number."
154
+ );
155
+ }
156
+
157
+ if (
158
+ props.renderWindowSize !== undefined &&
159
+ (!Number.isInteger(props.renderWindowSize) || props.renderWindowSize <= 0)
160
+ ) {
161
+ throw new Error(
162
+ "[react-native-reanimated-carousel] renderWindowSize must be a positive integer."
163
+ );
164
+ }
165
+ }
166
+
167
+ function isValidDefaultIndex(defaultIndex: number, dataLength: number) {
168
+ return Number.isInteger(defaultIndex) && defaultIndex >= 0 && defaultIndex < dataLength;
169
+ }
170
+
171
+ function assertValidDefaultIndex(defaultIndex: number, dataLength: number) {
172
+ if (!isValidDefaultIndex(defaultIndex, dataLength)) {
173
+ throw new Error(
174
+ `[react-native-reanimated-carousel] defaultIndex must be an integer between 0 and ${dataLength - 1}.`
175
+ );
176
+ }
177
+ }
@@ -1,26 +1,35 @@
1
1
  import React from "react";
2
2
 
3
- import type { TInitializeCarouselProps } from "./useInitProps";
4
-
5
- import type { TAnimationStyle } from "../components/ItemLayout";
6
3
  import { Layouts } from "../layouts";
4
+ import type { CarouselItemAnimation } from "../types";
5
+ import type { InitializedCarouselProps } from "./useInitProps";
7
6
 
8
- type TLayoutConfigOpts<T> = TInitializeCarouselProps<T> & { size: number };
7
+ type LayoutConfigOptions<Item> = InitializedCarouselProps<Item> & { size: number };
9
8
 
10
- export function useLayoutConfig<T>(opts: TLayoutConfigOpts<T>): TAnimationStyle {
11
- const { size, vertical } = opts as Required<TLayoutConfigOpts<T>>;
9
+ export function useLayoutConfig<Item>(options: LayoutConfigOptions<Item>): CarouselItemAnimation {
10
+ const { dataLength, directionSign, layout, orientation, size } = options;
11
+ const isVertical = orientation === "vertical";
12
12
 
13
13
  return React.useMemo(() => {
14
- const baseConfig = { size, vertical };
15
- switch (opts.mode) {
14
+ const baseConfig = { size, isVertical, directionSign };
15
+ switch (layout?.type) {
16
16
  case "parallax":
17
- return Layouts.parallax(baseConfig, opts.modeConfig);
17
+ return Layouts.parallax(baseConfig, layout);
18
18
  case "horizontal-stack":
19
- return Layouts.horizontalStack(opts.modeConfig);
19
+ return Layouts.horizontalStack(
20
+ {
21
+ ...layout,
22
+ visibleCount: layout.visibleCount ?? Math.max(0, dataLength - 1),
23
+ },
24
+ directionSign
25
+ );
20
26
  case "vertical-stack":
21
- return Layouts.verticalStack(opts.modeConfig);
27
+ return Layouts.verticalStack({
28
+ ...layout,
29
+ visibleCount: layout.visibleCount ?? Math.max(0, dataLength - 1),
30
+ });
22
31
  default:
23
32
  return Layouts.normal(baseConfig);
24
33
  }
25
- }, [opts.mode, opts.modeConfig, size, vertical]);
34
+ }, [dataLength, directionSign, isVertical, layout, size]);
26
35
  }
@@ -1,19 +1,19 @@
1
1
  import type { SharedValue } from "react-native-reanimated";
2
2
  import { Extrapolation, interpolate, useDerivedValue } from "react-native-reanimated";
3
3
 
4
- import type { IVisibleRanges } from "./useVisibleRanges";
4
+ import type { VisibleRangesValue } from "./useVisibleRanges";
5
5
 
6
- export interface IOpts {
6
+ export interface OffsetOptions {
7
7
  index: number;
8
8
  size: number;
9
9
  handlerOffset: SharedValue<number>;
10
10
  dataLength: number;
11
- type?: "positive" | "negative";
12
- viewCount?: number;
13
- loop?: boolean;
11
+ type?: "positive" | "negative" | undefined;
12
+ viewCount?: number | undefined;
13
+ loop?: boolean | undefined;
14
14
  }
15
15
 
16
- export const useOffsetX = (opts: IOpts, visibleRanges: IVisibleRanges) => {
16
+ export const useOffsetX = (opts: OffsetOptions, visibleRanges: VisibleRangesValue) => {
17
17
  const {
18
18
  handlerOffset,
19
19
  index,