react-native-reanimated-carousel 4.0.0-alpha.0 → 4.0.0-alpha.10

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 (230) hide show
  1. package/README.md +22 -162
  2. package/lib/commonjs/components/BaseLayout.js +95 -0
  3. package/lib/commonjs/components/BaseLayout.js.map +1 -0
  4. package/lib/commonjs/components/Carousel.js +210 -0
  5. package/lib/commonjs/components/Carousel.js.map +1 -0
  6. package/lib/commonjs/components/ItemRenderer.js +80 -0
  7. package/lib/commonjs/components/ItemRenderer.js.map +1 -0
  8. package/lib/commonjs/components/LazyView.js +22 -0
  9. package/lib/commonjs/components/LazyView.js.map +1 -0
  10. package/lib/commonjs/components/ScrollViewGesture.js +315 -0
  11. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
  12. package/lib/commonjs/components/rnr-demo.test.js +45 -0
  13. package/lib/commonjs/components/rnr-demo.test.js.map +1 -0
  14. package/lib/commonjs/constants/index.js +21 -1
  15. package/lib/commonjs/constants/index.js.map +1 -1
  16. package/lib/commonjs/hooks/useAutoPlay.js +56 -1
  17. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
  18. package/lib/commonjs/hooks/useCarouselController.js +245 -1
  19. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  20. package/lib/commonjs/hooks/useCheckMounted.js +23 -1
  21. package/lib/commonjs/hooks/useCheckMounted.js.map +1 -1
  22. package/lib/commonjs/hooks/useCommonVariables.js +102 -1
  23. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
  24. package/lib/commonjs/hooks/useCommonVariables.test.js +38 -0
  25. package/lib/commonjs/hooks/useCommonVariables.test.js.map +1 -0
  26. package/lib/commonjs/hooks/useInitProps.js +78 -1
  27. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  28. package/lib/commonjs/hooks/useLayoutConfig.js +39 -1
  29. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
  30. package/lib/commonjs/hooks/useOffsetX.js +51 -1
  31. package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
  32. package/lib/commonjs/hooks/useOffsetX.test.js +53 -0
  33. package/lib/commonjs/hooks/useOffsetX.test.js.map +1 -0
  34. package/lib/commonjs/hooks/useOnProgressChange.js +38 -1
  35. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
  36. package/lib/commonjs/hooks/usePanGestureProxy.js +84 -0
  37. package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
  38. package/lib/commonjs/hooks/usePanGestureProxy.test.js +397 -0
  39. package/lib/commonjs/hooks/usePanGestureProxy.test.js.map +1 -0
  40. package/lib/commonjs/hooks/usePropsErrorBoundary.js +36 -1
  41. package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
  42. package/lib/commonjs/hooks/useUpdateGestureConfig.js +20 -0
  43. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
  44. package/lib/commonjs/hooks/useVisibleRanges.js +71 -1
  45. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
  46. package/lib/commonjs/hooks/useVisibleRanges.test.js +162 -0
  47. package/lib/commonjs/hooks/useVisibleRanges.test.js.map +1 -0
  48. package/lib/commonjs/index.js +13 -1
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/commonjs/layouts/index.js +20 -1
  51. package/lib/commonjs/layouts/index.js.map +1 -1
  52. package/lib/commonjs/layouts/normal.js +27 -1
  53. package/lib/commonjs/layouts/normal.js.map +1 -1
  54. package/lib/commonjs/layouts/parallax.js +38 -1
  55. package/lib/commonjs/layouts/parallax.js.map +1 -1
  56. package/lib/commonjs/layouts/stack.js +215 -1
  57. package/lib/commonjs/layouts/stack.js.map +1 -1
  58. package/lib/commonjs/store/index.js +14 -1
  59. package/lib/commonjs/store/index.js.map +1 -1
  60. package/lib/commonjs/types.js +5 -1
  61. package/lib/commonjs/utils/compute-offset-if-data-changed.js +52 -0
  62. package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +1 -0
  63. package/lib/commonjs/utils/compute-offset-if-data-changed.test.js +30 -0
  64. package/lib/commonjs/utils/compute-offset-if-data-changed.test.js.map +1 -0
  65. package/lib/commonjs/utils/compute-offset-if-size-changed.js +18 -0
  66. package/lib/commonjs/utils/compute-offset-if-size-changed.js.map +1 -0
  67. package/lib/commonjs/utils/compute-offset-if-size-changed.test.js +72 -0
  68. package/lib/commonjs/utils/compute-offset-if-size-changed.test.js.map +1 -0
  69. package/lib/commonjs/utils/computed-with-auto-fill-data.js +124 -0
  70. package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
  71. package/lib/commonjs/utils/deal-with-animation.js +21 -0
  72. package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
  73. package/lib/commonjs/utils/handleroffset-direction.js +16 -0
  74. package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
  75. package/lib/commonjs/utils/handleroffset-direction.test.js +46 -0
  76. package/lib/commonjs/utils/handleroffset-direction.test.js.map +1 -0
  77. package/lib/commonjs/utils/index.test.js +74 -0
  78. package/lib/commonjs/utils/index.test.js.map +1 -0
  79. package/lib/commonjs/utils/log.js +22 -1
  80. package/lib/commonjs/utils/log.js.map +1 -1
  81. package/lib/module/{layouts → components}/BaseLayout.js +6 -16
  82. package/lib/module/components/BaseLayout.js.map +1 -0
  83. package/lib/module/{Carousel.js → components/Carousel.js} +33 -52
  84. package/lib/module/components/Carousel.js.map +1 -0
  85. package/lib/module/components/ItemRenderer.js +62 -0
  86. package/lib/module/components/ItemRenderer.js.map +1 -0
  87. package/lib/module/{ScrollViewGesture.js → components/ScrollViewGesture.js} +59 -32
  88. package/lib/module/components/ScrollViewGesture.js.map +1 -0
  89. package/lib/module/components/rnr-demo.test.js +33 -0
  90. package/lib/module/components/rnr-demo.test.js.map +1 -0
  91. package/lib/module/hooks/useCarouselController.js +15 -14
  92. package/lib/module/hooks/useCarouselController.js.map +1 -1
  93. package/lib/module/hooks/useCommonVariables.js +39 -9
  94. package/lib/module/hooks/useCommonVariables.js.map +1 -1
  95. package/lib/module/hooks/useCommonVariables.test.js +34 -0
  96. package/lib/module/hooks/useCommonVariables.test.js.map +1 -0
  97. package/lib/module/hooks/useInitProps.js +1 -3
  98. package/lib/module/hooks/useInitProps.js.map +1 -1
  99. package/lib/module/hooks/useLayoutConfig.js.map +1 -1
  100. package/lib/module/hooks/useOffsetX.js +9 -6
  101. package/lib/module/hooks/useOffsetX.js.map +1 -1
  102. package/lib/module/hooks/useOffsetX.test.js +48 -0
  103. package/lib/module/hooks/useOffsetX.test.js.map +1 -0
  104. package/lib/module/hooks/useOnProgressChange.js +1 -1
  105. package/lib/module/hooks/useOnProgressChange.js.map +1 -1
  106. package/lib/module/hooks/usePanGestureProxy.js +71 -0
  107. package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
  108. package/lib/module/hooks/usePanGestureProxy.test.js +383 -0
  109. package/lib/module/hooks/usePanGestureProxy.test.js.map +1 -0
  110. package/lib/module/hooks/useUpdateGestureConfig.js +10 -0
  111. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
  112. package/lib/module/hooks/useVisibleRanges.js +47 -19
  113. package/lib/module/hooks/useVisibleRanges.js.map +1 -1
  114. package/lib/module/hooks/useVisibleRanges.test.js +157 -0
  115. package/lib/module/hooks/useVisibleRanges.test.js.map +1 -0
  116. package/lib/module/index.js +1 -2
  117. package/lib/module/index.js.map +1 -1
  118. package/lib/module/{hooks/computeNewIndexWhenDataChanges.js → utils/compute-offset-if-data-changed.js} +2 -2
  119. package/lib/module/utils/compute-offset-if-data-changed.js.map +1 -0
  120. package/lib/module/utils/compute-offset-if-data-changed.test.js +27 -0
  121. package/lib/module/utils/compute-offset-if-data-changed.test.js.map +1 -0
  122. package/lib/module/utils/compute-offset-if-size-changed.js +11 -0
  123. package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -0
  124. package/lib/module/utils/compute-offset-if-size-changed.test.js +69 -0
  125. package/lib/module/utils/compute-offset-if-size-changed.test.js.map +1 -0
  126. package/lib/module/utils/{computedWithAutoFillData.js → computed-with-auto-fill-data.js} +1 -1
  127. package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
  128. package/lib/module/utils/{dealWithAnimation.js → deal-with-animation.js} +1 -1
  129. package/lib/module/utils/deal-with-animation.js.map +1 -0
  130. package/lib/module/utils/handleroffset-direction.js +9 -0
  131. package/lib/module/utils/handleroffset-direction.js.map +1 -0
  132. package/lib/module/utils/handleroffset-direction.test.js +41 -0
  133. package/lib/module/utils/handleroffset-direction.test.js.map +1 -0
  134. package/lib/module/{hooks → utils}/index.test.js +6 -6
  135. package/lib/module/utils/index.test.js.map +1 -0
  136. package/lib/typescript/{Carousel.d.ts → components/Carousel.d.ts} +1 -1
  137. package/lib/typescript/components/ItemRenderer.d.ts +22 -0
  138. package/lib/typescript/{ScrollViewGesture.d.ts → components/ScrollViewGesture.d.ts} +1 -1
  139. package/lib/typescript/hooks/useCarouselController.d.ts +3 -2
  140. package/lib/typescript/hooks/useCommonVariables.test.d.ts +1 -0
  141. package/lib/typescript/hooks/useLayoutConfig.d.ts +1 -1
  142. package/lib/typescript/hooks/useOffsetX.test.d.ts +1 -0
  143. package/lib/typescript/hooks/usePanGestureProxy.d.ts +9 -0
  144. package/lib/typescript/hooks/usePanGestureProxy.test.d.ts +1 -0
  145. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +5 -0
  146. package/lib/typescript/hooks/useVisibleRanges.d.ts +8 -4
  147. package/lib/typescript/hooks/useVisibleRanges.test.d.ts +1 -0
  148. package/lib/typescript/index.d.ts +3 -2
  149. package/lib/typescript/types.d.ts +113 -104
  150. package/lib/typescript/{hooks/computeNewIndexWhenDataChanges.d.ts → utils/compute-offset-if-data-changed.d.ts} +1 -1
  151. package/lib/typescript/utils/compute-offset-if-data-changed.test.d.ts +1 -0
  152. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts +5 -0
  153. package/lib/typescript/utils/compute-offset-if-size-changed.test.d.ts +1 -0
  154. package/lib/typescript/utils/handleroffset-direction.d.ts +3 -0
  155. package/lib/typescript/utils/handleroffset-direction.test.d.ts +1 -0
  156. package/lib/typescript/utils/index.test.d.ts +1 -0
  157. package/package.json +32 -73
  158. package/src/{layouts → components}/BaseLayout.tsx +7 -35
  159. package/src/{Carousel.tsx → components/Carousel.tsx} +35 -69
  160. package/src/components/ItemRenderer.tsx +105 -0
  161. package/src/{ScrollViewGesture.tsx → components/ScrollViewGesture.tsx} +88 -48
  162. package/src/components/rnr-demo.test.tsx +43 -0
  163. package/src/hooks/useCarouselController.tsx +27 -24
  164. package/src/hooks/useCommonVariables.test.tsx +41 -0
  165. package/src/hooks/useCommonVariables.ts +36 -11
  166. package/src/hooks/useInitProps.ts +1 -3
  167. package/src/hooks/useLayoutConfig.ts +1 -1
  168. package/src/hooks/useOffsetX.test.ts +54 -0
  169. package/src/hooks/useOffsetX.ts +33 -31
  170. package/src/hooks/useOnProgressChange.ts +1 -1
  171. package/src/hooks/usePanGestureProxy.test.tsx +376 -0
  172. package/src/hooks/usePanGestureProxy.ts +110 -0
  173. package/src/hooks/useUpdateGestureConfig.ts +15 -0
  174. package/src/hooks/useVisibleRanges.test.tsx +179 -0
  175. package/src/hooks/useVisibleRanges.tsx +72 -24
  176. package/src/index.tsx +4 -2
  177. package/src/types.ts +132 -125
  178. package/src/utils/compute-offset-if-data-changed.test.ts +30 -0
  179. package/src/{hooks/computeNewIndexWhenDataChanges.ts → utils/compute-offset-if-data-changed.ts} +1 -1
  180. package/src/utils/compute-offset-if-size-changed.test.ts +78 -0
  181. package/src/utils/compute-offset-if-size-changed.ts +11 -0
  182. package/src/utils/handleroffset-direction.test.ts +52 -0
  183. package/src/utils/handleroffset-direction.ts +18 -0
  184. package/src/{hooks → utils}/index.test.ts +6 -6
  185. package/README.zh-CN.md +0 -202
  186. package/lib/commonjs/Carousel.js +0 -2
  187. package/lib/commonjs/Carousel.js.map +0 -1
  188. package/lib/commonjs/LazyView.js +0 -2
  189. package/lib/commonjs/LazyView.js.map +0 -1
  190. package/lib/commonjs/ScrollViewGesture.js +0 -2
  191. package/lib/commonjs/ScrollViewGesture.js.map +0 -1
  192. package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js +0 -2
  193. package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
  194. package/lib/commonjs/hooks/index.test.js +0 -2
  195. package/lib/commonjs/hooks/index.test.js.map +0 -1
  196. package/lib/commonjs/layouts/BaseLayout.js +0 -2
  197. package/lib/commonjs/layouts/BaseLayout.js.map +0 -1
  198. package/lib/commonjs/layouts/ParallaxLayout.js +0 -2
  199. package/lib/commonjs/layouts/ParallaxLayout.js.map +0 -1
  200. package/lib/commonjs/utils/computedWithAutoFillData.js +0 -2
  201. package/lib/commonjs/utils/computedWithAutoFillData.js.map +0 -1
  202. package/lib/commonjs/utils/dealWithAnimation.js +0 -2
  203. package/lib/commonjs/utils/dealWithAnimation.js.map +0 -1
  204. package/lib/commonjs/utils/handlerOffsetDirection.js +0 -2
  205. package/lib/commonjs/utils/handlerOffsetDirection.js.map +0 -1
  206. package/lib/module/Carousel.js.map +0 -1
  207. package/lib/module/ScrollViewGesture.js.map +0 -1
  208. package/lib/module/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
  209. package/lib/module/hooks/index.test.js.map +0 -1
  210. package/lib/module/layouts/BaseLayout.js.map +0 -1
  211. package/lib/module/layouts/ParallaxLayout.js +0 -61
  212. package/lib/module/layouts/ParallaxLayout.js.map +0 -1
  213. package/lib/module/utils/computedWithAutoFillData.js.map +0 -1
  214. package/lib/module/utils/dealWithAnimation.js.map +0 -1
  215. package/lib/module/utils/handlerOffsetDirection.js +0 -9
  216. package/lib/module/utils/handlerOffsetDirection.js.map +0 -1
  217. package/lib/typescript/layouts/ParallaxLayout.d.ts +0 -13
  218. package/lib/typescript/utils/handlerOffsetDirection.d.ts +0 -2
  219. package/src/layouts/ParallaxLayout.tsx +0 -141
  220. package/src/utils/handlerOffsetDirection.ts +0 -15
  221. /package/lib/module/{LazyView.js → components/LazyView.js} +0 -0
  222. /package/lib/module/{LazyView.js.map → components/LazyView.js.map} +0 -0
  223. /package/lib/typescript/{layouts → components}/BaseLayout.d.ts +0 -0
  224. /package/lib/typescript/{LazyView.d.ts → components/LazyView.d.ts} +0 -0
  225. /package/lib/typescript/{hooks/index.test.d.ts → components/rnr-demo.test.d.ts} +0 -0
  226. /package/lib/typescript/utils/{computedWithAutoFillData.d.ts → computed-with-auto-fill-data.d.ts} +0 -0
  227. /package/lib/typescript/utils/{dealWithAnimation.d.ts → deal-with-animation.d.ts} +0 -0
  228. /package/src/{LazyView.tsx → components/LazyView.tsx} +0 -0
  229. /package/src/utils/{computedWithAutoFillData.ts → computed-with-auto-fill-data.ts} +0 -0
  230. /package/src/utils/{dealWithAnimation.ts → deal-with-animation.ts} +0 -0
package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- English | [简体中文](./README.zh-CN.md)
2
-
3
1
  # react-native-reanimated-carousel
4
2
 
5
3
  <img src="assets/home-banner.png" width="100%"/>
@@ -13,186 +11,48 @@ English | [简体中文](./README.zh-CN.md)
13
11
  [![github closed issues](https://img.shields.io/github/issues-closed/dohooo/react-native-reanimated-carousel.svg?style=flat-square&colorB=44cc11)](https://github.com/dohooo/react-native-reanimated-carousel/issues?q=is%3Aissue+is%3Aclosed)
14
12
  [![discord chat](https://img.shields.io/badge/chat-discord-blue?style=flat&logo=discord)](https://discord.gg/KsXRuDs43y)
15
13
 
16
- ## ReactNative community's best use of the carousel component! 🎉🎉🎉
14
+ ## The best carousel component in React Native community. ⚡️
15
+
16
+ - **It completely solved this** [problem](https://github.com/meliorence/react-native-snap-carousel/issues/632) **for `react-native-snap-carousel`**
17
+ - **Fully implemented using Reanimated 2&3**
18
+ - **[Demo](https://dohooo.github.io/react-native-reanimated-carousel/)**
17
19
 
18
- - **It completely solves this** [[problem]](https://github.com/meliorence/react-native-snap-carousel/issues/632) **for `react-native-snap-carousel`!**
19
- - **Simple**, **Infinitely scrolling very smooth**, **Fully implemented using Reanimated 2!**
20
+ ## Getting Started
20
21
 
21
- > V2 has been released! Join it! [[v1 docs]](https://github.com/dohooo/react-native-reanimated-carousel/tree/v1.x.x)
22
+ Check out [the documentation website](https://reanimated-carousel.dev).
22
23
 
23
- > Support to Web [[demo]](https://dohooo.github.io/react-native-reanimated-carousel/)
24
+ ## Examples
24
25
 
25
- > Click on the image to see the code snippets. [[Try it]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
26
+ > Click on the image to see the code snippets [[Try it]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
26
27
 
27
28
  | <img src="assets/normal-horizontal.gif"/> | <img src="assets/normal-vertical.gif"/> | <img src="assets/parallax-horizontal.gif"/> |
28
29
  | :------------------------------------------------------------------: | :-------------------------------------------------------------------: | :--------------------------------------------------------------------: |
29
- | <a href="./exampleExpo/src/pages/normal/index.tsx">normal-horizontal</a> | <a href="./exampleExpo/src/pages/normal/index.tsx">normal-vertical</a> | <a href="./exampleExpo/src/pages/parallax/index.tsx">parallax-horizontal</a> |
30
+ | <a href="./example/app/src/pages/normal/index.tsx">normal-horizontal</a> | <a href="./example/app/src/pages/normal/index.tsx">normal-vertical</a> | <a href="./example/app/src/pages/parallax/index.tsx">parallax-horizontal</a> |
30
31
  | <img src="assets/parallax-vertical.gif"/> | <img src="assets/stack-horizontal-left.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
31
- | <a href="./exampleExpo/src/pages/parallax/index.tsx">parallax-vertical</a> | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-horizontal-left</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-right</a> |
32
+ | <a href="./example/app/src/pages/parallax/index.tsx">parallax-vertical</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-left</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-right</a> |
32
33
  | <img src="assets/stack-vertical-left.gif"/> | <img src="assets/stack-vertical-right.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
33
- | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-vertical-left</a> | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-vertical-right</a> | <a href="./exampleExpo/src/stack/index.tsx">stack-horizontal-right</a> |
34
- | <img src="assets/left-align.gif"/> |
35
- | <a href="./exampleExpo/src/pages/left-align/index.tsx">left-align</a> |
34
+ | <a href="./example/app/src/pages/stack/index.tsx">stack-vertical-left</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-vertical-right</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-right</a> |
35
+ | <img src="assets/left-align.gif"/> | | <img src="assets/right-align.gif" > |
36
+ | <a href="./example/app/src/pages/left-align/index.tsx">left-align</a> | | <a href="./example/app/src/pages/right-align/index.tsx">right-align</a> |
36
37
 
37
-
38
- > Now you can make cool animations with us! Very easy! [[Details]](./docs/custom-animation.md)
38
+ > You can make cool animations with custom animation API [[Details]](https://reanimated-carousel.dev/custom-animations)
39
39
 
40
40
  | <img src="assets/advanced-parallax.gif"/> | <img src="assets/pause-advanced-parallax.gif"/> | <img src="assets/scale-fade-in-out.gif"/> |
41
41
  | :-----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------: |
42
- | <a href="./exampleExpo/src/pages/advanced-parallax/index.tsx">advanced-parallax</a> | <a href="./exampleExpo/src/pages/pause-advanced-parallax/index.tsx">pause-advanced-parallax</a> | <a href="./exampleExpo/src/pages/scale-fade-in-out/index.tsx">scale-fade-in-out</a> |
42
+ | <a href="./example/app/src/pages/advanced-parallax/index.tsx">advanced-parallax</a> | <a href="./example/app/src/pages/pause-advanced-parallax/index.tsx">pause-advanced-parallax</a> | <a href="./example/app/src/pages/scale-fade-in-out/index.tsx">scale-fade-in-out</a> |
43
43
  | <img src="assets/rotate-scale-fade-in-out.gif"/> | <img src="assets/rotate-in-out.gif"/> | <img src="assets/anim-tab-bar.gif"/> |
44
- | <a href="./exampleExpo/src/pages/rotate-scale-fade-in-out/index.tsx">rotate-scale-fade-in-out</a> | <a href="./exampleExpo/src/rotate-in-out/index.tsx">rotate-in-out</a> | <a href="./exampleExpo/src/pages/anim-tab-bar/index.tsx">anim-tab-bar</a> |
44
+ | <a href="./example/app/src/pages/rotate-scale-fade-in-out/index.tsx">rotate-scale-fade-in-out</a> | <a href="./example/app/src/pages/rotate-in-out/index.tsx">rotate-in-out</a> | <a href="./example/app/src/pages/anim-tab-bar/index.tsx">anim-tab-bar</a> |
45
45
  | <img src="assets/marquee.gif"/> | <img src="assets/multiple.gif"/> | <img src="assets/circular.gif"/> |
46
- | <a href="./exampleExpo/src/pages/marquee/index.tsx">marquee</a> | <a href="./exampleExpo/src/pages/multiple/index.tsx">multiple</a> | <a href="./exampleExpo/src/pages/circular/index.tsx">circular</a> |
46
+ | <a href="./example/app/src/pages/marquee/index.tsx">marquee</a> | <a href="./example/app/src/pages/multiple/index.tsx">multiple</a> | <a href="./example/app/src/pages/circular/index.tsx">circular</a> |
47
47
  | <img src="assets/fold.gif"/> | <img src="assets/tear.gif"/> | <img src="assets/press-swipe.gif"/> |
48
- | <a href="./exampleExpo/src/pages/fold/index.tsx">fold</a> | <a href="./exampleExpo/src/tear/index.tsx">tear</a> | <a href="./exampleExpo/src/pages/press-swipe/index.tsx">press-swipe</a> |
48
+ | <a href="./example/app/src/pages/fold/index.tsx">fold</a> | <a href="./example/app/src/pages/tear/index.tsx">tear</a> | <a href="./example/app/src/pages/press-swipe/index.tsx">press-swipe</a> |
49
49
  | <img src="assets/cube-3d.gif"/> | <img src="assets/blur-parallax.gif"/> | <img src="assets/curve.gif"/> |
50
- | <a href="./exampleExpo/src/pages/cube-3d/index.tsx">cube-3d</a> | <a href="./exampleExpo/src/pages/blur-parallax/index.tsx">blur-parallax</a> | <a href="./exampleExpo/src/pages/curve/index.tsx">curve</a> |
50
+ | <a href="./example/app/src/pages/cube-3d/index.tsx">cube-3d</a> | <a href="./example/app/src/pages/blur-parallax/index.tsx">blur-parallax</a> | <a href="./example/app/src/pages/curve/index.tsx">curve</a> |
51
51
  | <img src="assets/parallax-layers.gif"/> | <img src="assets/stack-cards.gif"/> | <img src="assets/flow.gif"/> |
52
- | <a href="./exampleExpo/src/pages/parallax-layers/index.tsx">parallax-layers</a> | <a href="./exampleExpo/src/stack-cards/index.tsx">stack-cards</a> | <a href="./exampleExpo/src/pages/flow/index.tsx">flow</a> |
52
+ | <a href="./example/app/src/pages/parallax-layers/index.tsx">parallax-layers</a> | <a href="./example/app/src/pages/stack-cards/index.tsx">stack-cards</a> | <a href="./example/app/src/pages/flow/index.tsx">flow</a> |
53
53
  | <img src="assets/blur-rotate.gif"/> | ||
54
- | <a href="./exampleExpo/src/pages/blur-rotate/index.tsx">blur-rotate</a> | | |
55
-
56
- ## Table of contents
57
-
58
- 1. [Installation](#Installation)
59
- 1. [Usage](#Usage)
60
- 1. [Props](./docs/props.md)
61
- 1. [Tips](#Tips)
62
- 1. [Reason](#Reason)
63
- 1. [Example](#Example)
64
-
65
- ## Installation
66
-
67
- Open a Terminal in the project root and run:
68
-
69
- ```sh
70
- yarn add react-native-reanimated-carousel
71
- ```
72
-
73
- Or if you use npm:
74
-
75
- ```sh
76
- npm install react-native-reanimated-carousel
77
- ```
78
-
79
- Now we need to install [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) and [`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated).
80
-
81
- | | react-native-reanimated | react-native-gesture-handler |
82
- | -------------------------------------- | ----------------------- | ---------------------------- |
83
- | react-native-reanimated-carousel v1、v2 | >=2.0 & <2.7.0 | <2.9.0 |
84
- | react-native-reanimated-carousel v3 | >=2.7.0 & < 3.x | <2.9.0 |
85
- | react-native-reanimated-carousel v4 | >=3.x | >=2.9.0 |
86
-
87
- ## Usage
88
-
89
- ```tsx
90
- import * as React from 'react';
91
- import { Dimensions, Text, View } from 'react-native';
92
- import Carousel from 'react-native-reanimated-carousel';
93
-
94
- function Index() {
95
- const width = Dimensions.get('window').width;
96
- return (
97
- <View style={{ flex: 1 }}>
98
- <Carousel
99
- loop
100
- width={width}
101
- height={width / 2}
102
- autoPlay={true}
103
- data={[...new Array(6).keys()]}
104
- scrollAnimationDuration={1000}
105
- onSnapToItem={(index) => console.log('current index:', index)}
106
- renderItem={({ index }) => (
107
- <View
108
- style={{
109
- flex: 1,
110
- borderWidth: 1,
111
- justifyContent: 'center',
112
- }}
113
- >
114
- <Text style={{ textAlign: 'center', fontSize: 30 }}>
115
- {index}
116
- </Text>
117
- </View>
118
- )}
119
- />
120
- </View>
121
- );
122
- }
123
-
124
- export default Index;
125
-
126
- ```
127
-
128
- ## Tips
129
-
130
- - Optimizing
131
-
132
- - When rendering a large number of elements, you can use the 'windowSize' property to control how many items of the current element are rendered. The default is full rendering. After testing without this property, frames will drop when rendering 200 empty views. After setting this property, rendering 1000 empty views is still smooth. (The specific number depends on the phone model tested)
133
-
134
- - Used in `ScrollView/FlatList`
135
-
136
- - **[#143](https://github.com/dohooo/react-native-reanimated-carousel/issues/143) - Carousel suppresses ScrollView/FlatList scroll gesture handler:** When using a carousel with a layout oriented to only one direction (vertical/horizontal) and inside a ScrollView/FlatList, it is important for the user experience that the unused axis does not impede the scroll of the list. So that, for example, the x-axis is free we can change the [activeOffsetX](https://docs.swmansion.com/react-native-gesture-handler/docs/1.10.3/api/gesture-handlers/pan-gh/#activeoffsetx) of the gesture handler:
137
-
138
- ```tsx
139
- <Carousel
140
- {...}
141
- panGestureHandlerProps={{
142
- activeOffsetX: [-10, 10],
143
- }}
144
- />
145
- ```
146
-
147
- - RTL
148
- - Support to RTL mode with no more configuration needed. But in RTL mode, need to manually set the autoPlayReverse props for autoplay to control scrolling direction.
149
- - EXPO
150
- - If use EXPO managed workflow please ensure that the version is greater than 41.Because the old version not support `Reanimated(v2)`.
151
- - Working principle
152
- - [About RNRC](./docs/about.md)
153
-
154
- - How to run tests in `exampleExpo`
155
- ```shell
156
- $ yarn prepare
157
- $ yarn link --global
158
- $ cd ./exampleExpo
159
- $ yarn link react-native-reanimated-carousel --global
160
- $ yarn test
161
- ```
162
-
163
- ## Reason
164
-
165
- <details>
166
- <summary>The common RN infinite scroll component. It get stuck on a fast slide. Wait for the next element to appear. This component will not have similar problems.Because using a completely different approach so the best performance is achieved.That's why this library was created.</summary>
167
- <p align="center">
168
- Use react-native-snap-carousel for quick swiping,you can see caton clearly when you reach the junction.(gif 4.6mb)
169
- </p>
170
- <p align="center">
171
- <img src="assets/react-native-snap-carousel.gif" width="50%"/>
172
- </p>
173
-
174
- <p align="center">
175
- Compared with react-native-reanimated-carousel,The actual test was ten slides per second, but it didn't show up very well in gif.
176
- </p>
177
- <p align="center">
178
- <img src="assets/normal-fast.gif" width="50%"/>
179
- </p>
180
- </details>
181
-
182
- ## Example
183
-
184
- > `:pretty` use pretty images
185
-
186
- ```shell
187
- yarn ios
188
- yarn ios:pretty
189
-
190
- yarn android
191
- yarn android:pretty
54
+ | <a href="./example/app/src/pages/blur-rotate/index.tsx">blur-rotate</a> | | |
192
55
 
193
- yarn web
194
- yarn web:pretty
195
- ```
196
56
 
197
57
  ## Sponsors
198
58
 
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.BaseLayout = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
11
+
12
+ var _useOffsetX = require("../hooks/useOffsetX");
13
+
14
+ var _store = require("../store");
15
+
16
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
+
18
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+
22
+ const BaseLayout = props => {
23
+ const {
24
+ handlerOffset,
25
+ index,
26
+ children,
27
+ visibleRanges,
28
+ animationStyle
29
+ } = props;
30
+
31
+ const context = _react.default.useContext(_store.CTX);
32
+
33
+ const {
34
+ props: {
35
+ loop,
36
+ dataLength,
37
+ width,
38
+ height,
39
+ vertical,
40
+ customConfig,
41
+ mode,
42
+ modeConfig
43
+ }
44
+ } = context;
45
+ const size = vertical ? height : width;
46
+ let offsetXConfig = {
47
+ handlerOffset,
48
+ index,
49
+ size,
50
+ dataLength,
51
+ loop,
52
+ ...(typeof customConfig === "function" ? customConfig() : {})
53
+ };
54
+
55
+ if (mode === "horizontal-stack") {
56
+ const {
57
+ snapDirection,
58
+ showLength
59
+ } = modeConfig;
60
+ offsetXConfig = {
61
+ handlerOffset,
62
+ index,
63
+ size,
64
+ dataLength,
65
+ loop,
66
+ type: snapDirection === "right" ? "negative" : "positive",
67
+ viewCount: showLength
68
+ };
69
+ }
70
+
71
+ const x = (0, _useOffsetX.useOffsetX)(offsetXConfig, visibleRanges);
72
+ const animationValue = (0, _reactNativeReanimated.useDerivedValue)(() => x.value / size, [x, size]);
73
+ const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
74
+ return animationStyle(x.value / size);
75
+ }, [animationStyle]);
76
+ return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
77
+ style: [{
78
+ width: width || "100%",
79
+ height: height || "100%",
80
+ position: "absolute"
81
+ }, animatedStyle]
82
+ /**
83
+ * We use this testID to know when the carousel item is ready to be tested in test.
84
+ * e.g.
85
+ * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.
86
+ * */
87
+ ,
88
+ testID: `__CAROUSEL_ITEM_${index}__`
89
+ }, children({
90
+ animationValue
91
+ }));
92
+ };
93
+
94
+ exports.BaseLayout = BaseLayout;
95
+ //# sourceMappingURL=BaseLayout.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","handlerOffset","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","position"],"mappings":";;;;;;;AAAA;;AAGA;;AAMA;;AAGA;;;;;;;;AAIO,MAAMA,UAQX,GAAIC,KAAD,IAAW;AACd,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,KAAjB;AAAwBC,IAAAA,QAAxB;AAAkCC,IAAAA,aAAlC;AAAiDC,IAAAA;AAAjD,MACFL,KADJ;;AAGA,QAAMM,OAAO,GAAGC,eAAMC,UAAN,CAAiBC,UAAjB,CAAhB;;AACA,QAAM;AACJT,IAAAA,KAAK,EAAE;AACLU,MAAAA,IADK;AAELC,MAAAA,UAFK;AAGLC,MAAAA,KAHK;AAILC,MAAAA,MAJK;AAKLC,MAAAA,QALK;AAMLC,MAAAA,YANK;AAOLC,MAAAA,IAPK;AAQLC,MAAAA;AARK;AADH,MAWFX,OAXJ;AAYA,QAAMY,IAAI,GAAGJ,QAAQ,GAAGD,MAAH,GAAYD,KAAjC;AAEA,MAAIO,aAAoB,GAAG;AACzBlB,IAAAA,aADyB;AAEzBC,IAAAA,KAFyB;AAGzBgB,IAAAA,IAHyB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react-native\";\nimport type { AnimatedStyleProp } from \"react-native-reanimated\";\nimport Animated, {\n useAnimatedStyle,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { IOpts } from \"../hooks/useOffsetX\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport type { ILayoutConfig } from \"../layouts/stack\";\nimport { CTX } from \"../store\";\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number\n handlerOffset: Animated.SharedValue<number>\n visibleRanges: IVisibleRanges\n animationStyle: TAnimationStyle\n children: (ctx: {\n animationValue: Animated.SharedValue<number>\n }) => React.ReactElement\n}> = (props) => {\n const { handlerOffset, index, children, visibleRanges, animationStyle }\n = props;\n\n const context = React.useContext(CTX);\n const {\n props: {\n loop,\n dataLength,\n width,\n height,\n vertical,\n customConfig,\n mode,\n modeConfig,\n },\n } = context;\n const size = vertical ? height : width;\n\n let offsetXConfig: IOpts = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n ...(typeof customConfig === \"function\" ? customConfig() : {}),\n };\n\n if (mode === \"horizontal-stack\") {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n type: snapDirection === \"right\" ? \"negative\" : \"positive\",\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n () => {\n return animationStyle(x.value / size);\n },\n [animationStyle],\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || \"100%\",\n height: height || \"100%\",\n position: \"absolute\",\n },\n animatedStyle,\n ]}\n /**\n * We use this testID to know when the carousel item is ready to be tested in test.\n * e.g.\n * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.\n * */\n testID={`__CAROUSEL_ITEM_${index}__`}\n >\n {children({ animationValue })}\n </Animated.View>\n );\n};\n"]}
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _reactNative = require("react-native");
11
+
12
+ var _reactNativeGestureHandler = require("react-native-gesture-handler");
13
+
14
+ var _reactNativeReanimated = require("react-native-reanimated");
15
+
16
+ var _ItemRenderer = require("./ItemRenderer");
17
+
18
+ var _ScrollViewGesture = require("./ScrollViewGesture");
19
+
20
+ var _useAutoPlay = require("../hooks/useAutoPlay");
21
+
22
+ var _useCarouselController = require("../hooks/useCarouselController");
23
+
24
+ var _useCommonVariables = require("../hooks/useCommonVariables");
25
+
26
+ var _useInitProps = require("../hooks/useInitProps");
27
+
28
+ var _useLayoutConfig = require("../hooks/useLayoutConfig");
29
+
30
+ var _useOnProgressChange = require("../hooks/useOnProgressChange");
31
+
32
+ var _usePropsErrorBoundary = require("../hooks/usePropsErrorBoundary");
33
+
34
+ var _store = require("../store");
35
+
36
+ var _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
37
+
38
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
39
+
40
+ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
41
+ const props = (0, _useInitProps.useInitProps)(_props);
42
+ const {
43
+ testID,
44
+ loop,
45
+ autoFillData,
46
+ // Fill data with autoFillData
47
+ data,
48
+ // Length of fill data
49
+ dataLength,
50
+ // Length of raw data
51
+ rawDataLength,
52
+ mode,
53
+ style,
54
+ width,
55
+ height,
56
+ vertical,
57
+ autoPlay,
58
+ windowSize,
59
+ autoPlayReverse,
60
+ autoPlayInterval,
61
+ scrollAnimationDuration,
62
+ withAnimation,
63
+ fixedDirection,
64
+ renderItem,
65
+ onScrollEnd,
66
+ onSnapToItem,
67
+ onScrollStart,
68
+ onProgressChange,
69
+ customAnimation,
70
+ defaultIndex
71
+ } = props;
72
+ const commonVariables = (0, _useCommonVariables.useCommonVariables)(props);
73
+ const {
74
+ size,
75
+ handlerOffset
76
+ } = commonVariables;
77
+ const offsetX = (0, _reactNativeReanimated.useDerivedValue)(() => {
78
+ const totalSize = size * dataLength;
79
+ const x = handlerOffset.value % totalSize;
80
+ if (!loop) return handlerOffset.value;
81
+ return isNaN(x) ? 0 : x;
82
+ }, [loop, size, dataLength]);
83
+ (0, _usePropsErrorBoundary.usePropsErrorBoundary)({ ...props,
84
+ dataLength
85
+ });
86
+ (0, _useOnProgressChange.useOnProgressChange)({
87
+ autoFillData,
88
+ loop,
89
+ size,
90
+ offsetX,
91
+ rawDataLength,
92
+ onProgressChange
93
+ });
94
+ const carouselController = (0, _useCarouselController.useCarouselController)({
95
+ loop,
96
+ size,
97
+ dataLength,
98
+ autoFillData,
99
+ handlerOffset,
100
+ withAnimation,
101
+ defaultIndex,
102
+ fixedDirection,
103
+ duration: scrollAnimationDuration,
104
+ onScrollEnd: () => (0, _reactNativeReanimated.runOnJS)(_onScrollEnd)(),
105
+ onScrollStart: () => !!onScrollStart && (0, _reactNativeReanimated.runOnJS)(onScrollStart)()
106
+ });
107
+ const {
108
+ next,
109
+ prev,
110
+ scrollTo,
111
+ getSharedIndex,
112
+ getCurrentIndex
113
+ } = carouselController;
114
+ const {
115
+ start: startAutoPlay,
116
+ pause: pauseAutoPlay
117
+ } = (0, _useAutoPlay.useAutoPlay)({
118
+ autoPlay,
119
+ autoPlayInterval,
120
+ autoPlayReverse,
121
+ carouselController
122
+ });
123
+
124
+ const _onScrollEnd = _react.default.useCallback(() => {
125
+ const _sharedIndex = Math.round(getSharedIndex());
126
+
127
+ const realIndex = (0, _computedWithAutoFillData.computedRealIndexWithAutoFillData)({
128
+ index: _sharedIndex,
129
+ dataLength: rawDataLength,
130
+ loop,
131
+ autoFillData
132
+ });
133
+ if (onSnapToItem) onSnapToItem(realIndex);
134
+ if (onScrollEnd) onScrollEnd(realIndex);
135
+ }, [loop, autoFillData, rawDataLength, getSharedIndex, onSnapToItem, onScrollEnd]);
136
+
137
+ const scrollViewGestureOnScrollStart = _react.default.useCallback(() => {
138
+ pauseAutoPlay();
139
+ onScrollStart === null || onScrollStart === void 0 ? void 0 : onScrollStart();
140
+ }, [onScrollStart, pauseAutoPlay]);
141
+
142
+ const scrollViewGestureOnScrollEnd = _react.default.useCallback(() => {
143
+ startAutoPlay();
144
+
145
+ _onScrollEnd();
146
+ }, [_onScrollEnd, startAutoPlay]);
147
+
148
+ const scrollViewGestureOnTouchBegin = _react.default.useCallback(pauseAutoPlay, [pauseAutoPlay]);
149
+
150
+ const scrollViewGestureOnTouchEnd = _react.default.useCallback(startAutoPlay, [startAutoPlay]);
151
+
152
+ _react.default.useImperativeHandle(ref, () => ({
153
+ next,
154
+ prev,
155
+ getCurrentIndex,
156
+ scrollTo
157
+ }), [getCurrentIndex, next, prev, scrollTo]);
158
+
159
+ const layoutConfig = (0, _useLayoutConfig.useLayoutConfig)({ ...props,
160
+ size
161
+ });
162
+ return /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.GestureHandlerRootView, null, /*#__PURE__*/_react.default.createElement(_store.CTX.Provider, {
163
+ value: {
164
+ props,
165
+ common: commonVariables
166
+ }
167
+ }, /*#__PURE__*/_react.default.createElement(_ScrollViewGesture.ScrollViewGesture, {
168
+ key: mode,
169
+ size: size,
170
+ translation: handlerOffset,
171
+ style: [styles.container, {
172
+ width: width || "100%",
173
+ height: height || "100%"
174
+ }, style, vertical ? styles.itemsVertical : styles.itemsHorizontal],
175
+ testID: testID,
176
+ onScrollStart: scrollViewGestureOnScrollStart,
177
+ onScrollEnd: scrollViewGestureOnScrollEnd,
178
+ onTouchBegin: scrollViewGestureOnTouchBegin,
179
+ onTouchEnd: scrollViewGestureOnTouchEnd
180
+ }, /*#__PURE__*/_react.default.createElement(_ItemRenderer.ItemRenderer, {
181
+ data: data,
182
+ dataLength: dataLength,
183
+ rawDataLength: rawDataLength,
184
+ loop: loop,
185
+ size: size,
186
+ windowSize: windowSize,
187
+ autoFillData: autoFillData,
188
+ offsetX: offsetX,
189
+ handlerOffset: handlerOffset,
190
+ layoutConfig: layoutConfig,
191
+ renderItem: renderItem,
192
+ customAnimation: customAnimation
193
+ }))));
194
+ });
195
+
196
+ var _default = Carousel;
197
+ exports.default = _default;
198
+
199
+ const styles = _reactNative.StyleSheet.create({
200
+ container: {
201
+ overflow: "hidden"
202
+ },
203
+ itemsHorizontal: {
204
+ flexDirection: "row"
205
+ },
206
+ itemsVertical: {
207
+ flexDirection: "column"
208
+ }
209
+ });
210
+ //# sourceMappingURL=Carousel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","testID","loop","autoFillData","data","dataLength","rawDataLength","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","fixedDirection","renderItem","onScrollEnd","onSnapToItem","onScrollStart","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffset","offsetX","totalSize","x","value","isNaN","carouselController","duration","_onScrollEnd","next","prev","scrollTo","getSharedIndex","getCurrentIndex","start","startAutoPlay","pause","pauseAutoPlay","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollStart","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","layoutConfig","common","styles","container","itemsVertical","itemsHorizontal","StyleSheet","create","overflow","flexDirection"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AACA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,QAAQ,gBAAGC,eAAMC,UAAN,CACf,CAACC,MAAD,EAASC,GAAT,KAAiB;AACf,QAAMC,KAAK,GAAG,gCAAaF,MAAb,CAAd;AAEA,QAA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AACEnD,MAAAA,KAAK,EAAEA,KAAK,IAAI,MADlB;AAEEC,MAAAA,MAAM,EAAEA,MAAM,IAAI;AAFpB,KAFK,EAMLF,KANK,EAOLG,QAAQ,GACJgD,MAAM,CAACE,aADH,GAEJF,MAAM,CAACG,eATN,CAJT;AAeE,IAAA,MAAM,EAAE7D,MAfV;AAgBE,IAAA,aAAa,EAAEmD,8BAhBjB;AAiBE,IAAA,WAAW,EAAEC,4BAjBf;AAkBE,IAAA,YAAY,EAAEC,6BAlBhB;AAmBE,IAAA,UAAU,EAAEC;AAnBd,kBAqBE,6BAAC,0BAAD;AACE,IAAA,IAAI,EAAEnD,IADR;AAEE,IAAA,UAAU,EAAEC,UAFd;AAGE,IAAA,aAAa,EAAEC,aAHjB;AAIE,IAAA,IAAI,EAAEJ,IAJR;AAKE,IAAA,IAAI,EAAEyB,IALR;AAME,IAAA,UAAU,EAAEd,UANd;AAOE,IAAA,YAAY,EAAEV,YAPhB;AAQE,IAAA,OAAO,EAAE0B,OARX;AASE,IAAA,aAAa,EAAED,aATjB;AAUE,IAAA,YAAY,EAAE6B,YAVhB;AAWE,IAAA,UAAU,EAAEtC,UAXd;AAYE,IAAA,eAAe,EAAEK;AAZnB,IArBF,CADF,CADF,CADF;AA0CD,CAnLc,CAAjB;;eAsLe7B,Q;;;AAIf,MAAMgE,MAAM,GAAGI,wBAAWC,MAAX,CAAkB;AAC/BJ,EAAAA,SAAS,EAAE;AACTK,IAAAA,QAAQ,EAAE;AADD,GADoB;AAI/BH,EAAAA,eAAe,EAAE;AACfI,IAAAA,aAAa,EAAE;AADA,GAJc;AAO/BL,EAAAA,aAAa,EAAE;AACbK,IAAAA,aAAa,EAAE;AADF;AAPgB,CAAlB,CAAf","sourcesContent":["import React from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport { GestureHandlerRootView } from \"react-native-gesture-handler\";\nimport { runOnJS, useDerivedValue } from \"react-native-reanimated\";\n\nimport { ItemRenderer } from \"./ItemRenderer\";\nimport { ScrollViewGesture } from \"./ScrollViewGesture\";\n\nimport { useAutoPlay } from \"../hooks/useAutoPlay\";\nimport { useCarouselController } from \"../hooks/useCarouselController\";\nimport { useCommonVariables } from \"../hooks/useCommonVariables\";\nimport { useInitProps } from \"../hooks/useInitProps\";\nimport { useLayoutConfig } from \"../hooks/useLayoutConfig\";\nimport { useOnProgressChange } from \"../hooks/useOnProgressChange\";\nimport { usePropsErrorBoundary } from \"../hooks/usePropsErrorBoundary\";\nimport { CTX } from \"../store\";\nimport type { ICarouselInstance, TCarouselProps } from \"../types\";\nimport { computedRealIndexWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n loop,\n autoFillData,\n // Fill data with autoFillData\n data,\n // Length of fill data\n dataLength,\n // Length of raw data\n rawDataLength,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n fixedDirection,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollStart,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffset } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n\n if (!loop)\n return handlerOffset.value;\n\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary({ ...props, dataLength });\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawDataLength,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n dataLength,\n autoFillData,\n handlerOffset,\n withAnimation,\n defaultIndex,\n fixedDirection,\n duration: scrollAnimationDuration,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollStart: () => !!onScrollStart && runOnJS(onScrollStart)(),\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex }\n = carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem)\n onSnapToItem(realIndex);\n\n if (onScrollEnd)\n onScrollEnd(realIndex);\n }, [\n loop,\n autoFillData,\n rawDataLength,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollStart = React.useCallback(() => {\n pauseAutoPlay();\n onScrollStart?.();\n }, [onScrollStart, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n }),\n [getCurrentIndex, next, prev, scrollTo],\n );\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n return (\n <GestureHandlerRootView>\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffset}\n style={[\n styles.container,\n {\n width: width || \"100%\",\n height: height || \"100%\",\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollStart={scrollViewGestureOnScrollStart}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n <ItemRenderer\n data={data}\n dataLength={dataLength}\n rawDataLength={rawDataLength}\n loop={loop}\n size={size}\n windowSize={windowSize}\n autoFillData={autoFillData}\n offsetX={offsetX}\n handlerOffset={handlerOffset}\n layoutConfig={layoutConfig}\n renderItem={renderItem}\n customAnimation={customAnimation}\n />\n </ScrollViewGesture>\n </CTX.Provider>\n </GestureHandlerRootView>\n );\n },\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: \"hidden\",\n },\n itemsHorizontal: {\n flexDirection: \"row\",\n },\n itemsVertical: {\n flexDirection: \"column\",\n },\n});\n"]}
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.ItemRenderer = void 0;
7
+
8
+ var _react = _interopRequireDefault(require("react"));
9
+
10
+ var _reactNativeReanimated = require("react-native-reanimated");
11
+
12
+ var _BaseLayout = require("./BaseLayout");
13
+
14
+ var _useVisibleRanges = require("../hooks/useVisibleRanges");
15
+
16
+ var _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
17
+
18
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
+
20
+ const ItemRenderer = props => {
21
+ const {
22
+ data,
23
+ size,
24
+ windowSize,
25
+ handlerOffset,
26
+ offsetX,
27
+ dataLength,
28
+ rawDataLength,
29
+ loop,
30
+ autoFillData,
31
+ layoutConfig,
32
+ renderItem,
33
+ customAnimation
34
+ } = props;
35
+ const visibleRanges = (0, _useVisibleRanges.useVisibleRanges)({
36
+ total: dataLength,
37
+ viewSize: size,
38
+ translation: handlerOffset,
39
+ windowSize,
40
+ loop
41
+ });
42
+
43
+ const [displayedItems, setDisplayedItems] = _react.default.useState(null);
44
+
45
+ (0, _reactNativeReanimated.useAnimatedReaction)(() => visibleRanges.value, ranges => (0, _reactNativeReanimated.runOnJS)(setDisplayedItems)(ranges), [visibleRanges]);
46
+ if (!displayedItems) return null;
47
+ return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, data.map((item, index) => {
48
+ const realIndex = (0, _computedWithAutoFillData.computedRealIndexWithAutoFillData)({
49
+ index,
50
+ dataLength: rawDataLength,
51
+ loop,
52
+ autoFillData
53
+ });
54
+ const {
55
+ negativeRange,
56
+ positiveRange
57
+ } = displayedItems;
58
+ const shouldRender = index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1];
59
+ if (!shouldRender) return null;
60
+ return /*#__PURE__*/_react.default.createElement(_BaseLayout.BaseLayout, {
61
+ key: index,
62
+ index: index,
63
+ handlerOffset: offsetX,
64
+ visibleRanges: visibleRanges,
65
+ animationStyle: customAnimation || layoutConfig
66
+ }, _ref => {
67
+ let {
68
+ animationValue
69
+ } = _ref;
70
+ return renderItem({
71
+ item,
72
+ index: realIndex,
73
+ animationValue
74
+ });
75
+ });
76
+ }));
77
+ };
78
+
79
+ exports.ItemRenderer = ItemRenderer;
80
+ //# sourceMappingURL=ItemRenderer.js.map