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,422 +1,273 @@
1
1
  import React, { useRef } from "react";
2
- import { StyleSheet } from "react-native";
3
- import { SharedValue, useAnimatedReaction, useSharedValue } from "react-native-reanimated";
2
+ import type { SharedValue } from "react-native-reanimated";
3
+ import { useAnimatedReaction, useSharedValue } from "react-native-reanimated";
4
4
  import { scheduleOnRN } from "react-native-worklets";
5
5
 
6
- import { Easing } from "../constants";
7
6
  import { useGlobalState } from "../store";
8
7
  import type {
9
- ICarouselInstance,
10
- TCarouselActionOptions,
11
- TCarouselProps,
12
- WithTimingAnimation,
8
+ CarouselAnimation,
9
+ CarouselRef,
10
+ InternalCarouselScrollToOptions,
11
+ InternalCarouselStepOptions,
13
12
  } from "../types";
14
13
  import {
15
- computedRealIndexWithAutoFillData,
16
- convertToSharedIndex,
17
- } from "../utils/computed-with-auto-fill-data";
14
+ getLogicalProgress,
15
+ getNearestLogicalPage,
16
+ getSettledRawIndex,
17
+ getShortestLoopTargetPage,
18
+ positiveModulo,
19
+ } from "../utils/carousel-math";
18
20
  import { dealWithAnimation } from "../utils/deal-with-animation";
19
- import { handlerOffsetDirection } from "../utils/handleroffset-direction";
20
- import { round } from "../utils/log";
21
21
 
22
- interface IOpts {
23
- ref: React.ForwardedRef<ICarouselInstance>;
22
+ interface CarouselControllerOptions {
23
+ ref: React.ForwardedRef<CarouselRef>;
24
24
  loop: boolean;
25
25
  size: number;
26
26
  dataLength: number;
27
+ rawDataLength: number;
27
28
  handlerOffset: SharedValue<number>;
28
- autoFillData: TCarouselProps["autoFillData"];
29
- withAnimation?: TCarouselProps["withAnimation"];
30
- fixedDirection?: TCarouselProps["fixedDirection"];
31
- duration?: number;
29
+ animation: CarouselAnimation;
32
30
  defaultIndex?: number;
33
31
  onScrollStart?: () => void;
34
- onScrollEnd?: () => void;
32
+ onMovementEnd?: (index: number) => void;
35
33
  }
36
34
 
37
- export interface ICarouselController {
35
+ export interface CarouselController {
38
36
  getSharedIndex: () => number;
39
- prev: (opts?: TCarouselActionOptions) => void;
40
- next: (opts?: TCarouselActionOptions) => void;
37
+ prev: (options?: InternalCarouselStepOptions) => void;
38
+ next: (options?: InternalCarouselStepOptions) => void;
41
39
  getCurrentIndex: () => number;
42
- scrollTo: (opts?: TCarouselActionOptions) => void;
40
+ scrollTo: (options: InternalCarouselScrollToOptions) => void;
43
41
  index: SharedValue<number>;
42
+ startMovement: () => void;
43
+ cancelMovement: () => void;
44
+ settle: () => number;
44
45
  }
45
46
 
46
- export function useCarouselController(options: IOpts): ICarouselController {
47
+ export function useCarouselController(options: CarouselControllerOptions): CarouselController {
47
48
  const {
48
- ref,
49
- size,
50
- loop,
49
+ animation,
51
50
  dataLength,
52
- handlerOffset,
53
- withAnimation,
54
51
  defaultIndex = 0,
55
- duration,
56
- autoFillData,
57
- fixedDirection,
52
+ handlerOffset,
53
+ loop,
54
+ rawDataLength,
55
+ ref,
56
+ size,
58
57
  } = options;
58
+ const {
59
+ common: {
60
+ cancelMovement: cancelCommonMovement,
61
+ dataRevision,
62
+ isMoving,
63
+ resolvedSize,
64
+ settleMovement,
65
+ sizePhase,
66
+ startMovement: startCommonMovement,
67
+ },
68
+ } = useGlobalState();
59
69
 
60
- const globalState = useGlobalState();
70
+ const index = useSharedValue(defaultIndex);
71
+ const liveRawIndex = useRef(rawDataLength > 0 ? defaultIndex : 0);
72
+ const settledIndex = useRef(rawDataLength > 0 ? defaultIndex : 0);
73
+ const warnedCommands = useRef(new Set<string>());
74
+ const canMove = rawDataLength > 1;
61
75
 
62
- const {
63
- props: { overscrollEnabled, vertical, style, width, height },
64
- layout: { containerSize },
65
- common: { sizePhase, resolvedSize },
66
- } = globalState;
76
+ const warnOnce = React.useCallback((key: string, message: string) => {
77
+ if (!__DEV__ || warnedCommands.current.has(key)) return;
78
+ warnedCommands.current.add(key);
79
+ console.warn(`[react-native-reanimated-carousel] ${message}`);
80
+ }, []);
67
81
 
68
- const dataInfo = React.useMemo(
69
- () => ({
70
- length: dataLength,
71
- disable: !dataLength,
72
- originalLength: dataLength,
73
- }),
74
- [dataLength]
75
- );
82
+ const currentVisualPage = React.useCallback(() => {
83
+ if (size <= 0 || rawDataLength <= 0) return 0;
76
84
 
77
- const index = useSharedValue<number>(defaultIndex);
78
- // The Index displayed to the user
79
- const sharedIndex = useRef<number>(defaultIndex);
80
- const sharedPreIndex = useRef<number>(defaultIndex);
81
-
82
- const currentFixedPage = React.useCallback(() => {
83
- if (size <= 0) return 0;
84
- if (loop) return -Math.round(handlerOffset.value / size);
85
-
86
- // In non-loop mode, treat the offset as negative when moving forward.
87
- // Clamp within valid range to avoid wrapping when a tiny positive offset
88
- // appears after overscroll at index 0.
89
- const rawPage = -handlerOffset.value / size;
90
- const rounded = Math.round(rawPage);
91
- const clamped = Math.max(0, Math.min(dataInfo.length - 1, rounded));
92
- return clamped;
93
- }, [handlerOffset, dataInfo, size, loop]);
94
-
95
- function setSharedIndex(newSharedIndex: number) {
96
- sharedIndex.current = newSharedIndex;
85
+ const page = getNearestLogicalPage(handlerOffset.value, size);
86
+ return loop ? page : Math.max(0, Math.min(rawDataLength - 1, page));
87
+ }, [handlerOffset, loop, rawDataLength, size]);
88
+
89
+ function setLiveRawIndex(nextIndex: number) {
90
+ liveRawIndex.current = nextIndex;
97
91
  }
98
92
 
99
93
  useAnimatedReaction(
100
94
  () => {
101
- if (size <= 0) {
102
- return {
103
- i: 0,
104
- newSharedIndexValue: 0,
105
- };
95
+ if (size <= 0 || dataLength <= 0 || rawDataLength <= 0) {
96
+ return { physicalIndex: 0, rawIndex: 0 };
106
97
  }
107
98
 
108
- const handlerOffsetValue = handlerOffset.value;
109
- const toInt = round(handlerOffsetValue / size) % dataInfo.length;
110
- const isPositive = handlerOffsetValue <= 0;
111
- const i = isPositive ? Math.abs(toInt) : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);
112
-
113
- const newSharedIndexValue = convertToSharedIndex({
114
- loop,
115
- rawDataLength: dataInfo.originalLength,
116
- autoFillData: autoFillData!,
117
- index: i,
118
- });
119
-
99
+ const page = getNearestLogicalPage(handlerOffset.value, size);
120
100
  return {
121
- i,
122
- newSharedIndexValue,
101
+ physicalIndex: positiveModulo(page, dataLength),
102
+ rawIndex: positiveModulo(page, rawDataLength),
123
103
  };
124
104
  },
125
- ({ i, newSharedIndexValue }) => {
126
- index.value = i;
127
- scheduleOnRN(setSharedIndex, newSharedIndexValue);
105
+ ({ physicalIndex, rawIndex }) => {
106
+ index.value = physicalIndex;
107
+ scheduleOnRN(setLiveRawIndex, rawIndex);
128
108
  },
129
- [sharedPreIndex, sharedIndex, size, dataInfo, index, loop, autoFillData, handlerOffset]
109
+ [dataLength, handlerOffset, index, rawDataLength, size]
130
110
  );
131
111
 
132
- const getCurrentIndex = React.useCallback(() => {
133
- const realIndex = computedRealIndexWithAutoFillData({
134
- index: index.value,
135
- dataLength: dataInfo.originalLength,
136
- loop,
137
- autoFillData: autoFillData!,
138
- });
112
+ const settle = React.useCallback(
113
+ (targetIndex?: number) => {
114
+ settleMovement();
115
+
116
+ const nextSettledIndex =
117
+ typeof targetIndex === "number" && rawDataLength > 0
118
+ ? positiveModulo(Math.round(targetIndex), rawDataLength)
119
+ : getSettledRawIndex(
120
+ loop
121
+ ? getLogicalProgress(handlerOffset.value, size)
122
+ : Math.max(
123
+ 0,
124
+ Math.min(rawDataLength - 1, getLogicalProgress(handlerOffset.value, size))
125
+ ),
126
+ rawDataLength
127
+ );
128
+
129
+ settledIndex.current = nextSettledIndex;
130
+ return nextSettledIndex;
131
+ },
132
+ [handlerOffset, loop, rawDataLength, settleMovement, size]
133
+ );
139
134
 
140
- return realIndex;
141
- }, [index, autoFillData, dataInfo, loop]);
135
+ const getCurrentIndex = React.useCallback(() => settledIndex.current, []);
136
+ const getSharedIndex = React.useCallback(() => liveRawIndex.current, []);
137
+ const startMovement = React.useCallback(() => startCommonMovement(), [startCommonMovement]);
138
+ const cancelMovement = React.useCallback(() => cancelCommonMovement(), [cancelCommonMovement]);
142
139
 
143
- const canSliding = React.useCallback(() => {
144
- const currentSize = resolvedSize.value ?? size;
145
- const ready = sizePhase.value === "ready" && !!currentSize;
140
+ React.useEffect(() => {
141
+ if (!isMoving.value) settle();
142
+ }, [dataRevision, isMoving, rawDataLength, settle]);
146
143
 
147
- return !dataInfo.disable && ready;
148
- }, [dataInfo, resolvedSize, sizePhase, size]);
149
-
150
- const onScrollEnd = React.useCallback(() => {
151
- options.onScrollEnd?.();
152
- }, [options]);
144
+ const isReady = React.useCallback(() => {
145
+ const currentSize = resolvedSize.value ?? size;
146
+ return sizePhase.value === "ready" && currentSize > 0;
147
+ }, [resolvedSize, size, sizePhase]);
153
148
 
154
- const onScrollStart = React.useCallback(() => {
149
+ const emitStart = React.useCallback(() => {
150
+ startMovement();
155
151
  options.onScrollStart?.();
156
- }, [options]);
152
+ }, [options, startMovement]);
157
153
 
158
- const scrollWithTiming = React.useCallback(
159
- (toValue: number, onFinished?: () => void) => {
154
+ const emitSettle = React.useCallback(
155
+ (targetIndex?: number) => {
156
+ const nextSettledIndex = settle(targetIndex);
157
+ options.onMovementEnd?.(nextSettledIndex);
158
+ },
159
+ [options, settle]
160
+ );
161
+
162
+ const animateTo = React.useCallback(
163
+ (targetOffset: number, targetIndex: number, onFinished?: () => void) => {
160
164
  "worklet";
161
- const callback = (isFinished: boolean) => {
165
+ return dealWithAnimation(animation)(targetOffset, (finished) => {
162
166
  "worklet";
163
- if (isFinished) {
164
- scheduleOnRN(onScrollEnd);
165
- onFinished && scheduleOnRN(onFinished);
167
+ if (finished) {
168
+ scheduleOnRN(emitSettle, targetIndex);
169
+ if (onFinished) scheduleOnRN(onFinished);
170
+ } else {
171
+ scheduleOnRN(cancelMovement);
166
172
  }
167
- };
168
-
169
- const defaultWithAnimation: WithTimingAnimation = {
170
- type: "timing",
171
- config: { duration, easing: Easing.easeOutQuart },
172
- };
173
-
174
- return dealWithAnimation(withAnimation ?? defaultWithAnimation)(toValue, callback);
173
+ });
175
174
  },
176
- [duration, withAnimation, onScrollEnd]
175
+ [animation, cancelMovement, emitSettle]
177
176
  );
178
177
 
179
- const flattenedStyle = StyleSheet.flatten(style) || {};
180
-
181
- const next = React.useCallback(
182
- (opts: TCarouselActionOptions = {}) => {
178
+ const moveToPage = React.useCallback(
179
+ (targetPage: number, animated: boolean, onFinished?: () => void) => {
183
180
  "worklet";
184
- const { count = 1, animated = true, onFinished } = opts;
185
- if (!canSliding()) return;
186
-
187
- if (!loop) {
188
- const newIndex = index.value + count;
189
- const isOutOfBounds = newIndex > dataInfo.length - 1;
190
- if (isOutOfBounds) {
191
- return;
192
- }
193
- }
194
-
195
- /*
196
- [Overscroll Protection Logic]
197
-
198
- This section handles the overscroll protection when overscrollEnabled is false.
199
- It prevents scrolling beyond the visible content area.
200
-
201
- Example scenario:
202
- - Container width: 300px
203
- - Item width: 75px (4 items per view)
204
- - Total items: 6
205
-
206
- Initial state (index = 0):
207
- [0][1][2][3] | [4][5]
208
- visible | remaining
209
-
210
- After 2 slides (index = 2):
211
- [0][1] | [2][3][4][5]
212
- hidden | visible
213
-
214
- The visibleContentWidth calculation:
215
- - At index 2, remaining items = 4 (items 2,3,4,5)
216
- - visibleContentWidth = 4 * 75px = 300px
217
-
218
- If we try to slide again:
219
- - New visibleContentWidth would be: 2 * 75px = 150px (only items 4,5 remain)
220
- - Since 150px < container width (300px), the slide is prevented
221
-
222
- This ensures we don't scroll beyond the last set of fully visible items,
223
- maintaining a clean UX without partial item visibility at the edges.
224
- */
225
- // For overscroll calculation, use the intended item size, not the measured container size
226
- // In the new dynamic size system, the measured `size` could reflect the container rather than
227
- // each item, so prefer explicit width/height props and fall back to style-based dimensions.
228
- const styleWidth =
229
- typeof flattenedStyle.width === "number" ? flattenedStyle.width : undefined;
230
- const styleHeight =
231
- typeof flattenedStyle.height === "number" ? flattenedStyle.height : undefined;
232
- const propWidth = typeof width === "number" ? width : undefined;
233
- const propHeight = typeof height === "number" ? height : undefined;
234
-
235
- // Use the page size (derived from itemWidth/itemHeight) for overscroll calculations.
236
- // Fallback to container/style dimensions only if page size is unavailable.
237
- const pageSize =
238
- size > 0
239
- ? size
240
- : vertical
241
- ? (propHeight ?? styleHeight ?? 0)
242
- : (propWidth ?? styleWidth ?? 0);
243
-
244
- const visibleContentWidth = (dataInfo.length - index.value) * pageSize;
245
-
246
- // Get effective container width, with fallback for cases where containerSize
247
- // hasn't been updated yet (e.g., in tests or during initialization)
248
- const getEffectiveContainerWidth = () => {
249
- // 1. Use measured value if available
250
- if (containerSize.value.width > 0) {
251
- return containerSize.value.width;
252
- }
253
-
254
- // 2. Fallback to style width/height when no measurement available
255
- if (!vertical) {
256
- if (propWidth && propWidth > 0) {
257
- return propWidth;
258
- }
259
- if (styleWidth && styleWidth > 0) {
260
- return styleWidth;
261
- }
262
- }
263
- if (vertical) {
264
- if (propHeight && propHeight > 0) {
265
- return propHeight;
266
- }
267
- if (styleHeight && styleHeight > 0) {
268
- return styleHeight;
269
- }
270
- }
271
-
272
- // 3. Final fallback - assume multiple items are visible
273
- return pageSize * 3; // Assume 3 items per view as reasonable default
274
- };
275
-
276
- const effectiveContainerWidth = getEffectiveContainerWidth();
277
-
278
- if (!overscrollEnabled && effectiveContainerWidth > 0) {
279
- if (!(visibleContentWidth > effectiveContainerWidth)) {
280
- return;
281
- }
282
- }
283
-
284
- onScrollStart?.();
285
-
286
- const nextPage = currentFixedPage() + count;
287
- index.value = nextPage;
181
+ const targetRawIndex = positiveModulo(targetPage, rawDataLength);
182
+ emitStart();
183
+ index.value = positiveModulo(targetPage, Math.max(dataLength, 1));
288
184
 
185
+ const targetOffset = -targetPage * size;
289
186
  if (animated) {
290
- handlerOffset.value = scrollWithTiming(-nextPage * size, onFinished) as any;
187
+ handlerOffset.value = animateTo(targetOffset, targetRawIndex, onFinished);
291
188
  } else {
292
- handlerOffset.value = -nextPage * size;
189
+ handlerOffset.value = targetOffset;
190
+ emitSettle(targetRawIndex);
293
191
  onFinished?.();
294
192
  }
295
193
  },
296
- [
297
- canSliding,
298
- loop,
299
- index,
300
- dataInfo,
301
- onScrollStart,
302
- handlerOffset,
303
- size,
304
- scrollWithTiming,
305
- currentFixedPage,
306
- overscrollEnabled,
307
- containerSize,
308
- vertical,
309
- flattenedStyle,
310
- width,
311
- height,
312
- ]
194
+ [animateTo, dataLength, emitSettle, emitStart, handlerOffset, index, rawDataLength, size]
313
195
  );
314
196
 
315
- const prev = React.useCallback(
316
- (opts: TCarouselActionOptions = {}) => {
317
- const { count = 1, animated = true, onFinished } = opts;
318
- if (!canSliding()) return;
319
-
320
- if (!loop && index.value <= 0) return;
197
+ const validateCount = React.useCallback(
198
+ (command: "next" | "prev", count: number) => {
199
+ if (count === 0) return false;
200
+ if (Number.isInteger(count) && count > 0) return true;
321
201
 
322
- onScrollStart?.();
323
-
324
- const prevPage = currentFixedPage() - count;
325
- index.value = prevPage;
326
-
327
- if (animated) {
328
- handlerOffset.value = scrollWithTiming(-prevPage * size, onFinished);
329
- } else {
330
- handlerOffset.value = -prevPage * size;
331
- onFinished?.();
332
- }
202
+ warnOnce(
203
+ `${command}:count`,
204
+ `${command} count must be a positive integer; received ${String(count)}.`
205
+ );
206
+ return false;
333
207
  },
334
- [
335
- canSliding,
336
- loop,
337
- index,
338
- onScrollStart,
339
- handlerOffset,
340
- size,
341
- scrollWithTiming,
342
- currentFixedPage,
343
- ]
208
+ [warnOnce]
344
209
  );
345
210
 
346
- const to = React.useCallback(
347
- (opts: { i: number; animated: boolean; onFinished?: () => void }) => {
348
- const { i, animated = false, onFinished } = opts;
211
+ const next = React.useCallback(
212
+ (stepOptions: InternalCarouselStepOptions = {}) => {
213
+ "worklet";
214
+ const { animated = true, count = 1, onFinished } = stepOptions;
215
+ if (!canMove || !isReady() || !validateCount("next", count)) return;
349
216
 
350
- if (i === index.value) return;
217
+ const currentPage = currentVisualPage();
218
+ const targetPage = loop
219
+ ? currentPage + count
220
+ : Math.min(rawDataLength - 1, currentPage + count);
221
+ if (targetPage === currentPage) return;
351
222
 
352
- if (!canSliding()) return;
223
+ moveToPage(targetPage, animated, onFinished);
224
+ },
225
+ [canMove, currentVisualPage, isReady, loop, moveToPage, rawDataLength, validateCount]
226
+ );
353
227
 
354
- onScrollStart?.();
355
- let finalOffset: number;
228
+ const prev = React.useCallback(
229
+ (stepOptions: InternalCarouselStepOptions = {}) => {
230
+ "worklet";
231
+ const { animated = true, count = 1, onFinished } = stepOptions;
232
+ if (!canMove || !isReady() || !validateCount("prev", count)) return;
356
233
 
357
- if (!loop) {
358
- // Non-loop mode always uses direct page-to-offset mapping.
359
- // This avoids sign flips when moving to lower indices.
360
- finalOffset = -i * size;
361
- } else {
362
- // direction -> 1 | -1
363
- let direction: -1 | 1;
364
- if (fixedDirection === "positive") direction = 1;
365
- else if (fixedDirection === "negative") direction = -1;
366
- else direction = handlerOffsetDirection(handlerOffset);
367
-
368
- // target offset
369
- const offset = i * size * direction;
370
- // page width size * page count
371
- const totalSize = dataInfo.length * size;
372
- const isCloseToNextLoop = Math.abs(handlerOffset.value % totalSize) / totalSize >= 0.5;
373
-
374
- finalOffset =
375
- (Math.floor(Math.abs(handlerOffset.value / totalSize)) + (isCloseToNextLoop ? 1 : 0)) *
376
- totalSize *
377
- direction +
378
- offset;
379
- }
234
+ const currentPage = currentVisualPage();
235
+ const targetPage = loop ? currentPage - count : Math.max(0, currentPage - count);
236
+ if (targetPage === currentPage) return;
380
237
 
381
- if (animated) {
382
- index.value = i;
383
- handlerOffset.value = scrollWithTiming(finalOffset, onFinished);
384
- } else {
385
- handlerOffset.value = finalOffset;
386
- index.value = i;
387
- onFinished?.();
388
- }
238
+ moveToPage(targetPage, animated, onFinished);
389
239
  },
390
- [
391
- size,
392
- loop,
393
- index,
394
- fixedDirection,
395
- handlerOffset,
396
- dataInfo.length,
397
- canSliding,
398
- onScrollStart,
399
- scrollWithTiming,
400
- ]
240
+ [canMove, currentVisualPage, isReady, loop, moveToPage, validateCount]
401
241
  );
402
242
 
403
243
  const scrollTo = React.useCallback(
404
- (opts: TCarouselActionOptions = {}) => {
405
- const { index: i, count, animated = false, onFinished } = opts;
406
-
407
- if (typeof i === "number" && i > -1) {
408
- to({ i, animated, onFinished });
244
+ (scrollOptions: InternalCarouselScrollToOptions) => {
245
+ "worklet";
246
+ const { animated = true, index: targetIndex, onFinished } = scrollOptions;
247
+ if (!canMove || !isReady()) return;
248
+
249
+ if (!Number.isInteger(targetIndex) || targetIndex < 0 || targetIndex >= rawDataLength) {
250
+ warnOnce(
251
+ "scrollTo:index",
252
+ `scrollTo index must be an integer between 0 and ${rawDataLength - 1}; received ${String(targetIndex)}.`
253
+ );
409
254
  return;
410
255
  }
411
256
 
412
- if (!count) return;
413
-
414
- const n = Math.round(count);
415
-
416
- if (n < 0) prev({ count: Math.abs(n), animated, onFinished });
417
- else next({ count: n, animated, onFinished });
257
+ const currentPage = currentVisualPage();
258
+ const currentRawIndex = positiveModulo(currentPage, rawDataLength);
259
+ if (currentRawIndex === targetIndex) return;
260
+
261
+ const targetPage = loop
262
+ ? getShortestLoopTargetPage({
263
+ currentPage,
264
+ targetIndex,
265
+ count: rawDataLength,
266
+ })
267
+ : targetIndex;
268
+ moveToPage(targetPage, animated, onFinished);
418
269
  },
419
- [prev, next, to]
270
+ [canMove, currentVisualPage, isReady, loop, moveToPage, rawDataLength, warnOnce]
420
271
  );
421
272
 
422
273
  React.useImperativeHandle(
@@ -435,7 +286,10 @@ export function useCarouselController(options: IOpts): ICarouselController {
435
286
  prev,
436
287
  scrollTo,
437
288
  getCurrentIndex,
438
- getSharedIndex: () => sharedIndex.current,
289
+ getSharedIndex,
439
290
  index,
291
+ startMovement,
292
+ cancelMovement,
293
+ settle,
440
294
  };
441
295
  }