react-native-reanimated-carousel 2.3.3 → 2.3.6

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 (66) hide show
  1. package/README.md +11 -3
  2. package/README.zh-CN.md +11 -3
  3. package/lib/commonjs/Carousel.js +1 -1
  4. package/lib/commonjs/Carousel.js.map +1 -1
  5. package/lib/commonjs/hooks/useAutoPlay.js +1 -1
  6. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
  7. package/lib/commonjs/hooks/useCarouselController.js +1 -1
  8. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  9. package/lib/commonjs/hooks/useCommonVariables.js +1 -1
  10. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
  11. package/lib/commonjs/hooks/useInitProps.js +1 -1
  12. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  13. package/lib/commonjs/hooks/useOnProgressChange.js +1 -1
  14. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
  15. package/lib/commonjs/utils/computedWithAutoFillData.js +2 -0
  16. package/lib/commonjs/utils/computedWithAutoFillData.js.map +1 -0
  17. package/lib/module/Carousel.js +15 -14
  18. package/lib/module/Carousel.js.map +1 -1
  19. package/lib/module/hooks/useAutoPlay.js +2 -1
  20. package/lib/module/hooks/useAutoPlay.js.map +1 -1
  21. package/lib/module/hooks/useCarouselController.js +5 -4
  22. package/lib/module/hooks/useCarouselController.js.map +1 -1
  23. package/lib/module/hooks/useCommonVariables.js +3 -2
  24. package/lib/module/hooks/useCommonVariables.js.map +1 -1
  25. package/lib/module/hooks/useInitProps.js +9 -14
  26. package/lib/module/hooks/useInitProps.js.map +1 -1
  27. package/lib/module/hooks/useOnProgressChange.js +13 -9
  28. package/lib/module/hooks/useOnProgressChange.js.map +1 -1
  29. package/lib/module/utils/computedWithAutoFillData.js +85 -0
  30. package/lib/module/utils/computedWithAutoFillData.js.map +1 -0
  31. package/lib/typescript/exampleBare/App.d.ts +2 -0
  32. package/lib/typescript/{Carousel.d.ts → src/Carousel.d.ts} +0 -0
  33. package/lib/typescript/{LazyView.d.ts → src/LazyView.d.ts} +0 -0
  34. package/lib/typescript/{ScrollViewGesture.d.ts → src/ScrollViewGesture.d.ts} +0 -0
  35. package/lib/typescript/{constants → src/constants}/index.d.ts +0 -0
  36. package/lib/typescript/{hooks → src/hooks}/useAutoPlay.d.ts +0 -0
  37. package/lib/typescript/{hooks → src/hooks}/useCarouselController.d.ts +1 -0
  38. package/lib/typescript/{hooks → src/hooks}/useCheckMounted.d.ts +0 -0
  39. package/lib/typescript/{hooks → src/hooks}/useCommonVariables.d.ts +0 -0
  40. package/lib/typescript/{hooks → src/hooks}/useInitProps.d.ts +1 -1
  41. package/lib/typescript/{hooks → src/hooks}/useLayoutConfig.d.ts +0 -0
  42. package/lib/typescript/{hooks → src/hooks}/useOffsetX.d.ts +0 -0
  43. package/lib/typescript/{hooks → src/hooks}/useOnProgressChange.d.ts +2 -0
  44. package/lib/typescript/{hooks → src/hooks}/usePropsErrorBoundary.d.ts +0 -0
  45. package/lib/typescript/{hooks → src/hooks}/useVisibleRanges.d.ts +0 -0
  46. package/lib/typescript/{index.d.ts → src/index.d.ts} +0 -0
  47. package/lib/typescript/{layouts → src/layouts}/BaseLayout.d.ts +0 -0
  48. package/lib/typescript/{layouts → src/layouts}/ParallaxLayout.d.ts +0 -0
  49. package/lib/typescript/{layouts → src/layouts}/index.d.ts +0 -0
  50. package/lib/typescript/{layouts → src/layouts}/normal.d.ts +0 -0
  51. package/lib/typescript/{layouts → src/layouts}/parallax.d.ts +0 -0
  52. package/lib/typescript/{layouts → src/layouts}/stack.d.ts +0 -0
  53. package/lib/typescript/{store → src/store}/index.d.ts +0 -0
  54. package/lib/typescript/{types.d.ts → src/types.d.ts} +8 -1
  55. package/lib/typescript/src/utils/computedWithAutoFillData.d.ts +18 -0
  56. package/lib/typescript/{utils → src/utils}/dealWithAnimation.d.ts +0 -0
  57. package/lib/typescript/{utils → src/utils}/log.d.ts +0 -0
  58. package/package.json +1 -1
  59. package/src/Carousel.tsx +20 -11
  60. package/src/hooks/useAutoPlay.ts +2 -1
  61. package/src/hooks/useCarouselController.tsx +5 -3
  62. package/src/hooks/useCommonVariables.ts +2 -2
  63. package/src/hooks/useInitProps.ts +14 -14
  64. package/src/hooks/useOnProgressChange.ts +20 -10
  65. package/src/types.ts +8 -0
  66. package/src/utils/computedWithAutoFillData.ts +76 -0
package/README.md CHANGED
@@ -17,7 +17,7 @@ English | [简体中文](./README.zh-CN.md)
17
17
  - **It completely solves this** [[problem]](https://github.com/meliorence/react-native-snap-carousel/issues/632) **for `react-native-snap-carousel`!**
18
18
  - **Simple**、**Infinitely scrolling very smooth**、**Fully implemented using Reanimated 2!**
19
19
 
20
- > V2 has been released! Join it! [[v1 docs]](https://github.com/dohooo/react-native-reanimated-carousel/tree/v1.x.x)
20
+ > V2 has been released! Join it! [[v1 docs]](https://github.com/dohooo/react-native-reanimated-carousel/tree/v1.x.x)
21
21
 
22
22
  > Support to Web [[demo]](https://dohooo.github.io/react-native-reanimated-carousel/)
23
23
 
@@ -74,10 +74,16 @@ English | [简体中文](./README.zh-CN.md)
74
74
  <a href="./example/src/marquee/index.tsx">
75
75
  <img src="assets/marquee.gif" width="300"/>
76
76
  </a>
77
- <br/>
77
+ <a href="./example/src/multiple/index.tsx">
78
+ <img src="assets/multiple.gif" width="300"/>
79
+ </a>
78
80
  <a href="./example/src/flow/index.tsx">
79
81
  <img src="assets/flow.gif" width="300"/>
80
82
  </a>
83
+ <br/>
84
+ <a href="./example/src/parallax-layers/index.tsx">
85
+ <img src="assets/parallax-layers.gif" width="300"/>
86
+ </a>
81
87
  </p>
82
88
 
83
89
  ## Table of contents
@@ -123,7 +129,7 @@ import Carousel from 'react-native-reanimated-carousel';
123
129
  - Optimizing
124
130
 
125
131
  - 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)
126
-
132
+
127
133
  - Used in `ScrollView/FlastList`
128
134
 
129
135
  - **[#143](https://github.com/dohooo/react-native-reanimated-carousel/issues/143) - Carousel suppresses ScrollView/FlastList 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:
@@ -162,7 +168,9 @@ import Carousel from 'react-native-reanimated-carousel';
162
168
  </details>
163
169
 
164
170
  ## Example
171
+
165
172
  > `:pretty` use pretty images
173
+
166
174
  ```shell
167
175
  yarn ios
168
176
  yarn ios:pretty
package/README.zh-CN.md CHANGED
@@ -19,7 +19,7 @@
19
19
 
20
20
  > v2 已经发布,希望大家喜欢!~ [[v1 文档]](https://github.com/dohooo/react-native-reanimated-carousel/tree/v1.x.x)
21
21
 
22
- > 支持Web端 [[示例]](https://dohooo.github.io/react-native-reanimated-carousel/)
22
+ > 支持 Web 端 [[示例]](https://dohooo.github.io/react-native-reanimated-carousel/)
23
23
 
24
24
  > 点击图片,查看代码 [[试一下]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
25
25
 
@@ -74,10 +74,17 @@
74
74
  <a href="./example/src/marquee/index.tsx">
75
75
  <img src="assets/marquee.gif" width="300"/>
76
76
  </a>
77
+ <a href="./example/src/multiple/index.tsx">
78
+ <img src="assets/multiple.gif" width="300"/>
79
+ </a>
77
80
  <br/>
78
81
  <a href="./example/src/flow/index.tsx">
79
82
  <img src="assets/flow.gif" width="300"/>
80
83
  </a>
84
+ <br/>
85
+ <a href="./example/src/parallax-layers/index.tsx">
86
+ <img src="assets/parallax-layers.gif" width="300"/>
87
+ </a>
81
88
  </p>
82
89
 
83
90
  ## 目录
@@ -125,7 +132,8 @@ import Carousel from 'react-native-reanimated-carousel';
125
132
  - 优化
126
133
  - 当渲染大量元素时,可使用`windowSize`属性,来控制当前元素的两侧渲染数量,默认为全量渲染。经测试不加此属性,渲染 200 个空 view 时会出现掉帧情况,设置此属性后渲染 1000 个空 view 依旧流畅。(具体数量与测试的手机型号相关)
127
134
  - 在`ScrollView/FlastList`中使用
128
- - **[#143](https://github.com/dohooo/react-native-reanimated-carousel/issues/143) - Carousel suppresses ScrollView/FlastList scroll gesture handler:** 当轮播图被放置在ScrollView/FlatList中时,轮播图的部分将无法控制列表滚动,解决办法是我们只允许手势系统识别某一方向,而不是所有方向,在下方例子中我们为了让列表可以向下滑动,所以我们使用[activeOffsetX](https://docs.swmansion.com/react-native-gesture-handler/docs/1.10.3/api/gesture-handlers/pan-gh/#activeoffsetx)属性来控制轮播图只识别横向手势:
135
+
136
+ - **[#143](https://github.com/dohooo/react-native-reanimated-carousel/issues/143) - Carousel suppresses ScrollView/FlastList scroll gesture handler:** 当轮播图被放置在 ScrollView/FlatList 中时,轮播图的部分将无法控制列表滚动,解决办法是我们只允许手势系统识别某一方向,而不是所有方向,在下方例子中我们为了让列表可以向下滑动,所以我们使用[activeOffsetX](https://docs.swmansion.com/react-native-gesture-handler/docs/1.10.3/api/gesture-handlers/pan-gh/#activeoffsetx)属性来控制轮播图只识别横向手势:
129
137
 
130
138
  ```tsx
131
139
  <Carousel
@@ -135,7 +143,7 @@ import Carousel from 'react-native-reanimated-carousel';
135
143
  }}
136
144
  />
137
145
  ```
138
-
146
+
139
147
  - RTL
140
148
  - 所有 layout 均完美支持 RTL 模式,并且无需再做任何配置。但在 RTL 模式下使用自动播放时,默认不会自动转换方向,需要结合 autoPlayReverse 来手动控制方向。
141
149
  - EXPO
@@ -1,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useCarouselController=require("./hooks/useCarouselController");var _useAutoPlay2=require("./hooks/useAutoPlay");var _usePropsErrorBoundary=require("./hooks/usePropsErrorBoundary");var _ScrollViewGesture=require("./ScrollViewGesture");var _useVisibleRanges=require("./hooks/useVisibleRanges");var _reactNative=require("react-native");var _constants=require("./constants");var _BaseLayout=require("./layouts/BaseLayout");var _useLayoutConfig=require("./hooks/useLayoutConfig");var _useInitProps=require("./hooks/useInitProps");var _store=require("./store");var _useCommonVariables=require("./hooks/useCommonVariables");var _useOnProgressChange=require("./hooks/useOnProgressChange");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}var Carousel=_react.default.forwardRef(function(_props,ref){var props=(0,_useInitProps.useInitProps)(_props);var data=props.data,rawData=props.rawData,loop=props.loop,mode=props.mode,style=props.style,width=props.width,height=props.height,vertical=props.vertical,autoPlay=props.autoPlay,windowSize=props.windowSize,autoPlayReverse=props.autoPlayReverse,autoPlayInterval=props.autoPlayInterval,scrollAnimationDuration=props.scrollAnimationDuration,withAnimation=props.withAnimation,renderItem=props.renderItem,onScrollEnd=props.onScrollEnd,onSnapToItem=props.onSnapToItem,_onScrollBegin=props.onScrollBegin,onProgressChange=props.onProgressChange,customAnimation=props.customAnimation;var commonVariables=(0,_useCommonVariables.useCommonVariables)(props);var size=commonVariables.size,handlerOffsetX=commonVariables.handlerOffsetX;var dataLength=data.length;var offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var totalSize=size*dataLength;var x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;};_f._closure={size:size,dataLength:dataLength,handlerOffsetX:handlerOffsetX,loop:loop};_f.asString="function _f(){const{size,dataLength,handlerOffsetX,loop}=jsThis._closure;{const totalSize=size*dataLength;const x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;}}";_f.__workletHash=17456063948631;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx (51:40)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,size,dataLength]);(0,_usePropsErrorBoundary.usePropsErrorBoundary)(props);(0,_useOnProgressChange.useOnProgressChange)({size:size,offsetX:offsetX,rawData:rawData,onProgressChange:onProgressChange});var carouselController=(0,_useCarouselController.useCarouselController)({loop:loop,size:size,handlerOffsetX:handlerOffsetX,length:data.length,disable:!data.length,withAnimation:withAnimation,originalLength:data.length,onScrollEnd:function onScrollEnd(){return(0,_reactNativeReanimated.runOnJS)(_onScrollEnd)();},onScrollBegin:function onScrollBegin(){return!!_onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(_onScrollBegin)();},onChange:function onChange(i){return!!onSnapToItem&&(0,_reactNativeReanimated.runOnJS)(onSnapToItem)(i);},duration:scrollAnimationDuration});var next=carouselController.next,prev=carouselController.prev,sharedPreIndex=carouselController.sharedPreIndex,sharedIndex=carouselController.sharedIndex,computedIndex=carouselController.computedIndex,getCurrentIndex=carouselController.getCurrentIndex;var _useAutoPlay=(0,_useAutoPlay2.useAutoPlay)({autoPlay:autoPlay,autoPlayInterval:autoPlayInterval,autoPlayReverse:autoPlayReverse,carouselController:carouselController}),start=_useAutoPlay.start,pause=_useAutoPlay.pause;var _onScrollEnd=_react.default.useCallback(function(){computedIndex();onScrollEnd==null?void 0:onScrollEnd(sharedPreIndex.current,sharedIndex.current);},[sharedPreIndex,sharedIndex,computedIndex,onScrollEnd]);var scrollViewGestureOnScrollBegin=_react.default.useCallback(function(){pause();_onScrollBegin==null?void 0:_onScrollBegin();},[_onScrollBegin,pause]);var scrollViewGestureOnScrollEnd=_react.default.useCallback(function(){start();_onScrollEnd();},[_onScrollEnd,start]);var scrollViewGestureOnTouchBegin=_react.default.useCallback(pause,[pause]);var scrollViewGestureOnTouchEnd=_react.default.useCallback(start,[start]);var goToIndex=_react.default.useCallback(function(i,animated){carouselController.to(i,animated);},[carouselController]);_react.default.useImperativeHandle(ref,function(){return{next:next,prev:prev,getCurrentIndex:getCurrentIndex,goToIndex:goToIndex,scrollTo:carouselController.scrollTo};},[getCurrentIndex,goToIndex,next,prev,carouselController.scrollTo]);var visibleRanges=(0,_useVisibleRanges.useVisibleRanges)({total:data.length,viewSize:size,translation:handlerOffsetX,windowSize:windowSize});var layoutConfig=(0,_useLayoutConfig.useLayoutConfig)(_objectSpread(_objectSpread({},props),{},{size:size}));var renderLayout=_react.default.useCallback(function(item,i){var realIndex=i;if(rawData.length===_constants.DATA_LENGTH.SINGLE_ITEM){realIndex=i%1;}if(rawData.length===_constants.DATA_LENGTH.DOUBLE_ITEM){realIndex=i%2;}return _react.default.createElement(_BaseLayout.BaseLayout,{key:i,index:i,handlerOffsetX:offsetX,visibleRanges:visibleRanges,animationStyle:customAnimation||layoutConfig,__self:_this,__source:{fileName:_jsxFileName,lineNumber:159,columnNumber:21}},function(_ref){var animationValue=_ref.animationValue;return renderItem({item:item,index:realIndex,animationValue:animationValue});});},[rawData,offsetX,visibleRanges,renderItem,layoutConfig,customAnimation]);return _react.default.createElement(_store.CTX.Provider,{value:{props:props,common:commonVariables},__self:_this,__source:{fileName:_jsxFileName,lineNumber:187,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:[styles.container,{width:width||'100%',height:height||'100%'},style],__self:_this,__source:{fileName:_jsxFileName,lineNumber:188,columnNumber:17}},_react.default.createElement(_ScrollViewGesture.ScrollViewGesture,{size:size,translation:handlerOffsetX,onScrollBegin:scrollViewGestureOnScrollBegin,onScrollEnd:scrollViewGestureOnScrollEnd,onTouchBegin:scrollViewGestureOnTouchBegin,onTouchEnd:scrollViewGestureOnTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:195,columnNumber:21}},_react.default.createElement(_reactNativeReanimated.default.View,{key:mode,style:[styles.container,{width:width||'100%',height:height||'100%'},style,vertical?styles.itemsVertical:styles.itemsHorizontal],__self:_this,__source:{fileName:_jsxFileName,lineNumber:203,columnNumber:25}},data.map(renderLayout)))));});var _default=Carousel;exports.default=_default;var styles=_reactNative.StyleSheet.create({container:{overflow:'hidden'},itemsHorizontal:{flexDirection:'row'},itemsVertical:{flexDirection:'column'}});
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useCarouselController=require("./hooks/useCarouselController");var _useAutoPlay2=require("./hooks/useAutoPlay");var _usePropsErrorBoundary=require("./hooks/usePropsErrorBoundary");var _ScrollViewGesture=require("./ScrollViewGesture");var _useVisibleRanges=require("./hooks/useVisibleRanges");var _reactNative=require("react-native");var _BaseLayout=require("./layouts/BaseLayout");var _useLayoutConfig=require("./hooks/useLayoutConfig");var _useInitProps=require("./hooks/useInitProps");var _store=require("./store");var _useCommonVariables=require("./hooks/useCommonVariables");var _useOnProgressChange=require("./hooks/useOnProgressChange");var _computedWithAutoFillData=require("./utils/computedWithAutoFillData");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}var Carousel=_react.default.forwardRef(function(_props,ref){var props=(0,_useInitProps.useInitProps)(_props);var data=props.data,rawData=props.rawData,loop=props.loop,autoFillData=props.autoFillData,mode=props.mode,style=props.style,width=props.width,height=props.height,vertical=props.vertical,autoPlay=props.autoPlay,windowSize=props.windowSize,autoPlayReverse=props.autoPlayReverse,autoPlayInterval=props.autoPlayInterval,scrollAnimationDuration=props.scrollAnimationDuration,withAnimation=props.withAnimation,renderItem=props.renderItem,onScrollEnd=props.onScrollEnd,onSnapToItem=props.onSnapToItem,_onScrollBegin=props.onScrollBegin,onProgressChange=props.onProgressChange,customAnimation=props.customAnimation,defaultIndex=props.defaultIndex;var commonVariables=(0,_useCommonVariables.useCommonVariables)(props);var size=commonVariables.size,handlerOffsetX=commonVariables.handlerOffsetX;var dataLength=data.length;var offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var totalSize=size*dataLength;var x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;};_f._closure={size:size,dataLength:dataLength,handlerOffsetX:handlerOffsetX,loop:loop};_f.asString="function _f(){const{size,dataLength,handlerOffsetX,loop}=jsThis._closure;{const totalSize=size*dataLength;const x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;}}";_f.__workletHash=17456063948631;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx (53:40)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,size,dataLength]);(0,_usePropsErrorBoundary.usePropsErrorBoundary)(props);(0,_useOnProgressChange.useOnProgressChange)({autoFillData:autoFillData,loop:loop,size:size,offsetX:offsetX,rawData:rawData,onProgressChange:onProgressChange});var carouselController=(0,_useCarouselController.useCarouselController)({loop:loop,size:size,handlerOffsetX:handlerOffsetX,length:data.length,disable:!data.length,withAnimation:withAnimation,originalLength:data.length,defaultIndex:defaultIndex,onScrollEnd:function onScrollEnd(){return(0,_reactNativeReanimated.runOnJS)(_onScrollEnd)();},onScrollBegin:function onScrollBegin(){return!!_onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(_onScrollBegin)();},onChange:function onChange(i){return!!onSnapToItem&&(0,_reactNativeReanimated.runOnJS)(onSnapToItem)(i);},duration:scrollAnimationDuration});var next=carouselController.next,prev=carouselController.prev,sharedPreIndex=carouselController.sharedPreIndex,sharedIndex=carouselController.sharedIndex,computedIndex=carouselController.computedIndex,getCurrentIndex=carouselController.getCurrentIndex;var _useAutoPlay=(0,_useAutoPlay2.useAutoPlay)({autoPlay:autoPlay,autoPlayInterval:autoPlayInterval,autoPlayReverse:autoPlayReverse,carouselController:carouselController}),start=_useAutoPlay.start,pause=_useAutoPlay.pause;var _onScrollEnd=_react.default.useCallback(function(){computedIndex();onScrollEnd==null?void 0:onScrollEnd(sharedPreIndex.current,sharedIndex.current);},[sharedPreIndex,sharedIndex,computedIndex,onScrollEnd]);var scrollViewGestureOnScrollBegin=_react.default.useCallback(function(){pause();_onScrollBegin==null?void 0:_onScrollBegin();},[_onScrollBegin,pause]);var scrollViewGestureOnScrollEnd=_react.default.useCallback(function(){start();_onScrollEnd();},[_onScrollEnd,start]);var scrollViewGestureOnTouchBegin=_react.default.useCallback(pause,[pause]);var scrollViewGestureOnTouchEnd=_react.default.useCallback(start,[start]);var goToIndex=_react.default.useCallback(function(i,animated){carouselController.to(i,animated);},[carouselController]);_react.default.useImperativeHandle(ref,function(){return{next:next,prev:prev,getCurrentIndex:getCurrentIndex,goToIndex:goToIndex,scrollTo:carouselController.scrollTo};},[getCurrentIndex,goToIndex,next,prev,carouselController.scrollTo]);var visibleRanges=(0,_useVisibleRanges.useVisibleRanges)({total:data.length,viewSize:size,translation:handlerOffsetX,windowSize:windowSize});var layoutConfig=(0,_useLayoutConfig.useLayoutConfig)(_objectSpread(_objectSpread({},props),{},{size:size}));var renderLayout=_react.default.useCallback(function(item,i){var realIndex=(0,_computedWithAutoFillData.computedRealIndexWithAutoFillData)({index:i,dataLength:rawData.length,loop:loop,autoFillData:autoFillData});return _react.default.createElement(_BaseLayout.BaseLayout,{key:i,index:i,handlerOffsetX:offsetX,visibleRanges:visibleRanges,animationStyle:customAnimation||layoutConfig,__self:_this,__source:{fileName:_jsxFileName,lineNumber:167,columnNumber:21}},function(_ref){var animationValue=_ref.animationValue;return renderItem({item:item,index:realIndex,animationValue:animationValue});});},[loop,rawData,offsetX,visibleRanges,autoFillData,renderItem,layoutConfig,customAnimation]);return _react.default.createElement(_store.CTX.Provider,{value:{props:props,common:commonVariables},__self:_this,__source:{fileName:_jsxFileName,lineNumber:197,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:[styles.container,{width:width||'100%',height:height||'100%'}],__self:_this,__source:{fileName:_jsxFileName,lineNumber:198,columnNumber:17}},_react.default.createElement(_ScrollViewGesture.ScrollViewGesture,{size:size,translation:handlerOffsetX,onScrollBegin:scrollViewGestureOnScrollBegin,onScrollEnd:scrollViewGestureOnScrollEnd,onTouchBegin:scrollViewGestureOnTouchBegin,onTouchEnd:scrollViewGestureOnTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:204,columnNumber:21}},_react.default.createElement(_reactNativeReanimated.default.View,{key:mode,style:[styles.container,{width:width||'100%',height:height||'100%'},style,vertical?styles.itemsVertical:styles.itemsHorizontal],__self:_this,__source:{fileName:_jsxFileName,lineNumber:212,columnNumber:25}},data.map(renderLayout)))));});var _default=Carousel;exports.default=_default;var styles=_reactNative.StyleSheet.create({container:{overflow:'hidden'},itemsHorizontal:{flexDirection:'row'},itemsVertical:{flexDirection:'column'}});
2
2
  //# sourceMappingURL=Carousel.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","data","rawData","loop","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","commonVariables","size","handlerOffsetX","dataLength","length","offsetX","totalSize","x","value","isNaN","carouselController","disable","originalLength","_onScrollEnd","onChange","i","duration","next","prev","sharedPreIndex","sharedIndex","computedIndex","getCurrentIndex","start","pause","useCallback","current","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","goToIndex","animated","to","useImperativeHandle","scrollTo","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","realIndex","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","animationValue","index","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":"iQAAA,oDACA,uFAEA,oEACA,iDACA,oEACA,sDACA,0DAGA,yCACA,sCACA,gDACA,wDACA,kDACA,8BACA,8DACA,gE,o3DAEA,GAAMA,CAAAA,QAAQ,CAAGC,eAAMC,UAAN,CACb,SAACC,MAAD,CAASC,GAAT,CAAiB,CACb,GAAMC,CAAAA,KAAK,CAAG,+BAAaF,MAAb,CAAd,CAEA,GACIG,CAAAA,IADJ,CAqBID,KArBJ,CACIC,IADJ,CAEIC,OAFJ,CAqBIF,KArBJ,CAEIE,OAFJ,CAGIC,IAHJ,CAqBIH,KArBJ,CAGIG,IAHJ,CAIIC,IAJJ,CAqBIJ,KArBJ,CAIII,IAJJ,CAKIC,KALJ,CAqBIL,KArBJ,CAKIK,KALJ,CAMIC,KANJ,CAqBIN,KArBJ,CAMIM,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zC,eANJ,CA7BiB,CAArB,CAuCA,MACI,8BAAC,UAAD,CAAK,QAAL,EAAc,KAAK,CAAE,CAAEpB,KAAK,CAALA,KAAF,CAASsE,MAAM,CAAEjD,eAAjB,CAArB,+EACI,6BAAC,iBAAD,EACI,KAAK,CAAE,CACHkD,MAAM,CAACC,SADJ,CAEH,CAAElE,KAAK,CAAEA,KAAK,EAAI,MAAlB,CAA0BC,MAAM,CAAEA,MAAM,EAAI,MAA5C,CAFG,CAGHF,KAHG,CADX,+EAOI,6BAAC,oCAAD,EACI,IAAI,CAAEiB,IADV,CAEI,WAAW,CAAEC,cAFjB,CAGI,aAAa,CAAEyB,8BAHnB,CAII,WAAW,CAAEC,4BAJjB,CAKI,YAAY,CAAEC,6BALlB,CAMI,UAAU,CAAEC,2BANhB,+EAQI,6BAAC,8BAAD,CAAU,IAAV,EACI,GAAG,CAAE/C,IADT,CAEI,KAAK,CAAE,CACHmE,MAAM,CAACC,SADJ,CAEH,CACIlE,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAFG,CAMHF,KANG,CAOHG,QAAQ,CACF+D,MAAM,CAACE,aADL,CAEFF,MAAM,CAACG,eATV,CAFX,+EAcKzE,IAAI,CAAC0E,GAAL,CAASb,YAAT,CAdL,CARJ,CAPJ,CADJ,CADJ,CAqCH,CA3MY,CAAjB,C,aA8MenE,Q,0BAIf,GAAM4E,CAAAA,MAAM,CAAGK,wBAAWC,MAAX,CAAkB,CAC7BL,SAAS,CAAE,CACPM,QAAQ,CAAE,QADH,CADkB,CAI7BJ,eAAe,CAAE,CACbK,aAAa,CAAE,KADF,CAJY,CAO7BN,aAAa,CAAE,CACXM,aAAa,CAAE,QADJ,CAPc,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport Animated, { runOnJS, useDerivedValue } from 'react-native-reanimated';\n\nimport { useCarouselController } from './hooks/useCarouselController';\nimport { useAutoPlay } from './hooks/useAutoPlay';\nimport { usePropsErrorBoundary } from './hooks/usePropsErrorBoundary';\nimport { ScrollViewGesture } from './ScrollViewGesture';\nimport { useVisibleRanges } from './hooks/useVisibleRanges';\n\nimport type { ICarouselInstance, TCarouselProps } from './types';\nimport { StyleSheet, View } from 'react-native';\nimport { DATA_LENGTH } from './constants';\nimport { BaseLayout } from './layouts/BaseLayout';\nimport { useLayoutConfig } from './hooks/useLayoutConfig';\nimport { useInitProps } from './hooks/useInitProps';\nimport { CTX } from './store';\nimport { useCommonVariables } from './hooks/useCommonVariables';\nimport { useOnProgressChange } from './hooks/useOnProgressChange';\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n data,\n rawData,\n loop,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffsetX } = commonVariables;\n const dataLength = data.length;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary(props);\n useOnProgressChange({ size, offsetX, rawData, onProgressChange });\n\n const carouselController = useCarouselController({\n loop,\n size,\n handlerOffsetX,\n length: data.length,\n disable: !data.length,\n withAnimation,\n originalLength: data.length,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n onChange: (i) => !!onSnapToItem && runOnJS(onSnapToItem)(i),\n duration: scrollAnimationDuration,\n });\n\n const {\n next,\n prev,\n sharedPreIndex,\n sharedIndex,\n computedIndex,\n getCurrentIndex,\n } = carouselController;\n\n const { start, pause } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n computedIndex();\n onScrollEnd?.(sharedPreIndex.current, sharedIndex.current);\n }, [sharedPreIndex, sharedIndex, computedIndex, onScrollEnd]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pause();\n onScrollBegin?.();\n }, [onScrollBegin, pause]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n start();\n _onScrollEnd();\n }, [_onScrollEnd, start]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pause, [pause]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(start, [start]);\n\n const goToIndex = React.useCallback(\n (i: number, animated?: boolean) => {\n carouselController.to(i, animated);\n },\n [carouselController]\n );\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n goToIndex,\n scrollTo: carouselController.scrollTo,\n }),\n [\n getCurrentIndex,\n goToIndex,\n next,\n prev,\n carouselController.scrollTo,\n ]\n );\n\n const visibleRanges = useVisibleRanges({\n total: data.length,\n viewSize: size,\n translation: handlerOffsetX,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n let realIndex = i;\n if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {\n realIndex = i % 1;\n }\n\n if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {\n realIndex = i % 2;\n }\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffsetX={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n rawData,\n offsetX,\n visibleRanges,\n renderItem,\n layoutConfig,\n customAnimation,\n ]\n );\n\n return (\n <CTX.Provider value={{ props, common: commonVariables }}>\n <View\n style={[\n styles.container,\n { width: width || '100%', height: height || '100%' },\n style,\n ]}\n >\n <ScrollViewGesture\n size={size}\n translation={handlerOffsetX}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n <Animated.View\n key={mode}\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 >\n {data.map(renderLayout)}\n </Animated.View>\n </ScrollViewGesture>\n </View>\n </CTX.Provider>\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"]}
1
+ {"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","data","rawData","loop","autoFillData","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffsetX","dataLength","length","offsetX","totalSize","x","value","isNaN","carouselController","disable","originalLength","_onScrollEnd","onChange","i","duration","next","prev","sharedPreIndex","sharedIndex","computedIndex","getCurrentIndex","start","pause","useCallback","current","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","goToIndex","animated","to","useImperativeHandle","scrollTo","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","realIndex","index","animationValue","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":"iQAAA,oDACA,uFAEA,oEACA,iDACA,oEACA,sDACA,0DAGA,yCACA,gDACA,wDACA,k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AAM,CAAEA,MAAM,EAAI,MAFtB,CAFG,CAMHF,KANG,CAOHG,QAAQ,CACF6D,MAAM,CAACE,aADL,CAEFF,MAAM,CAACG,eATV,CAFX,+EAcKxE,IAAI,CAACyE,GAAL,CAASV,YAAT,CAdL,CARJ,CANJ,CADJ,CADJ,CAoCH,CApNY,CAAjB,C,aAuNerE,Q,0BAIf,GAAM2E,CAAAA,MAAM,CAAGK,wBAAWC,MAAX,CAAkB,CAC7BL,SAAS,CAAE,CACPM,QAAQ,CAAE,QADH,CADkB,CAI7BJ,eAAe,CAAE,CACbK,aAAa,CAAE,KADF,CAJY,CAO7BN,aAAa,CAAE,CACXM,aAAa,CAAE,QADJ,CAPc,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport Animated, { runOnJS, useDerivedValue } from 'react-native-reanimated';\n\nimport { useCarouselController } from './hooks/useCarouselController';\nimport { useAutoPlay } from './hooks/useAutoPlay';\nimport { usePropsErrorBoundary } from './hooks/usePropsErrorBoundary';\nimport { ScrollViewGesture } from './ScrollViewGesture';\nimport { useVisibleRanges } from './hooks/useVisibleRanges';\n\nimport type { ICarouselInstance, TCarouselProps } from './types';\nimport { StyleSheet, View } from 'react-native';\nimport { BaseLayout } from './layouts/BaseLayout';\nimport { useLayoutConfig } from './hooks/useLayoutConfig';\nimport { useInitProps } from './hooks/useInitProps';\nimport { CTX } from './store';\nimport { useCommonVariables } from './hooks/useCommonVariables';\nimport { useOnProgressChange } from './hooks/useOnProgressChange';\nimport { computedRealIndexWithAutoFillData } from './utils/computedWithAutoFillData';\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n data,\n rawData,\n loop,\n autoFillData,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffsetX } = commonVariables;\n const dataLength = data.length;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary(props);\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawData,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n handlerOffsetX,\n length: data.length,\n disable: !data.length,\n withAnimation,\n originalLength: data.length,\n defaultIndex,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n onChange: (i) => !!onSnapToItem && runOnJS(onSnapToItem)(i),\n duration: scrollAnimationDuration,\n });\n\n const {\n next,\n prev,\n sharedPreIndex,\n sharedIndex,\n computedIndex,\n getCurrentIndex,\n } = carouselController;\n\n const { start, pause } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n computedIndex();\n onScrollEnd?.(sharedPreIndex.current, sharedIndex.current);\n }, [sharedPreIndex, sharedIndex, computedIndex, onScrollEnd]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pause();\n onScrollBegin?.();\n }, [onScrollBegin, pause]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n start();\n _onScrollEnd();\n }, [_onScrollEnd, start]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pause, [pause]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(start, [start]);\n\n const goToIndex = React.useCallback(\n (i: number, animated?: boolean) => {\n carouselController.to(i, animated);\n },\n [carouselController]\n );\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n goToIndex,\n scrollTo: carouselController.scrollTo,\n }),\n [\n getCurrentIndex,\n goToIndex,\n next,\n prev,\n carouselController.scrollTo,\n ]\n );\n\n const visibleRanges = useVisibleRanges({\n total: data.length,\n viewSize: size,\n translation: handlerOffsetX,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index: i,\n dataLength: rawData.length,\n loop,\n autoFillData,\n });\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffsetX={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n loop,\n rawData,\n offsetX,\n visibleRanges,\n autoFillData,\n renderItem,\n layoutConfig,\n customAnimation,\n ]\n );\n\n return (\n <CTX.Provider value={{ props, common: commonVariables }}>\n <View\n style={[\n styles.container,\n { width: width || '100%', height: height || '100%' },\n ]}\n >\n <ScrollViewGesture\n size={size}\n translation={handlerOffsetX}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n <Animated.View\n key={mode}\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 >\n {data.map(renderLayout)}\n </Animated.View>\n </ScrollViewGesture>\n </View>\n </CTX.Provider>\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"]}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.useAutoPlay=useAutoPlay;var React=_interopRequireWildcard(require("react"));function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}function useAutoPlay(opts){var _opts$autoPlay=opts.autoPlay,autoPlay=_opts$autoPlay===void 0?false:_opts$autoPlay,_opts$autoPlayReverse=opts.autoPlayReverse,autoPlayReverse=_opts$autoPlayReverse===void 0?false:_opts$autoPlayReverse,autoPlayInterval=opts.autoPlayInterval,carouselController=opts.carouselController;var timer=React.useRef();var stopped=React.useRef(!autoPlay);var play=React.useCallback(function(){if(stopped.current){return;}timer.current=setTimeout(function(){autoPlayReverse?carouselController.prev({onFinished:play}):carouselController.next({onFinished:play});},autoPlayInterval);},[autoPlayReverse,autoPlayInterval,carouselController]);var pause=React.useCallback(function(){if(!autoPlay){return;}timer.current&&clearInterval(timer.current);stopped.current=true;},[autoPlay]);var start=React.useCallback(function(){if(!autoPlay){return;}stopped.current=false;play();},[play,autoPlay]);React.useEffect(function(){if(autoPlay){start();}else{pause();}return pause;},[pause,start,autoPlay]);return{pause:pause,start:start};}
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.useAutoPlay=useAutoPlay;var React=_interopRequireWildcard(require("react"));function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}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;}function useAutoPlay(opts){var _opts$autoPlay=opts.autoPlay,autoPlay=_opts$autoPlay===void 0?false:_opts$autoPlay,_opts$autoPlayReverse=opts.autoPlayReverse,autoPlayReverse=_opts$autoPlayReverse===void 0?false:_opts$autoPlayReverse,autoPlayInterval=opts.autoPlayInterval,carouselController=opts.carouselController;var timer=React.useRef();var stopped=React.useRef(!autoPlay);var play=React.useCallback(function(){if(stopped.current){return;}timer.current&&clearTimeout(timer.current);timer.current=setTimeout(function(){autoPlayReverse?carouselController.prev({onFinished:play}):carouselController.next({onFinished:play});},autoPlayInterval);},[autoPlayReverse,autoPlayInterval,carouselController]);var pause=React.useCallback(function(){if(!autoPlay){return;}timer.current&&clearTimeout(timer.current);stopped.current=true;},[autoPlay]);var start=React.useCallback(function(){if(!autoPlay){return;}stopped.current=false;play();},[play,autoPlay]);React.useEffect(function(){if(autoPlay){start();}else{pause();}return pause;},[pause,start,autoPlay]);return{pause:pause,start:start};}
2
2
  //# sourceMappingURL=useAutoPlay.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useAutoPlay.ts"],"names":["useAutoPlay","opts","autoPlay","autoPlayReverse","autoPlayInterval","carouselController","timer","React","useRef","stopped","play","useCallback","current","setTimeout","prev","onFinished","next","pause","clearInterval","start","useEffect"],"mappings":"yFAAA,oD,0/BAGO,QAASA,CAAAA,WAAT,CAAqBC,IAArB,CAKJ,CACC,mBAKIA,IALJ,CACIC,QADJ,CACIA,QADJ,yBACe,KADf,sCAKID,IALJ,CAEIE,eAFJ,CAEIA,eAFJ,gCAEsB,KAFtB,uBAGIC,gBAHJ,CAKIH,IALJ,CAGIG,gBAHJ,CAIIC,kBAJJ,CAKIJ,IALJ,CAIII,kBAJJ,CAOA,GAAMC,CAAAA,KAAK,CAAGC,KAAK,CAACC,MAAN,EAAd,CACA,GAAMC,CAAAA,OAAO,CAAGF,KAAK,CAACC,MAAN,CAAsB,CAACN,QAAvB,CAAhB,CAEA,GAAMQ,CAAAA,IAAI,CAAGH,KAAK,CAACI,WAAN,CAAkB,UAAM,CACjC,GAAIF,OAAO,CAACG,OAAZ,CAAqB,CACjB,OACH,CAEDN,KAAK,CAACM,OAAN,CAAgBC,UAAU,CAAC,UAAM,CAC7BV,eAAe,CACTE,kBAAkB,CAACS,IAAnB,CAAwB,CAAEC,UAAU,CAAEL,IAAd,CAAxB,CADS,CAETL,kBAAkB,CAACW,IAAnB,CAAwB,CAAED,UAAU,CAAEL,IAAd,CAAxB,CAFN,CAGH,CAJyB,CAIvBN,gBAJuB,CAA1B,CAKH,CAVY,CAUV,CAACD,eAAD,CAAkBC,gBAAlB,CAAoCC,kBAApC,CAVU,CAAb,CAYA,GAAMY,CAAAA,KAAK,CAAGV,KAAK,CAACI,WAAN,CAAkB,UAAM,CAClC,GAAI,CAACT,QAAL,CAAe,CACX,OACH,CACDI,KAAK,CAACM,OAAN,EAAiBM,aAAa,CAACZ,KAAK,CAACM,OAAP,CAA9B,CACAH,OAAO,CAACG,OAAR,CAAkB,IAAlB,CACH,CANa,CAMX,CAACV,QAAD,CANW,CAAd,CAQA,GAAMiB,CAAAA,KAAK,CAAGZ,KAAK,CAACI,WAAN,CAAkB,UAAM,CAClC,GAAI,CAACT,QAAL,CAAe,CACX,OACH,CACDO,OAAO,CAACG,OAAR,CAAkB,KAAlB,CACAF,IAAI,GACP,CANa,CAMX,CAACA,IAAD,CAAOR,QAAP,CANW,CAAd,CAQAK,KAAK,CAACa,SAAN,CAAgB,UAAM,CAClB,GAAIlB,QAAJ,CAAc,CACViB,KAAK,GACR,CAFD,IAEO,CACHF,KAAK,GACR,CACD,MAAOA,CAAAA,KAAP,CACH,CAPD,CAOG,CAACA,KAAD,CAAQE,KAAR,CAAejB,QAAf,CAPH,EASA,MAAO,CACHe,KAAK,CAALA,KADG,CAEHE,KAAK,CAALA,KAFG,CAAP,CAIH","sourcesContent":["import * as React from 'react';\nimport type { ICarouselController } from './useCarouselController';\n\nexport function useAutoPlay(opts: {\n autoPlay?: boolean;\n autoPlayInterval?: number;\n autoPlayReverse?: boolean;\n carouselController: ICarouselController;\n}) {\n const {\n autoPlay = false,\n autoPlayReverse = false,\n autoPlayInterval,\n carouselController,\n } = opts;\n\n const timer = React.useRef<NodeJS.Timer>();\n const stopped = React.useRef<boolean>(!autoPlay);\n\n const play = React.useCallback(() => {\n if (stopped.current) {\n return;\n }\n\n timer.current = setTimeout(() => {\n autoPlayReverse\n ? carouselController.prev({ onFinished: play })\n : carouselController.next({ onFinished: play });\n }, autoPlayInterval);\n }, [autoPlayReverse, autoPlayInterval, carouselController]);\n\n const pause = React.useCallback(() => {\n if (!autoPlay) {\n return;\n }\n timer.current && clearInterval(timer.current);\n stopped.current = true;\n }, [autoPlay]);\n\n const start = React.useCallback(() => {\n if (!autoPlay) {\n return;\n }\n stopped.current = false;\n play();\n }, [play, autoPlay]);\n\n React.useEffect(() => {\n if (autoPlay) {\n start();\n } else {\n pause();\n }\n return pause;\n }, [pause, start, autoPlay]);\n\n return {\n pause,\n start,\n };\n}\n"]}
1
+ {"version":3,"sources":["useAutoPlay.ts"],"names":["useAutoPlay","opts","autoPlay","autoPlayReverse","autoPlayInterval","carouselController","timer","React","useRef","stopped","play","useCallback","current","clearTimeout","setTimeout","prev","onFinished","next","pause","start","useEffect"],"mappings":"yFAAA,oD,0/BAGO,QAASA,CAAAA,WAAT,CAAqBC,IAArB,CAKJ,CACC,mBAKIA,IALJ,CACIC,QADJ,CACIA,QADJ,yBACe,KADf,sCAKID,IALJ,CAEIE,eAFJ,CAEIA,eAFJ,gCAEsB,KAFtB,uBAGIC,gBAHJ,CAKIH,IALJ,CAGIG,gBAHJ,CAIIC,kBAJJ,CAKIJ,IALJ,CAIII,kBAJJ,CAOA,GAAMC,CAAAA,KAAK,CAAGC,KAAK,CAACC,MAAN,EAAd,CACA,GAAMC,CAAAA,OAAO,CAAGF,KAAK,CAACC,MAAN,CAAsB,CAACN,QAAvB,CAAhB,CAEA,GAAMQ,CAAAA,IAAI,CAAGH,KAAK,CAACI,WAAN,CAAkB,UAAM,CACjC,GAAIF,OAAO,CAACG,OAAZ,CAAqB,CACjB,OACH,CAEDN,KAAK,CAACM,OAAN,EAAiBC,YAAY,CAACP,KAAK,CAACM,OAAP,CAA7B,CACAN,KAAK,CAACM,OAAN,CAAgBE,UAAU,CAAC,UAAM,CAC7BX,eAAe,CACTE,kBAAkB,CAACU,IAAnB,CAAwB,CAAEC,UAAU,CAAEN,IAAd,CAAxB,CADS,CAETL,kBAAkB,CAACY,IAAnB,CAAwB,CAAED,UAAU,CAAEN,IAAd,CAAxB,CAFN,CAGH,CAJyB,CAIvBN,gBAJuB,CAA1B,CAKH,CAXY,CAWV,CAACD,eAAD,CAAkBC,gBAAlB,CAAoCC,kBAApC,CAXU,CAAb,CAaA,GAAMa,CAAAA,KAAK,CAAGX,KAAK,CAACI,WAAN,CAAkB,UAAM,CAClC,GAAI,CAACT,QAAL,CAAe,CACX,OACH,CACDI,KAAK,CAACM,OAAN,EAAiBC,YAAY,CAACP,KAAK,CAACM,OAAP,CAA7B,CACAH,OAAO,CAACG,OAAR,CAAkB,IAAlB,CACH,CANa,CAMX,CAACV,QAAD,CANW,CAAd,CAQA,GAAMiB,CAAAA,KAAK,CAAGZ,KAAK,CAACI,WAAN,CAAkB,UAAM,CAClC,GAAI,CAACT,QAAL,CAAe,CACX,OACH,CACDO,OAAO,CAACG,OAAR,CAAkB,KAAlB,CACAF,IAAI,GACP,CANa,CAMX,CAACA,IAAD,CAAOR,QAAP,CANW,CAAd,CAQAK,KAAK,CAACa,SAAN,CAAgB,UAAM,CAClB,GAAIlB,QAAJ,CAAc,CACViB,KAAK,GACR,CAFD,IAEO,CACHD,KAAK,GACR,CACD,MAAOA,CAAAA,KAAP,CACH,CAPD,CAOG,CAACA,KAAD,CAAQC,KAAR,CAAejB,QAAf,CAPH,EASA,MAAO,CACHgB,KAAK,CAALA,KADG,CAEHC,KAAK,CAALA,KAFG,CAAP,CAIH","sourcesContent":["import * as React from 'react';\nimport type { ICarouselController } from './useCarouselController';\n\nexport function useAutoPlay(opts: {\n autoPlay?: boolean;\n autoPlayInterval?: number;\n autoPlayReverse?: boolean;\n carouselController: ICarouselController;\n}) {\n const {\n autoPlay = false,\n autoPlayReverse = false,\n autoPlayInterval,\n carouselController,\n } = opts;\n\n const timer = React.useRef<NodeJS.Timer>();\n const stopped = React.useRef<boolean>(!autoPlay);\n\n const play = React.useCallback(() => {\n if (stopped.current) {\n return;\n }\n\n timer.current && clearTimeout(timer.current);\n timer.current = setTimeout(() => {\n autoPlayReverse\n ? carouselController.prev({ onFinished: play })\n : carouselController.next({ onFinished: play });\n }, autoPlayInterval);\n }, [autoPlayReverse, autoPlayInterval, carouselController]);\n\n const pause = React.useCallback(() => {\n if (!autoPlay) {\n return;\n }\n timer.current && clearTimeout(timer.current);\n stopped.current = true;\n }, [autoPlay]);\n\n const start = React.useCallback(() => {\n if (!autoPlay) {\n return;\n }\n stopped.current = false;\n play();\n }, [play, autoPlay]);\n\n React.useEffect(() => {\n if (autoPlay) {\n start();\n } else {\n pause();\n }\n return pause;\n }, [pause, start, autoPlay]);\n\n return {\n pause,\n start,\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireDefault(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");function useCarouselController(options){var size=options.size,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$disable=options.disable,disable=_options$disable===void 0?false:_options$disable,originalLength=options.originalLength,length=options.length,onChange=options.onChange,duration=options.duration;var index=(0,_reactNativeReanimated.useSharedValue)(0);var sharedIndex=_react.default.useRef(0);var sharedPreIndex=_react.default.useRef(0);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?length-fixed:0));},[handlerOffsetX,length,size,loop]);var convertToSharedIndex=_react.default.useCallback(function(i){if(loop){switch(originalLength){case 1:return 0;case 2:return i%2;}}return i;},[originalLength,loop]);var computedIndex=_react.default.useCallback(function(){sharedPreIndex.current=sharedIndex.current;var toInt=handlerOffsetX.value/size%length;var i=handlerOffsetX.value<=0?Math.abs(toInt):Math.abs(toInt>0?length-toInt:0);index.value=i;var _sharedIndex=convertToSharedIndex(i);sharedIndex.current=_sharedIndex;onChange(_sharedIndex);},[length,handlerOffsetX,sharedPreIndex,index,size,sharedIndex,convertToSharedIndex,onChange]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!disable;},[disable]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (127:29)";global.__reanimatedWorkletInit(_f);return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (125:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,length:length,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,length,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=260250463458;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (149:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[canSliding,loop,index,length,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(idx){var animated=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(idx===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var offset=handlerOffsetX.value+(index.value-idx)*size;if(animated){index.value=idx;handlerOffsetX.value=scrollWithTiming(offset);}else{handlerOffsetX.value=offset;index.value=idx;(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,scrollWithTiming,onScrollEnd]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var count=opts.count,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next]);return{next:next,prev:prev,to:to,scrollTo:scrollTo,index:index,length:length,sharedIndex:sharedIndex,sharedPreIndex:sharedPreIndex,computedIndex:computedIndex,getCurrentIndex:getCurrentIndex};}
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireDefault(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");function useCarouselController(options){var size=options.size,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$disable=options.disable,disable=_options$disable===void 0?false:_options$disable,originalLength=options.originalLength,length=options.length,onChange=options.onChange,duration=options.duration,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex;var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=_react.default.useRef(defaultIndex);var sharedPreIndex=_react.default.useRef(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?length-fixed:0));},[handlerOffsetX,length,size,loop]);var convertToSharedIndex=_react.default.useCallback(function(i){if(loop){switch(originalLength){case 1:return 0;case 2:return i%2;}}return i;},[originalLength,loop]);var computedIndex=_react.default.useCallback(function(){sharedPreIndex.current=sharedIndex.current;var toInt=handlerOffsetX.value/size%length;var i=handlerOffsetX.value<=0?Math.abs(toInt):Math.abs(toInt>0?length-toInt:0);index.value=i;var _sharedIndex=convertToSharedIndex(i);sharedIndex.current=_sharedIndex;onChange(_sharedIndex);},[length,handlerOffsetX,sharedPreIndex,index,size,sharedIndex,convertToSharedIndex,onChange]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!disable;},[disable]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (129:29)";global.__reanimatedWorkletInit(_f);return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (127:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,length:length,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,length,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=260250463458;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (151:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[canSliding,loop,index,length,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(idx){var animated=arguments.length>1&&arguments[1]!==undefined?arguments[1]:false;if(idx===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var offset=handlerOffsetX.value+(index.value-idx)*size;if(animated){index.value=idx;handlerOffsetX.value=scrollWithTiming(offset);}else{handlerOffsetX.value=offset;index.value=idx;(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,scrollWithTiming,onScrollEnd]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var count=opts.count,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next]);return{next:next,prev:prev,to:to,scrollTo:scrollTo,index:index,length:length,sharedIndex:sharedIndex,sharedPreIndex:sharedPreIndex,computedIndex:computedIndex,getCurrentIndex:getCurrentIndex};}
2
2
  //# sourceMappingURL=useCarouselController.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","loop","handlerOffsetX","withAnimation","disable","originalLength","length","onChange","duration","index","sharedIndex","React","useRef","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","convertToSharedIndex","i","computedIndex","current","toInt","_sharedIndex","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","runOnJS","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","idx","offset","scrollTo","n"],"mappings":"gMAAA,oDAEA,uCACA,8DAMA,6DA8BO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CAUID,OAVJ,CACIC,IADJ,CAEIC,IAFJ,CAUIF,OAVJ,CAEIE,IAFJ,CAGIC,cAHJ,CAUIH,OAVJ,CAGIG,cAHJ,CAIIC,aAJJ,CAUIJ,OAVJ,CAIII,aAJJ,kBAUIJ,OAVJ,CAKIK,OALJ,CAKIA,OALJ,2BAKc,KALd,kBAMIC,cANJ,CAUIN,OAVJ,CAMIM,cANJ,CAOIC,MAPJ,CAUIP,OAVJ,CAOIO,MAPJ,CAQIC,QARJ,CAUIR,OAVJ,CAQIQ,QARJ,CASIC,QATJ,CAUIT,OAVJ,CASIS,QATJ,CAYA,GAAMC,CAAAA,KAA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R,OACH,CACD,GAAMS,CAAAA,CAAC,CAAGvC,IAAI,CAACC,KAAL,CAAW6B,KAAX,CAAV,CACA,GAAIS,CAAC,CAAG,CAAR,CAAW,CACPN,IAAI,CAAC,CAAEH,KAAK,CAAE9B,IAAI,CAACI,GAAL,CAASmC,CAAT,CAAT,CAAsBR,QAAQ,CAARA,QAAtB,CAAgCd,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHW,IAAI,CAAC,CAAEE,KAAK,CAAES,CAAT,CAAYR,QAAQ,CAARA,QAAZ,CAAsBd,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAZY,CAab,CAACgB,IAAD,CAAOL,IAAP,CAba,CAAjB,CAgBA,MAAO,CACHA,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHE,EAAE,CAAFA,EAHG,CAIHG,QAAQ,CAARA,QAJG,CAKH7C,KAAK,CAALA,KALG,CAMHH,MAAM,CAANA,MANG,CAOHI,WAAW,CAAXA,WAPG,CAQHG,cAAc,CAAdA,cARG,CASHU,aAAa,CAAbA,aATG,CAUHI,eAAe,CAAfA,eAVG,CAAP,CAYH","sourcesContent":["import React from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport { runOnJS, useSharedValue } from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '@/utils/dealWithAnimation';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n disable?: boolean;\n duration?: number;\n originalLength: number;\n length: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n // the length before fill data\n onChange: (index: number) => void;\n}\n\nexport interface ICarouselController {\n length: number;\n index: Animated.SharedValue<number>;\n sharedIndex: React.MutableRefObject<number>;\n sharedPreIndex: React.MutableRefObject<number>;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n computedIndex: () => void;\n getCurrentIndex: () => number;\n to: (index: number, animated?: boolean) => void;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n loop,\n handlerOffsetX,\n withAnimation,\n disable = false,\n originalLength,\n length,\n onChange,\n duration,\n } = options;\n\n const index = useSharedValue<number>(0);\n // The Index displayed to the user\n const sharedIndex = React.useRef<number>(0);\n const sharedPreIndex = React.useRef<number>(0);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? length - fixed : 0)\n );\n }, [handlerOffsetX, length, size, loop]);\n\n const convertToSharedIndex = React.useCallback(\n (i: number) => {\n if (loop) {\n switch (originalLength) {\n case 1:\n return 0;\n case 2:\n return i % 2;\n }\n }\n return i;\n },\n [originalLength, loop]\n );\n\n const computedIndex = React.useCallback(() => {\n sharedPreIndex.current = sharedIndex.current;\n const toInt = (handlerOffsetX.value / size) % length;\n const i =\n handlerOffsetX.value <= 0\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? length - toInt : 0);\n index.value = i;\n const _sharedIndex = convertToSharedIndex(i);\n sharedIndex.current = _sharedIndex;\n onChange(_sharedIndex);\n }, [\n length,\n handlerOffsetX,\n sharedPreIndex,\n index,\n size,\n sharedIndex,\n convertToSharedIndex,\n onChange,\n ]);\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !disable;\n }, [disable]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= length - 1)) return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n length,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (idx: number, animated: boolean = false) => {\n if (idx === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n\n const offset = handlerOffsetX.value + (index.value - idx) * size;\n\n if (animated) {\n index.value = idx;\n handlerOffsetX.value = scrollWithTiming(offset);\n } else {\n handlerOffsetX.value = offset;\n index.value = idx;\n runOnJS(onScrollEnd)();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n onScrollEnd,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count, animated = false, onFinished } = opts;\n if (!count) {\n return;\n }\n const n = Math.round(count);\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next]\n );\n\n return {\n next,\n prev,\n to,\n scrollTo,\n index,\n length,\n sharedIndex,\n sharedPreIndex,\n computedIndex,\n getCurrentIndex,\n };\n}\n"]}
1
+ {"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","loop","handlerOffsetX","withAnimation","disable","originalLength","length","onChange","duration","defaultIndex","index","sharedIndex","React","useRef","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","convertToSharedIndex","i","computedIndex","current","toInt","_sharedIndex","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","runOnJS","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","idx","offset","scrollTo","n"],"mappings":"gMAAA,oDAEA,uCACA,8DAMA,6DA+BO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CAWID,OAXJ,CACIC,IADJ,CAEIC,IAFJ,CAWIF,OAXJ,CAEIE,IAFJ,CAGIC,cAHJ,CAWIH,OAXJ,CAGIG,cAHJ,CAIIC,aAJJ,CAWIJ,OAXJ,CAIII,aAJJ,kBAWIJ,OAXJ,CAKIK,OALJ,CAKIA,OALJ,2BAKc,KALd,kBAMIC,cANJ,CAWIN,OAXJ,CAMIM,cANJ,CAOIC,MAPJ,CAWIP,OAXJ,CAOIO,MAPJ,CAQIC,QARJ,CAWIR,OAXJ,CAQIQ,QARJ,CASIC,QATJ,CAWI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AAf,CAAeA,QAAf,0BAA0B,KAA1B,iBAAiCd,UAAjC,CAAgDY,IAAhD,CAAiCZ,UAAjC,CACA,GAAI,CAACa,KAAL,CAAY,CACR,OACH,CACD,GAAMS,CAAAA,CAAC,CAAGvC,IAAI,CAACC,KAAL,CAAW6B,KAAX,CAAV,CACA,GAAIS,CAAC,CAAG,CAAR,CAAW,CACPN,IAAI,CAAC,CAAEH,KAAK,CAAE9B,IAAI,CAACI,GAAL,CAASmC,CAAT,CAAT,CAAsBR,QAAQ,CAARA,QAAtB,CAAgCd,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHW,IAAI,CAAC,CAAEE,KAAK,CAAES,CAAT,CAAYR,QAAQ,CAARA,QAAZ,CAAsBd,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAZY,CAab,CAACgB,IAAD,CAAOL,IAAP,CAba,CAAjB,CAgBA,MAAO,CACHA,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHE,EAAE,CAAFA,EAHG,CAIHG,QAAQ,CAARA,QAJG,CAKH7C,KAAK,CAALA,KALG,CAMHJ,MAAM,CAANA,MANG,CAOHK,WAAW,CAAXA,WAPG,CAQHG,cAAc,CAAdA,cARG,CASHU,aAAa,CAAbA,aATG,CAUHI,eAAe,CAAfA,eAVG,CAAP,CAYH","sourcesContent":["import React from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport { runOnJS, useSharedValue } from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '@/utils/dealWithAnimation';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n disable?: boolean;\n duration?: number;\n originalLength: number;\n length: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n // the length before fill data\n onChange: (index: number) => void;\n}\n\nexport interface ICarouselController {\n length: number;\n index: Animated.SharedValue<number>;\n sharedIndex: React.MutableRefObject<number>;\n sharedPreIndex: React.MutableRefObject<number>;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n computedIndex: () => void;\n getCurrentIndex: () => number;\n to: (index: number, animated?: boolean) => void;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n loop,\n handlerOffsetX,\n withAnimation,\n disable = false,\n originalLength,\n length,\n onChange,\n duration,\n defaultIndex = 0,\n } = options;\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = React.useRef<number>(defaultIndex);\n const sharedPreIndex = React.useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? length - fixed : 0)\n );\n }, [handlerOffsetX, length, size, loop]);\n\n const convertToSharedIndex = React.useCallback(\n (i: number) => {\n if (loop) {\n switch (originalLength) {\n case 1:\n return 0;\n case 2:\n return i % 2;\n }\n }\n return i;\n },\n [originalLength, loop]\n );\n\n const computedIndex = React.useCallback(() => {\n sharedPreIndex.current = sharedIndex.current;\n const toInt = (handlerOffsetX.value / size) % length;\n const i =\n handlerOffsetX.value <= 0\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? length - toInt : 0);\n index.value = i;\n const _sharedIndex = convertToSharedIndex(i);\n sharedIndex.current = _sharedIndex;\n onChange(_sharedIndex);\n }, [\n length,\n handlerOffsetX,\n sharedPreIndex,\n index,\n size,\n sharedIndex,\n convertToSharedIndex,\n onChange,\n ]);\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !disable;\n }, [disable]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= length - 1)) return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n length,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (idx: number, animated: boolean = false) => {\n if (idx === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n\n const offset = handlerOffsetX.value + (index.value - idx) * size;\n\n if (animated) {\n index.value = idx;\n handlerOffsetX.value = scrollWithTiming(offset);\n } else {\n handlerOffsetX.value = offset;\n index.value = idx;\n runOnJS(onScrollEnd)();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n onScrollEnd,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count, animated = false, onFinished } = opts;\n if (!count) {\n return;\n }\n const n = Math.round(count);\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next]\n );\n\n return {\n next,\n prev,\n to,\n scrollTo,\n index,\n length,\n sharedIndex,\n sharedPreIndex,\n computedIndex,\n getCurrentIndex,\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCommonVariables=useCommonVariables;var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=require("react-native-reanimated");function useCommonVariables(props){var vertical=props.vertical,height=props.height,width=props.width,data=props.data,defaultIndex=props.defaultIndex;var size=vertical?height:width;var validLength=data.length-1;var defaultHandlerOffsetX=-Math.abs(defaultIndex*size);var handlerOffsetX=(0,_reactNativeReanimated.useSharedValue)(defaultHandlerOffsetX);_react.default.useEffect(function(){handlerOffsetX.value=defaultHandlerOffsetX;},[vertical,handlerOffsetX,defaultHandlerOffsetX]);return{size:size,validLength:validLength,handlerOffsetX:handlerOffsetX};}
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCommonVariables=useCommonVariables;var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=require("react-native-reanimated");function useCommonVariables(props){var vertical=props.vertical,height=props.height,width=props.width,data=props.data,defaultIndex=props.defaultIndex,rawData=props.rawData;var size=vertical?height:width;var validLength=data.length-1;var defaultHandlerOffsetX=-Math.abs(defaultIndex*size);var handlerOffsetX=(0,_reactNativeReanimated.useSharedValue)(defaultHandlerOffsetX);_react.default.useEffect(function(){handlerOffsetX.value=defaultHandlerOffsetX;},[vertical,handlerOffsetX,defaultHandlerOffsetX,rawData]);return{size:size,validLength:validLength,handlerOffsetX:handlerOffsetX};}
2
2
  //# sourceMappingURL=useCommonVariables.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useCommonVariables.ts"],"names":["useCommonVariables","props","vertical","height","width","data","defaultIndex","size","validLength","length","defaultHandlerOffsetX","Math","abs","handlerOffsetX","React","useEffect","value"],"mappings":"0LAAA,oDACA,8DASO,QAASA,CAAAA,kBAAT,CACHC,KADG,CAEa,CAChB,GAAQC,CAAAA,QAAR,CAAwDD,KAAxD,CAAQC,QAAR,CAAkBC,MAAlB,CAAwDF,KAAxD,CAAkBE,MAAlB,CAA0BC,KAA1B,CAAwDH,KAAxD,CAA0BG,KAA1B,CAAiCC,IAAjC,CAAwDJ,KAAxD,CAAiCI,IAAjC,CAAuCC,YAAvC,CAAwDL,KAAxD,CAAuCK,YAAvC,CACA,GAAMC,CAAAA,IAAI,CAAGL,QAAQ,CAAGC,MAAH,CAAYC,KAAjC,CACA,GAAMI,CAAAA,WAAW,CAAGH,IAAI,CAACI,MAAL,CAAc,CAAlC,CACA,GAAMC,CAAAA,qBAAqB,CAAG,CAACC,IAAI,CAACC,GAAL,CAASN,YAAY,CAAGC,IAAxB,CAA/B,CACA,GAAMM,CAAAA,cAAc,CAAG,0CAAuBH,qBAAvB,CAAvB,CAEAI,eAAMC,SAAN,CAAgB,UAAM,CAClBF,cAAc,CAACG,KAAf,CAAuBN,qBAAvB,CACH,CAFD,CAEG,CAACR,QAAD,CAAWW,cAAX,CAA2BH,qBAA3B,CAFH,EAIA,MAAO,CACHH,IAAI,CAAJA,IADG,CAEHC,WAAW,CAAXA,WAFG,CAGHK,cAAc,CAAdA,cAHG,CAAP,CAKH","sourcesContent":["import React from 'react';\nimport Animated, { useSharedValue } from 'react-native-reanimated';\nimport type { TInitializeCarouselProps } from './useInitProps';\n\ninterface ICommonVariables {\n size: number;\n validLength: number;\n handlerOffsetX: Animated.SharedValue<number>;\n}\n\nexport function useCommonVariables(\n props: TInitializeCarouselProps<any>\n): ICommonVariables {\n const { vertical, height, width, data, defaultIndex } = props;\n const size = vertical ? height : width;\n const validLength = data.length - 1;\n const defaultHandlerOffsetX = -Math.abs(defaultIndex * size);\n const handlerOffsetX = useSharedValue<number>(defaultHandlerOffsetX);\n\n React.useEffect(() => {\n handlerOffsetX.value = defaultHandlerOffsetX;\n }, [vertical, handlerOffsetX, defaultHandlerOffsetX]);\n\n return {\n size,\n validLength,\n handlerOffsetX,\n };\n}\n"]}
1
+ {"version":3,"sources":["useCommonVariables.ts"],"names":["useCommonVariables","props","vertical","height","width","data","defaultIndex","rawData","size","validLength","length","defaultHandlerOffsetX","Math","abs","handlerOffsetX","React","useEffect","value"],"mappings":"0LAAA,oDACA,8DASO,QAASA,CAAAA,kBAAT,CACHC,KADG,CAEa,CAChB,GAAQC,CAAAA,QAAR,CAAiED,KAAjE,CAAQC,QAAR,CAAkBC,MAAlB,CAAiEF,KAAjE,CAAkBE,MAAlB,CAA0BC,KAA1B,CAAiEH,KAAjE,CAA0BG,KAA1B,CAAiCC,IAAjC,CAAiEJ,KAAjE,CAAiCI,IAAjC,CAAuCC,YAAvC,CAAiEL,KAAjE,CAAuCK,YAAvC,CAAqDC,OAArD,CAAiEN,KAAjE,CAAqDM,OAArD,CACA,GAAMC,CAAAA,IAAI,CAAGN,QAAQ,CAAGC,MAAH,CAAYC,KAAjC,CACA,GAAMK,CAAAA,WAAW,CAAGJ,IAAI,CAACK,MAAL,CAAc,CAAlC,CACA,GAAMC,CAAAA,qBAAqB,CAAG,CAACC,IAAI,CAACC,GAAL,CAASP,YAAY,CAAGE,IAAxB,CAA/B,CACA,GAAMM,CAAAA,cAAc,CAAG,0CAAuBH,qBAAvB,CAAvB,CAEAI,eAAMC,SAAN,CAAgB,UAAM,CAClBF,cAAc,CAACG,KAAf,CAAuBN,qBAAvB,CACH,CAFD,CAEG,CAACT,QAAD,CAAWY,cAAX,CAA2BH,qBAA3B,CAAkDJ,OAAlD,CAFH,EAIA,MAAO,CACHC,IAAI,CAAJA,IADG,CAEHC,WAAW,CAAXA,WAFG,CAGHK,cAAc,CAAdA,cAHG,CAAP,CAKH","sourcesContent":["import React from 'react';\nimport Animated, { useSharedValue } from 'react-native-reanimated';\nimport type { TInitializeCarouselProps } from './useInitProps';\n\ninterface ICommonVariables {\n size: number;\n validLength: number;\n handlerOffsetX: Animated.SharedValue<number>;\n}\n\nexport function useCommonVariables(\n props: TInitializeCarouselProps<any>\n): ICommonVariables {\n const { vertical, height, width, data, defaultIndex, rawData } = props;\n const size = vertical ? height : width;\n const validLength = data.length - 1;\n const defaultHandlerOffsetX = -Math.abs(defaultIndex * size);\n const handlerOffsetX = useSharedValue<number>(defaultHandlerOffsetX);\n\n React.useEffect(() => {\n handlerOffsetX.value = defaultHandlerOffsetX;\n }, [vertical, handlerOffsetX, defaultHandlerOffsetX, rawData]);\n\n return {\n size,\n validLength,\n handlerOffsetX,\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useInitProps=useInitProps;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _react=_interopRequireDefault(require("react"));var _constants=require("../constants");function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}function useInitProps(props){var _props$enableSnap;var _props$defaultIndex=props.defaultIndex,defaultIndex=_props$defaultIndex===void 0?0:_props$defaultIndex,_props$data=props.data,rawData=_props$data===void 0?[]:_props$data,_props$loop=props.loop,loop=_props$loop===void 0?true:_props$loop,_props$enabled=props.enabled,enabled=_props$enabled===void 0?true:_props$enabled,_props$autoPlayInterv=props.autoPlayInterval,_autoPlayInterval=_props$autoPlayInterv===void 0?1000:_props$autoPlayInterv,_props$scrollAnimatio=props.scrollAnimationDuration,scrollAnimationDuration=_props$scrollAnimatio===void 0?500:_props$scrollAnimatio,_props$style=props.style,style=_props$style===void 0?{}:_props$style,_props$panGestureHand=props.panGestureHandlerProps,panGestureHandlerProps=_props$panGestureHand===void 0?{}:_props$panGestureHand,_props$pagingEnabled=props.pagingEnabled,pagingEnabled=_props$pagingEnabled===void 0?true:_props$pagingEnabled,_props$snapEnabled=props.snapEnabled,snapEnabled=_props$snapEnabled===void 0?(_props$enableSnap=props.enableSnap)!=null?_props$enableSnap:true:_props$snapEnabled,_width=props.width,_height=props.height;var width=Math.round(_width||0);var height=Math.round(_height||0);var autoPlayInterval=Math.max(_autoPlayInterval,0);var data=_react.default.useMemo(function(){if(!loop)return rawData;if(rawData.length===_constants.DATA_LENGTH.SINGLE_ITEM){return[rawData[0],rawData[0],rawData[0]];}if(rawData.length===_constants.DATA_LENGTH.DOUBLE_ITEM){return[rawData[0],rawData[1],rawData[0],rawData[1]];}return rawData;},[rawData,loop]);if(props.mode==='vertical-stack'||props.mode==='horizontal-stack'){var _props$modeConfig$sho,_props$modeConfig;if(!props.modeConfig){props.modeConfig={};}props.modeConfig.showLength=(_props$modeConfig$sho=(_props$modeConfig=props.modeConfig)==null?void 0:_props$modeConfig.showLength)!=null?_props$modeConfig$sho:data.length-1;}return _objectSpread(_objectSpread({},props),{},{defaultIndex:defaultIndex,data:data,rawData:rawData,loop:loop,enabled:enabled,autoPlayInterval:autoPlayInterval,scrollAnimationDuration:scrollAnimationDuration,style:style,panGestureHandlerProps:panGestureHandlerProps,pagingEnabled:pagingEnabled,snapEnabled:snapEnabled,width:width,height:height});}
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useInitProps=useInitProps;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _react=_interopRequireDefault(require("react"));function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);enumerableOnly&&(symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;})),keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=null!=arguments[i]?arguments[i]:{};i%2?ownKeys(Object(source),!0).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);}):Object.getOwnPropertyDescriptors?Object.defineProperties(target,Object.getOwnPropertyDescriptors(source)):ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}return target;}function useInitProps(props){var _props$enableSnap;var _props$defaultIndex=props.defaultIndex,defaultIndex=_props$defaultIndex===void 0?0:_props$defaultIndex,_props$data=props.data,rawData=_props$data===void 0?[]:_props$data,_props$loop=props.loop,loop=_props$loop===void 0?true:_props$loop,_props$enabled=props.enabled,enabled=_props$enabled===void 0?true:_props$enabled,_props$autoPlayInterv=props.autoPlayInterval,_autoPlayInterval=_props$autoPlayInterv===void 0?1000:_props$autoPlayInterv,_props$scrollAnimatio=props.scrollAnimationDuration,scrollAnimationDuration=_props$scrollAnimatio===void 0?500:_props$scrollAnimatio,_props$style=props.style,style=_props$style===void 0?{}:_props$style,_props$panGestureHand=props.panGestureHandlerProps,panGestureHandlerProps=_props$panGestureHand===void 0?{}:_props$panGestureHand,_props$pagingEnabled=props.pagingEnabled,pagingEnabled=_props$pagingEnabled===void 0?true:_props$pagingEnabled,_props$autoFillData=props.autoFillData,autoFillData=_props$autoFillData===void 0?true:_props$autoFillData,_props$snapEnabled=props.snapEnabled,snapEnabled=_props$snapEnabled===void 0?(_props$enableSnap=props.enableSnap)!=null?_props$enableSnap:true:_props$snapEnabled,_width=props.width,_height=props.height;var width=Math.round(_width||0);var height=Math.round(_height||0);var autoPlayInterval=Math.max(_autoPlayInterval,0);var data=_react.default.useMemo(function(){return(0,_computedWithAutoFillData.computedFillDataWithAutoFillData)({loop:loop,autoFillData:autoFillData,data:rawData,dataLength:rawData.length});},[rawData,loop,autoFillData]);if(props.mode==='vertical-stack'||props.mode==='horizontal-stack'){var _props$modeConfig$sho,_props$modeConfig;if(!props.modeConfig){props.modeConfig={};}props.modeConfig.showLength=(_props$modeConfig$sho=(_props$modeConfig=props.modeConfig)==null?void 0:_props$modeConfig.showLength)!=null?_props$modeConfig$sho:data.length-1;}return _objectSpread(_objectSpread({},props),{},{defaultIndex:defaultIndex,autoFillData:autoFillData,data:data,rawData:rawData,loop:loop,enabled:enabled,autoPlayInterval:autoPlayInterval,scrollAnimationDuration:scrollAnimationDuration,style:style,panGestureHandlerProps:panGestureHandlerProps,pagingEnabled:pagingEnabled,snapEnabled:snapEnabled,width:width,height:height});}
2
2
  //# sourceMappingURL=useInitProps.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useInitProps.ts"],"names":["useInitProps","props","defaultIndex","data","rawData","loop","enabled","autoPlayInterval","_autoPlayInterval","scrollAnimationDuration","style","panGestureHandlerProps","pagingEnabled","snapEnabled","enableSnap","_width","width","_height","height","Math","round","max","React","useMemo","length","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","mode","modeConfig","showLength"],"mappings":"4QA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AAD,CAAR,CAAaA,OAAO,CAAC,CAAD,CAApB,CAAyBA,OAAO,CAAC,CAAD,CAAhC,CAAP,CACH,CAED,GAAIA,OAAO,CAACoB,MAAR,GAAmBC,uBAAYE,WAAnC,CAAgD,CAC5C,MAAO,CAACvB,OAAO,CAAC,CAAD,CAAR,CAAaA,OAAO,CAAC,CAAD,CAApB,CAAyBA,OAAO,CAAC,CAAD,CAAhC,CAAqCA,OAAO,CAAC,CAAD,CAA5C,CAAP,CACH,CAED,MAAOA,CAAAA,OAAP,CACH,CAZY,CAYV,CAACA,OAAD,CAAUC,IAAV,CAZU,CAAb,CAcA,GAAIJ,KAAK,CAAC2B,IAAN,GAAe,gBAAf,EAAmC3B,KAAK,CAAC2B,IAAN,GAAe,kBAAtD,CAA0E,6CACtE,GAAI,CAAC3B,KAAK,CAAC4B,UAAX,CAAuB,CACnB5B,KAAK,CAAC4B,UAAN,CAAmB,EAAnB,CACH,CACD5B,KAAK,CAAC4B,UAAN,CAAiBC,UAAjB,2CACI7B,KAAK,CAAC4B,UADV,eACI,kBAAkBC,UADtB,8BACoC3B,IAAI,CAACqB,MAAL,CAAc,CADlD,CAEH,CACD,sCACOvB,KADP,MAEIC,YAAY,CAAZA,YAFJ,CAGIC,IAAI,CAAJA,IAHJ,CAIIC,OAAO,CAAPA,OAJJ,CAKIC,IAAI,CAAJA,IALJ,CAMIC,OAAO,CAAPA,OANJ,CAOIC,gBAAgB,CAAhBA,gBAPJ,CAQIE,uBAAuB,CAAvBA,uBARJ,CASIC,KAAK,CAALA,KATJ,CAUIC,sBAAsB,CAAtBA,sBAVJ,CAWIC,aAAa,CAAbA,aAXJ,CAYIC,WAAW,CAAXA,WAZJ,CAaIG,KAAK,CAALA,KAbJ,CAcIE,MAAM,CAANA,MAdJ,GAgBH","sourcesContent":["import React from 'react';\nimport { DATA_LENGTH } from '../constants';\nimport type { TCarouselProps } from '../types';\n\ntype TGetRequiredProps<P extends keyof TCarouselProps> = Record<\n P,\n Required<TCarouselProps>[P]\n>;\n\nexport type TInitializeCarouselProps<T> = TCarouselProps<T> &\n TGetRequiredProps<\n | 'defaultIndex'\n | 'loop'\n | 'width'\n | 'height'\n | 'scrollAnimationDuration'\n | 'autoPlayInterval'\n > & {\n // Raw data that has not been processed\n rawData: T[];\n };\n\nexport function useInitProps<T>(\n props: TCarouselProps<T>\n): TInitializeCarouselProps<T> {\n const {\n defaultIndex = 0,\n data: rawData = [],\n loop = true,\n enabled = true,\n autoPlayInterval: _autoPlayInterval = 1000,\n scrollAnimationDuration = 500,\n style = {},\n panGestureHandlerProps = {},\n pagingEnabled = true,\n snapEnabled = props.enableSnap ?? true,\n width: _width,\n height: _height,\n } = props;\n\n const width = Math.round(_width || 0);\n const height = Math.round(_height || 0);\n const autoPlayInterval = Math.max(_autoPlayInterval, 0);\n\n const data = React.useMemo<T[]>(() => {\n if (!loop) return rawData;\n\n if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {\n return [rawData[0], rawData[0], rawData[0]];\n }\n\n if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {\n return [rawData[0], rawData[1], rawData[0], rawData[1]];\n }\n\n return rawData;\n }, [rawData, loop]);\n\n if (props.mode === 'vertical-stack' || props.mode === 'horizontal-stack') {\n if (!props.modeConfig) {\n props.modeConfig = {};\n }\n props.modeConfig.showLength =\n props.modeConfig?.showLength ?? data.length - 1;\n }\n return {\n ...props,\n defaultIndex,\n data,\n rawData,\n loop,\n enabled,\n autoPlayInterval,\n scrollAnimationDuration,\n style,\n panGestureHandlerProps,\n pagingEnabled,\n snapEnabled,\n width,\n height,\n };\n}\n"]}
1
+ {"version":3,"sources":["useInitProps.ts"],"names":["useInitProps","props","defaultIndex","data","rawData","loop","enabled","autoPlayInterval","_autoPlayInterval","scrollAnimationDuration","style","panGestureHandlerProps","pagingEnabled","autoFillData","snapEnabled","enableSnap","_width","width","_height","height","Math","round","max","React","useMemo","dataLength","length","mode","modeConfig","showLength"],"mappings":"4QAAA,2EACA,oD,kxBA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AAU,CAAErB,OAAO,CAACsB,MAJY,CAApC,CADJ,EADS,CAQT,CAACtB,OAAD,CAAUC,IAAV,CAAgBQ,YAAhB,CARS,CAAb,CAWA,GAAIZ,KAAK,CAAC0B,IAAN,GAAe,gBAAf,EAAmC1B,KAAK,CAAC0B,IAAN,GAAe,kBAAtD,CAA0E,6CACtE,GAAI,CAAC1B,KAAK,CAAC2B,UAAX,CAAuB,CACnB3B,KAAK,CAAC2B,UAAN,CAAmB,EAAnB,CACH,CACD3B,KAAK,CAAC2B,UAAN,CAAiBC,UAAjB,2CACI5B,KAAK,CAAC2B,UADV,eACI,kBAAkBC,UADtB,8BACoC1B,IAAI,CAACuB,MAAL,CAAc,CADlD,CAEH,CACD,sCACOzB,KADP,MAEIC,YAAY,CAAZA,YAFJ,CAGIW,YAAY,CAAZA,YAHJ,CAIIV,IAAI,CAAJA,IAJJ,CAKIC,OAAO,CAAPA,OALJ,CAMIC,IAAI,CAAJA,IANJ,CAOIC,OAAO,CAAPA,OAPJ,CAQIC,gBAAgB,CAAhBA,gBARJ,CASIE,uBAAuB,CAAvBA,uBATJ,CAUIC,KAAK,CAALA,KAVJ,CAWIC,sBAAsB,CAAtBA,sBAXJ,CAYIC,aAAa,CAAbA,aAZJ,CAaIE,WAAW,CAAXA,WAbJ,CAcIG,KAAK,CAALA,KAdJ,CAeIE,MAAM,CAANA,MAfJ,GAiBH","sourcesContent":["import { computedFillDataWithAutoFillData } from '@/utils/computedWithAutoFillData';\nimport React from 'react';\nimport type { TCarouselProps } from '../types';\n\ntype TGetRequiredProps<P extends keyof TCarouselProps> = Record<\n P,\n Required<TCarouselProps>[P]\n>;\n\nexport type TInitializeCarouselProps<T> = TCarouselProps<T> &\n TGetRequiredProps<\n | 'defaultIndex'\n | 'loop'\n | 'width'\n | 'height'\n | 'scrollAnimationDuration'\n | 'autoPlayInterval'\n | 'autoFillData'\n > & {\n // Raw data that has not been processed\n rawData: T[];\n };\n\nexport function useInitProps<T>(\n props: TCarouselProps<T>\n): TInitializeCarouselProps<T> {\n const {\n defaultIndex = 0,\n data: rawData = [],\n loop = true,\n enabled = true,\n autoPlayInterval: _autoPlayInterval = 1000,\n scrollAnimationDuration = 500,\n style = {},\n panGestureHandlerProps = {},\n pagingEnabled = true,\n autoFillData = true,\n snapEnabled = props.enableSnap ?? true,\n width: _width,\n height: _height,\n } = props;\n\n const width = Math.round(_width || 0);\n const height = Math.round(_height || 0);\n const autoPlayInterval = Math.max(_autoPlayInterval, 0);\n\n const data = React.useMemo<T[]>(\n () =>\n computedFillDataWithAutoFillData<T>({\n loop,\n autoFillData,\n data: rawData,\n dataLength: rawData.length,\n }),\n [rawData, loop, autoFillData]\n );\n\n if (props.mode === 'vertical-stack' || props.mode === 'horizontal-stack') {\n if (!props.modeConfig) {\n props.modeConfig = {};\n }\n props.modeConfig.showLength =\n props.modeConfig?.showLength ?? data.length - 1;\n }\n return {\n ...props,\n defaultIndex,\n autoFillData,\n data,\n rawData,\n loop,\n enabled,\n autoPlayInterval,\n scrollAnimationDuration,\n style,\n panGestureHandlerProps,\n pagingEnabled,\n snapEnabled,\n width,\n height,\n };\n}\n"]}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.useOnProgressChange=useOnProgressChange;var _reactNativeReanimated=require("react-native-reanimated");var _constants=require("../constants");function useOnProgressChange(opts){var offsetX=opts.offsetX,rawData=opts.rawData,size=opts.size,onProgressChange=opts.onProgressChange;var rawDataLength=rawData.length;(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return offsetX.value;};_f._closure={offsetX:offsetX};_f.asString="function _f(){const{offsetX}=jsThis._closure;{return offsetX.value;}}";_f.__workletHash=11091407603539;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOnProgressChange.ts (18:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(_value){var value=_value;if(rawDataLength===_constants.DATA_LENGTH.SINGLE_ITEM){value=value%size;}if(rawDataLength===_constants.DATA_LENGTH.DOUBLE_ITEM){value=value%(size*2);}var absoluteProgress=Math.abs(value/size);if(value>0){absoluteProgress=rawDataLength-absoluteProgress;}!!onProgressChange&&(0,_reactNativeReanimated.runOnJS)(onProgressChange)(value,absoluteProgress);};_f._closure={rawDataLength:rawDataLength,DATA_LENGTH:{SINGLE_ITEM:_constants.DATA_LENGTH.SINGLE_ITEM,DOUBLE_ITEM:_constants.DATA_LENGTH.DOUBLE_ITEM},size:size,onProgressChange:onProgressChange,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(_value){const{rawDataLength,DATA_LENGTH,size,onProgressChange,runOnJS}=jsThis._closure;{let value=_value;if(rawDataLength===DATA_LENGTH.SINGLE_ITEM){value=value%size;}if(rawDataLength===DATA_LENGTH.DOUBLE_ITEM){value=value%(size*2);}let absoluteProgress=Math.abs(value/size);if(value>0){absoluteProgress=rawDataLength-absoluteProgress;}!!onProgressChange&&runOnJS(onProgressChange)(value,absoluteProgress);}}";_f.__workletHash=13919234910402;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOnProgressChange.ts (19:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[onProgressChange,rawDataLength]);}
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.useOnProgressChange=useOnProgressChange;var _reactNativeReanimated=require("react-native-reanimated");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");function useOnProgressChange(opts){var autoFillData=opts.autoFillData,loop=opts.loop,offsetX=opts.offsetX,rawData=opts.rawData,size=opts.size,onProgressChange=opts.onProgressChange;var rawDataLength=rawData.length;(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return offsetX.value;};_f._closure={offsetX:offsetX};_f.asString="function _f(){const{offsetX}=jsThis._closure;{return offsetX.value;}}";_f.__workletHash=11091407603539;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOnProgressChange.ts (23:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(_value){var value=(0,_computedWithAutoFillData.computedOffsetXValueWithAutoFillData)({value:_value,rawDataLength:rawDataLength,size:size,autoFillData:autoFillData,loop:loop});if(!loop){value=Math.max(-((rawDataLength-1)*size),Math.min(value,0));}var absoluteProgress=Math.abs(value/size);if(value>0){absoluteProgress=rawDataLength-absoluteProgress;}!!onProgressChange&&(0,_reactNativeReanimated.runOnJS)(onProgressChange)(value,absoluteProgress);};_f._closure={computedOffsetXValueWithAutoFillData:_computedWithAutoFillData.computedOffsetXValueWithAutoFillData,rawDataLength:rawDataLength,size:size,autoFillData:autoFillData,loop:loop,onProgressChange:onProgressChange,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(_value){const{computedOffsetXValueWithAutoFillData,rawDataLength,size,autoFillData,loop,onProgressChange,runOnJS}=jsThis._closure;{let value=computedOffsetXValueWithAutoFillData({value:_value,rawDataLength:rawDataLength,size:size,autoFillData:autoFillData,loop:loop});if(!loop){value=Math.max(-((rawDataLength-1)*size),Math.min(value,0));}let absoluteProgress=Math.abs(value/size);if(value>0){absoluteProgress=rawDataLength-absoluteProgress;}!!onProgressChange&&runOnJS(onProgressChange)(value,absoluteProgress);}}";_f.__workletHash=10178584953814;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOnProgressChange.ts (24:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,autoFillData,rawDataLength,onProgressChange]);}
2
2
  //# sourceMappingURL=useOnProgressChange.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useOnProgressChange.ts"],"names":["useOnProgressChange","opts","offsetX","rawData","size","onProgressChange","rawDataLength","length","value","_value","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","absoluteProgress","Math","abs","runOnJS"],"mappings":"yGAAA,8DAIA,uCAGO,QAASA,CAAAA,mBAAT,CACHC,IADG,CAML,CACE,GAAQC,CAAAA,OAAR,CAAqDD,IAArD,CAAQC,OAAR,CAAiBC,OAAjB,CAAqDF,IAArD,CAAiBE,OAAjB,CAA0BC,IAA1B,CAAqDH,IAArD,CAA0BG,IAA1B,CAAgCC,gBAAhC,CAAqDJ,IAArD,CAAgCI,gBAAhC,CACA,GAAMC,CAAAA,aAAa,CAAGH,OAAO,CAACI,MAA9B,CACA,iEACI,oBAAML,CAAAA,OAAO,CAACM,KAAd,EADJ,sBAfGN,OAeH,sTAEKO,MAFL,CAEgB,CACR,GAAID,CAAAA,KAAK,CAAGC,MAAZ,CAEA,GAAIH,aAAa,GAAKI,uBAAYC,WAAlC,CAA+C,CAC3CH,KAAK,CAAGA,KAAK,CAAGJ,IAAhB,CACH,CAED,GAAIE,aAAa,GAAKI,uBAAYE,WAAlC,CAA+C,CAC3CJ,KAAK,CAAGA,KAAK,EAAIJ,IAAI,CAAG,CAAX,CAAb,CACH,CAED,GAAIS,CAAAA,gBAAgB,CAAGC,IAAI,CAACC,GAAL,CAASP,KAAK,CAAGJ,IAAjB,CAAvB,CAEA,GAAII,KAAK,CAAG,CAAZ,CAAe,CACXK,gBAAgB,CAAGP,aAAa,CAAGO,gBAAnC,CACH,CAED,CAAC,CAACR,gBAAF,EACI,mCAAQA,gBAAR,EAA0BG,KAA1B,CAAiCK,gBAAjC,CADJ,CAEH,CArBL,4BADmBP,aACnB,0BAZoBI,uBAAYC,WAYhC,aARoBD,uBAAYE,WAQhC,OAJsCR,IAItC,kBAE4BC,gBAF5B,SAEoBW,8BAFpB,unBAsBI,CAACX,gBAAD,CAAmBC,aAAnB,CAtBJ,EAwBH","sourcesContent":["import Animated, {\n runOnJS,\n useAnimatedReaction,\n} from 'react-native-reanimated';\nimport { DATA_LENGTH } from '../constants';\nimport type { TCarouselProps } from '../types';\n\nexport function useOnProgressChange(\n opts: {\n size: number;\n offsetX: Animated.SharedValue<number>;\n rawData: TCarouselProps['data'];\n } & Pick<TCarouselProps, 'onProgressChange'>\n) {\n const { offsetX, rawData, size, onProgressChange } = opts;\n const rawDataLength = rawData.length;\n useAnimatedReaction(\n () => offsetX.value,\n (_value) => {\n let value = _value;\n\n if (rawDataLength === DATA_LENGTH.SINGLE_ITEM) {\n value = value % size;\n }\n\n if (rawDataLength === DATA_LENGTH.DOUBLE_ITEM) {\n value = value % (size * 2);\n }\n\n let absoluteProgress = Math.abs(value / size);\n\n if (value > 0) {\n absoluteProgress = rawDataLength - absoluteProgress;\n }\n\n !!onProgressChange &&\n runOnJS(onProgressChange)(value, absoluteProgress);\n },\n [onProgressChange, rawDataLength]\n );\n}\n"]}
1
+ {"version":3,"sources":["useOnProgressChange.ts"],"names":["useOnProgressChange","opts","autoFillData","loop","offsetX","rawData","size","onProgressChange","rawDataLength","length","value","_value","Math","max","min","absoluteProgress","abs","computedOffsetXValueWithAutoFillData","runOnJS"],"mappings":"yGAAA,8DAIA,2EAGO,QAASA,CAAAA,mBAAT,CACHC,IADG,CAQL,CACE,GAAQC,CAAAA,YAAR,CACID,IADJ,CAAQC,YAAR,CAAsBC,IAAtB,CACIF,IADJ,CAAsBE,IAAtB,CAA4BC,OAA5B,CACIH,IADJ,CAA4BG,OAA5B,CAAqCC,OAArC,CACIJ,IADJ,CAAqCI,OAArC,CAA8CC,IAA9C,CACIL,IADJ,CAA8CK,IAA9C,CAAoDC,gBAApD,CACIN,IADJ,CAAoDM,gBAApD,CAGA,GAAMC,CAAAA,aAAa,CAAGH,OAAO,CAACI,MAA9B,CAEA,iEACI,oBAAML,CAAAA,OAAO,CAACM,KAAd,EADJ,sBApBGN,OAoBH,sTAEKO,MAFL,CAEgB,CACR,GAAID,CAAAA,KAAK,CAAG,mEAAqC,CAC7CA,KAAK,CAAEC,MADsC,CAE7CH,aAAa,CAAbA,aAF6C,CAG7CF,IAAI,CAAJA,IAH6C,CAI7CJ,YAAY,CAAZA,YAJ6C,CAK7CC,IAAI,CAAJA,IAL6C,CAArC,CAAZ,CAQA,GAAI,CAACA,IAAL,CAAW,CACPO,KAAK,CAAGE,IAAI,CAACC,GAAL,CACJ,EAAE,CAACL,aAAa,CAAG,CAAjB,EAAsBF,IAAxB,CADI,CAEJM,IAAI,CAACE,GAAL,CAASJ,KAAT,CAAgB,CAAhB,CAFI,CAAR,CAIH,CAED,GAAIK,CAAAA,gBAAgB,CAAGH,IAAI,CAACI,GAAL,CAASN,KAAK,CAAGJ,IAAjB,CAAvB,CAEA,GAAII,KAAK,CAAG,CAAZ,CAAe,CACXK,gBAAgB,CAAGP,aAAa,CAAGO,gBAAnC,CACH,CAED,CAAC,CAACR,gBAAF,EACI,mCAAQA,gBAAR,EAA0BG,KAA1B,CAAiCK,gBAAjC,CADJ,CAEH,CA1BL,mDAnBUE,8DAmBV,eAJmBT,aAInB,MAPsCF,IAOtC,cAfAJ,YAeA,MAXGC,IAWH,kBAD4BI,gBAC5B,SADoBW,8BACpB,iuBA2BI,CAACf,IAAD,CAAOD,YAAP,CAAqBM,aAArB,CAAoCD,gBAApC,CA3BJ,EA6BH","sourcesContent":["import Animated, {\n runOnJS,\n useAnimatedReaction,\n} from 'react-native-reanimated';\nimport { computedOffsetXValueWithAutoFillData } from '@/utils/computedWithAutoFillData';\nimport type { TCarouselProps } from '../types';\n\nexport function useOnProgressChange(\n opts: {\n size: number;\n autoFillData: boolean;\n loop: boolean;\n offsetX: Animated.SharedValue<number>;\n rawData: TCarouselProps['data'];\n } & Pick<TCarouselProps, 'onProgressChange'>\n) {\n const { autoFillData, loop, offsetX, rawData, size, onProgressChange } =\n opts;\n\n const rawDataLength = rawData.length;\n\n useAnimatedReaction(\n () => offsetX.value,\n (_value) => {\n let value = computedOffsetXValueWithAutoFillData({\n value: _value,\n rawDataLength,\n size,\n autoFillData,\n loop,\n });\n\n if (!loop) {\n value = Math.max(\n -((rawDataLength - 1) * size),\n Math.min(value, 0)\n );\n }\n\n let absoluteProgress = Math.abs(value / size);\n\n if (value > 0) {\n absoluteProgress = rawDataLength - absoluteProgress;\n }\n\n !!onProgressChange &&\n runOnJS(onProgressChange)(value, absoluteProgress);\n },\n [loop, autoFillData, rawDataLength, onProgressChange]\n );\n}\n"]}
@@ -0,0 +1,2 @@
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.computedFillDataWithAutoFillData=computedFillDataWithAutoFillData;exports.computedOffsetXValueWithAutoFillData=void 0;exports.computedRealIndexWithAutoFillData=computedRealIndexWithAutoFillData;var _constants=require("../constants");var SINGLE_ITEM=_constants.DATA_LENGTH.SINGLE_ITEM,DOUBLE_ITEM=_constants.DATA_LENGTH.DOUBLE_ITEM;var isAutoFillData=function(){var _f=function _f(params){return!!params.loop&&!!params.autoFillData;};_f._closure={};_f.asString="function isAutoFillData(params){return!!params.loop&&!!params.autoFillData;}";_f.__workletHash=12581181073993;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/utils/computedWithAutoFillData.ts (5:0)";global.__reanimatedWorkletInit(_f);return _f;}();var computedOffsetXValueWithAutoFillData=function(){var _f=function _f(params){var rawDataLength=params.rawDataLength,value=params.value,size=params.size,loop=params.loop,autoFillData=params.autoFillData;if(isAutoFillData({loop:loop,autoFillData:autoFillData})){switch(rawDataLength){case SINGLE_ITEM:return value%size;case DOUBLE_ITEM:return value%(size*2);}}return value;};_f._closure={isAutoFillData:isAutoFillData,SINGLE_ITEM:SINGLE_ITEM,DOUBLE_ITEM:DOUBLE_ITEM};_f.asString="function computedOffsetXValueWithAutoFillData(params){const{isAutoFillData,SINGLE_ITEM,DOUBLE_ITEM}=jsThis._closure;{const{rawDataLength:rawDataLength,value:value,size:size,loop:loop,autoFillData:autoFillData}=params;if(isAutoFillData({loop:loop,autoFillData:autoFillData})){switch(rawDataLength){case SINGLE_ITEM:return value%size;case DOUBLE_ITEM:return value%(size*2);}}return value;}}";_f.__workletHash=8949924672961;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/utils/computedWithAutoFillData.ts (15:7)";global.__reanimatedWorkletInit(_f);return _f;}();exports.computedOffsetXValueWithAutoFillData=computedOffsetXValueWithAutoFillData;function computedRealIndexWithAutoFillData(params){var index=params.index,dataLength=params.dataLength,loop=params.loop,autoFillData=params.autoFillData;if(isAutoFillData({loop:loop,autoFillData:autoFillData})){switch(dataLength){case SINGLE_ITEM:return index%1;case DOUBLE_ITEM:return index%2;}}return index;}function computedFillDataWithAutoFillData(params){var data=params.data,loop=params.loop,autoFillData=params.autoFillData,dataLength=params.dataLength;if(isAutoFillData({loop:loop,autoFillData:autoFillData})){switch(dataLength){case SINGLE_ITEM:return[data[0],data[0],data[0]];case DOUBLE_ITEM:return[data[0],data[1],data[0],data[1]];}}return data;}
2
+ //# sourceMappingURL=computedWithAutoFillData.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["computedWithAutoFillData.ts"],"names":["SINGLE_ITEM","DATA_LENGTH","DOUBLE_ITEM","isAutoFillData","params","loop","autoFillData","computedOffsetXValueWithAutoFillData","rawDataLength","value","size","computedRealIndexWithAutoFillData","index","dataLength","computedFillDataWithAutoFillData","data"],"mappings":"mQAAA,uCAEA,GAAQA,CAAAA,WAAR,CAAqCC,sBAArC,CAAQD,WAAR,CAAqBE,WAArB,CAAqCD,sBAArC,CAAqBC,WAArB,C,GAESC,CAAAA,c,+BAAeC,M,CAAkD,CAEtE,MAAO,CAAC,CAACA,MAAM,CAACC,IAAT,EAAiB,CAAC,CAACD,MAAM,CAACE,YAAjC,CACH,C,oTAOeC,CAAAA,oC,+BACZH,M,CAKF,CAGE,GAAQI,CAAAA,aAAR,CAA2DJ,MAA3D,CAAQI,aAAR,CAAuBC,KAAvB,CAA2DL,MAA3D,CAAuBK,KAAvB,CAA8BC,IAA9B,CAA2DN,MAA3D,CAA8BM,IAA9B,CAAoCL,IAApC,CAA2DD,MAA3D,CAAoCC,IAApC,CAA0CC,YAA1C,CAA2DF,MAA3D,CAA0CE,YAA1C,CAEA,GAAIH,cAAc,CAAC,CAAEE,IAAI,CAAJA,IAAF,CAAQC,YAAY,CAAZA,YAAR,CAAD,CAAlB,CAA4C,CACxC,OAAQE,aAAR,EACI,IAAKR,CAAAA,WAAL,CACI,MAAOS,CAAAA,KAAK,CA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AAC,CAAD,CAAL,CAAUA,IAAI,CAAC,CAAD,CAAd,CAAmBA,IAAI,CAAC,CAAD,CAAvB,CAA4BA,IAAI,CAAC,CAAD,CAAhC,CAAP,CAJR,CAMH,CAED,MAAOA,CAAAA,IAAP,CACH","sourcesContent":["import { DATA_LENGTH } from 'src/constants';\n\nconst { SINGLE_ITEM, DOUBLE_ITEM } = DATA_LENGTH;\n\nfunction isAutoFillData(params: { autoFillData: boolean; loop: boolean }) {\n 'worklet';\n return !!params.loop && !!params.autoFillData;\n}\n\ntype BaseParams<T extends object = {}> = {\n autoFillData: boolean;\n loop: boolean;\n} & T;\n\nexport function computedOffsetXValueWithAutoFillData(\n params: BaseParams<{\n rawDataLength: number;\n value: number;\n size: number;\n }>\n) {\n 'worklet';\n\n const { rawDataLength, value, size, loop, autoFillData } = params;\n\n if (isAutoFillData({ loop, autoFillData })) {\n switch (rawDataLength) {\n case SINGLE_ITEM:\n return value % size;\n case DOUBLE_ITEM:\n return value % (size * 2);\n }\n }\n\n return value;\n}\n\nexport function computedRealIndexWithAutoFillData(\n params: BaseParams<{\n index: number;\n dataLength: number;\n }>\n) {\n const { index, dataLength, loop, autoFillData } = params;\n\n if (isAutoFillData({ loop, autoFillData })) {\n switch (dataLength) {\n case SINGLE_ITEM:\n return index % 1;\n case DOUBLE_ITEM:\n return index % 2;\n }\n }\n\n return index;\n}\n\nexport function computedFillDataWithAutoFillData<T>(\n params: BaseParams<{\n data: T[];\n dataLength: number;\n }>\n): T[] {\n const { data, loop, autoFillData, dataLength } = params;\n\n if (isAutoFillData({ loop, autoFillData })) {\n switch (dataLength) {\n case SINGLE_ITEM:\n return [data[0], data[0], data[0]];\n case DOUBLE_ITEM:\n return [data[0], data[1], data[0], data[1]];\n }\n }\n\n return data;\n}\n"]}