react-native-reanimated-carousel 2.3.0 → 2.3.1

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 (49) hide show
  1. package/lib/commonjs/Carousel.js +1 -1
  2. package/lib/commonjs/Carousel.js.map +1 -1
  3. package/lib/commonjs/ScrollViewGesture.js.map +1 -1
  4. package/lib/commonjs/constants/index.js.map +1 -1
  5. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  6. package/lib/commonjs/hooks/useCheckMounted.js +2 -0
  7. package/lib/commonjs/hooks/useCheckMounted.js.map +1 -0
  8. package/lib/commonjs/hooks/useInitProps.js +1 -1
  9. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  10. package/lib/commonjs/layouts/BaseLayout.js +1 -1
  11. package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
  12. package/lib/commonjs/layouts/ParallaxLayout.js +1 -1
  13. package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
  14. package/lib/commonjs/layouts/parallax.js +1 -1
  15. package/lib/commonjs/layouts/parallax.js.map +1 -1
  16. package/lib/commonjs/layouts/stack.js +1 -1
  17. package/lib/commonjs/layouts/stack.js.map +1 -1
  18. package/lib/module/Carousel.js +10 -7
  19. package/lib/module/Carousel.js.map +1 -1
  20. package/lib/module/ScrollViewGesture.js.map +1 -1
  21. package/lib/module/constants/index.js.map +1 -1
  22. package/lib/module/hooks/useCarouselController.js +8 -4
  23. package/lib/module/hooks/useCarouselController.js.map +1 -1
  24. package/lib/module/hooks/useCheckMounted.js +12 -0
  25. package/lib/module/hooks/useCheckMounted.js.map +1 -0
  26. package/lib/module/layouts/BaseLayout.js +4 -2
  27. package/lib/module/layouts/BaseLayout.js.map +1 -1
  28. package/lib/module/layouts/ParallaxLayout.js +2 -1
  29. package/lib/module/layouts/ParallaxLayout.js.map +1 -1
  30. package/lib/module/layouts/parallax.js +5 -3
  31. package/lib/module/layouts/parallax.js.map +1 -1
  32. package/lib/module/layouts/stack.js +7 -3
  33. package/lib/module/layouts/stack.js.map +1 -1
  34. package/lib/module/utils/log.js +2 -2
  35. package/lib/module/utils/log.js.map +1 -1
  36. package/lib/typescript/constants/index.d.ts +2 -1
  37. package/lib/typescript/hooks/useCheckMounted.d.ts +2 -0
  38. package/lib/typescript/layouts/ParallaxLayout.d.ts +2 -3
  39. package/lib/typescript/layouts/parallax.d.ts +8 -3
  40. package/lib/typescript/types.d.ts +4 -2
  41. package/package.json +3 -2
  42. package/src/ScrollViewGesture.tsx +2 -2
  43. package/src/constants/index.ts +7 -2
  44. package/src/hooks/useCarouselController.tsx +2 -2
  45. package/src/hooks/useCheckMounted.ts +14 -0
  46. package/src/layouts/BaseLayout.tsx +8 -5
  47. package/src/layouts/ParallaxLayout.tsx +13 -11
  48. package/src/layouts/parallax.ts +15 -7
  49. package/src/types.ts +11 -9
@@ -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);if(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=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{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 offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var totalSize=size*data.length;var x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;};_f._closure={size:size,data:data,handlerOffsetX:handlerOffsetX,loop:loop};_f.asString="function _f(){const{size,data,handlerOffsetX,loop}=jsThis._closure;{const totalSize=size*data.length;const x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;}}";_f.__workletHash=3891980848773;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx (50:40)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,size,data]);(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:158,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:186,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:[styles.container,{width:width||'100%',height:height||'100%'},style],__self:_this,__source:{fileName:_jsxFileName,lineNumber:187,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:194,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:202,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 _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 offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var totalSize=size*data.length;var x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;};_f._closure={size:size,data:data,handlerOffsetX:handlerOffsetX,loop:loop};_f.asString="function _f(){const{size,data,handlerOffsetX,loop}=jsThis._closure;{const totalSize=size*data.length;const x=handlerOffsetX.value%totalSize;if(!loop){return handlerOffsetX.value;}return isNaN(x)?0:x;}}";_f.__workletHash=3891980848773;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/Carousel.tsx (50:40)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,size,data]);(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:158,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:186,columnNumber:13}},_react.default.createElement(_reactNative.View,{style:[styles.container,{width:width||'100%',height:height||'100%'},style],__self:_this,__source:{fileName:_jsxFileName,lineNumber:187,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:194,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:202,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","offsetX","totalSize","length","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","DOU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AFG,CAMHF,KANG,CAOHG,QAAQ,CACF8D,MAAM,CAACE,aADL,CAEFF,MAAM,CAACG,eATV,CAFX,+EAcKxE,IAAI,CAACyE,GAAL,CAASb,YAAT,CAdL,CARJ,CAPJ,CADJ,CADJ,CAqCH,CA1MY,CAAjB,C,aA6MelE,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 { 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\n const offsetX = useDerivedValue(() => {\n const totalSize = size * data.length;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, data]);\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","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","commonVariables","size","handlerOffsetX","offsetX","totalSize","length","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,KANJ,CAOIC,MAPJ,CAqBIP,KArBJ,CAOIO,MAPJ,CAQIC,QARJ,CAqBIR,KArBJ,CAQIQ,QARJ,CASIC,QATJ,CAqBIT,KArBJ,CASIS,QATJ,CAUIC,UAVJ,CAqBIV,KArBJ,CAUIU,UAVJ,CAWIC,eAXJ,CAqBIX,KArBJ,CAWIW,eAXJ,CAYIC,gBAZJ,CAqBIZ,KArBJ,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MAA5C,CAFG,CAGHF,KAHG,CADX,+EAOI,6BAAC,oCAAD,EACI,IAAI,CAAEiB,IADV,CAEI,WAAW,CAAEC,cAFjB,CAGI,aAAa,CAAEwB,8BAHnB,CAII,WAAW,CAAEC,4BAJjB,CAKI,YAAY,CAAEC,6BALlB,CAMI,UAAU,CAAEC,2BANhB,+EAQI,6BAAC,8BAAD,CAAU,IAAV,EACI,GAAG,CAAE9C,IADT,CAEI,KAAK,CAAE,CACHkE,MAAM,CAACC,SADJ,CAEH,CACIjE,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAFG,CAMHF,KANG,CAOHG,QAAQ,CACF8D,MAAM,CAACE,aADL,CAEFF,MAAM,CAACG,eATV,CAFX,+EAcKxE,IAAI,CAACyE,GAAL,CAASb,YAAT,CAdL,CARJ,CAPJ,CADJ,CADJ,CAqCH,CA1MY,CAAjB,C,aA6MelE,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 { 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\n const offsetX = useDerivedValue(() => {\n const totalSize = size * data.length;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, data]);\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 +1 @@
1
- {"version":3,"sources":["ScrollViewGesture.tsx"],"names":["IScrollViewGesture","props","React","useContext","CTX","vertical","style","data","pagingEnabled","snapEnabled","panGestureHandlerProps","infinite","loop","scrollAnimationDuration","withAnimation","enabled","translation","size","onScrollBegin","onScrollEnd","onTouchBegin","onTouchEnd","maxPage","length","isHorizontal","touching","scrollEndTranslation","scrollEndVelocity","_withSpring","useCallback","toValue","onFinished","callback","isFinished","runOnJS","defaultWithAnimation","type","config","duration","easing","Easing","easeOutQuart","dealWithAnimation","endWithSpring","origin","value","velocity","nextPage","Math","round","deceleration","page","velocityPage","finalPage","min","max","withDecay","onFinish","activeDecay","resetBoundary","panGestureEventHandler","onStart","_","ctx","panOffset","cancelAnimation","onActive","e","translationX","translationY","panTranslation","boundary","fixed","dynamic","onEnd","velocityX","velocityY","directionStyle","useMemo","styles","contentHorizontal","contentVertical","container","children","ScrollViewGesture","StyleSheet","create","flex","overflow","flexDirection"],"mappings":"6PAAA,oDACA,yCACA,uEAIA,uFASA,sCACA,8BAEA,4D,2mCAkBA,GAAMA,CAAAA,kBAAmC,CAAG,QAAtCA,CAAAA,kBAAsC,CAACC,KAAD,CAAW,CACnD,sBAaIC,eAAMC,UAAN,CAAiBC,UAAjB,CAbJ,yCACIH,KADJ,CAEQI,QAFR,uBAEQA,QAFR,CAGQC,KAHR,uBAGQA,KAHR,CAIQC,IAJR,uBAIQA,IAJR,CAKQC,aALR,uBAKQA,aALR,CAMQC,WANR,uBAMQA,WANR,CAOQC,sBAPR,uBAOQA,sBA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V,EACI,KAAK,CAAE,CAAC0E,MAAM,CAACG,SAAR,CAAmBL,cAAnB,CAAmCvE,KAAnC,CADX,CAEI,YAAY,CAAEc,YAFlB,CAGI,UAAU,CAAEC,UAHhB,8EAKI,6BAAC,4CAAD,0BACQX,sBADR,EAEI,OAAO,CAAEK,OAFb,CAGI,cAAc,CAAE6C,sBAHpB,gFAKK3D,KAAK,CAACkF,QALX,CALJ,CADJ,CAeH,CAxPD,CA0PO,GAAMC,CAAAA,iBAAiB,CAAGpF,kBAA1B,C,4CAEP,GAAM+E,CAAAA,MAAM,CAAGM,wBAAWC,MAAX,CAAkB,CAC7BJ,SAAS,CAAE,CACPK,IAAI,CAAE,CADC,CAEPC,QAAQ,CAAE,QAFH,CADkB,CAK7BP,eAAe,CAAE,CACbQ,aAAa,CAAE,QADF,CALY,CAQ7BT,iBAAiB,CAAE,CACfS,aAAa,CAAE,KADA,CARU,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport { StyleProp, StyleSheet, ViewStyle } from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n withDecay,\n} from 'react-native-reanimated';\nimport { Easing } from './constants';\nimport { CTX } from './store';\nimport type { WithAnimation } from './types';\nimport { dealWithAnimation } from './utils/dealWithAnimation';\n\ntype GestureContext = {\n panOffset: number;\n max: number;\n};\n\ninterface Props {\n size: number;\n infinite?: boolean;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n onTouchBegin?: () => void;\n onTouchEnd?: () => void;\n style?: StyleProp<ViewStyle>;\n translation: Animated.SharedValue<number>;\n}\n\nconst IScrollViewGesture: React.FC<Props> = (props) => {\n const {\n props: {\n vertical,\n style,\n data,\n pagingEnabled,\n snapEnabled,\n panGestureHandlerProps,\n loop: infinite,\n scrollAnimationDuration,\n withAnimation,\n enabled,\n },\n } = React.useContext(CTX);\n\n const {\n translation,\n size,\n onScrollBegin,\n onScrollEnd,\n onTouchBegin,\n onTouchEnd,\n } = props;\n\n const maxPage = data.length;\n const isHorizontal = useDerivedValue(() => !vertical, [vertical]);\n const touching = useSharedValue(false);\n const scrollEndTranslation = useSharedValue(0);\n const scrollEndVelocity = useSharedValue(0);\n\n const _withSpring = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithAnimation = {\n type: 'timing',\n config: {\n duration: scrollAnimationDuration,\n easing: Easing.easeOutQuart,\n },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [scrollAnimationDuration, withAnimation]\n );\n\n const endWithSpring = React.useCallback(\n (onFinished?: () => void) => {\n 'worklet';\n const origin = translation.value;\n const velocity = scrollEndVelocity.value;\n if (!pagingEnabled) {\n if (snapEnabled) {\n const nextPage =\n Math.round((origin + velocity * 0.4) / size) * size;\n translation.value = _withSpring(nextPage, onFinished);\n return;\n }\n translation.value = withDecay({\n velocity,\n deceleration: 0.999,\n });\n return;\n }\n const page = Math.round(-translation.value / size);\n const velocityPage = Math.round(\n -(translation.value + scrollEndVelocity.value) / size\n );\n let finalPage = Math.min(\n page + 1,\n Math.max(page - 1, velocityPage)\n );\n if (!infinite) {\n finalPage = Math.min(maxPage - 1, Math.max(0, finalPage));\n }\n\n translation.value = _withSpring(-finalPage * size, onFinished);\n },\n [\n infinite,\n _withSpring,\n translation,\n scrollEndVelocity,\n size,\n maxPage,\n pagingEnabled,\n snapEnabled,\n ]\n );\n\n const onFinish = React.useCallback(\n (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n touching.value = false;\n onScrollEnd && runOnJS(onScrollEnd)();\n }\n },\n [onScrollEnd, touching]\n );\n\n const activeDecay = React.useCallback(() => {\n 'worklet';\n touching.value = true;\n translation.value = withDecay(\n { velocity: scrollEndVelocity.value },\n (isFinished) => onFinish(isFinished as boolean)\n );\n }, [onFinish, scrollEndVelocity.value, touching, translation]);\n\n const resetBoundary = React.useCallback(() => {\n 'worklet';\n if (touching.value) {\n return;\n }\n\n if (translation.value > 0) {\n if (scrollEndTranslation.value < 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(0);\n return;\n }\n }\n\n if (translation.value < -((maxPage - 1) * size)) {\n if (scrollEndTranslation.value > 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(-((maxPage - 1) * size));\n return;\n }\n }\n }, [\n touching.value,\n translation,\n maxPage,\n size,\n scrollEndTranslation.value,\n infinite,\n activeDecay,\n _withSpring,\n ]);\n\n useAnimatedReaction(\n () => translation.value,\n () => {\n if (!pagingEnabled) {\n resetBoundary();\n }\n },\n [pagingEnabled, resetBoundary]\n );\n\n const panGestureEventHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n GestureContext\n >(\n {\n onStart: (_, ctx) => {\n touching.value = true;\n cancelAnimation(translation);\n onScrollBegin && runOnJS(onScrollBegin)();\n ctx.max = (maxPage - 1) * size;\n ctx.panOffset = translation.value;\n },\n onActive: (e, ctx) => {\n touching.value = true;\n const { translationX, translationY } = e;\n let panTranslation = isHorizontal.value\n ? translationX\n : translationY;\n\n if (\n !infinite &&\n (translation.value > 0 || translation.value < -ctx.max)\n ) {\n const boundary = translation.value > 0 ? 0 : -ctx.max;\n const fixed = boundary - ctx.panOffset;\n const dynamic = panTranslation - fixed;\n translation.value = boundary + dynamic * 0.5;\n return;\n }\n\n translation.value = ctx.panOffset + panTranslation;\n },\n onEnd: (e) => {\n const { velocityX, velocityY, translationX, translationY } = e;\n scrollEndVelocity.value = isHorizontal.value\n ? velocityX\n : velocityY;\n scrollEndTranslation.value = isHorizontal.value\n ? translationX\n : translationY;\n\n endWithSpring(onScrollEnd);\n\n if (!infinite) {\n touching.value = false;\n }\n },\n },\n [\n pagingEnabled,\n isHorizontal.value,\n infinite,\n maxPage,\n size,\n snapEnabled,\n onScrollBegin,\n onScrollEnd,\n ]\n );\n\n const directionStyle = React.useMemo(() => {\n return vertical ? styles.contentHorizontal : styles.contentVertical;\n }, [vertical]);\n\n return (\n <Animated.View\n style={[styles.container, directionStyle, style]}\n onTouchStart={onTouchBegin}\n onTouchEnd={onTouchEnd}\n >\n <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={enabled}\n onGestureEvent={panGestureEventHandler}\n >\n {props.children}\n </PanGestureHandler>\n </Animated.View>\n );\n};\n\nexport const ScrollViewGesture = IScrollViewGesture;\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n contentVertical: {\n flexDirection: 'column',\n },\n contentHorizontal: {\n flexDirection: 'row',\n },\n});\n"]}
1
+ {"version":3,"sources":["ScrollViewGesture.tsx"],"names":["IScrollViewGesture","props","React","useContext","CTX","vertical","style","data","pagingEnabled","snapEnabled","panGestureHandlerProps","infinite","loop","scrollAnimationDuration","withAnimation","enabled","translation","size","onScrollBegin","onScrollEnd","onTouchBegin","onTouchEnd","maxPage","length","isHorizontal","touching","scrollEndTranslation","scrollEndVelocity","_withSpring","useCallback","toValue","onFinished","callback","isFinished","runOnJS","defaultWithAnimation","type","config","duration","easing","Easing","easeOutQuart","dealWithAnimation","endWithSpring","origin","value","velocity","nextPage","Math","round","deceleration","page","velocityPage","finalPage","min","max","withDecay","onFinish","activeDecay","resetBoundary","panGestureEventHandler","onStart","_","ctx","panOffset","cancelAnimation","onActive","e","translationX","translationY","panTranslation","boundary","fixed","dynamic","onEnd","velocityX","velocityY","directionStyle","useMemo","styles","contentHorizontal","contentVertical","container","children","ScrollViewGesture","StyleSheet","create","flex","overflow","flexDirection"],"mappings":"6PAAA,oDACA,yCACA,uEAIA,uFASA,sCACA,8BAEA,4D,2mCAkBA,GAAMA,CAAAA,kBAAmC,CAAG,QAAtCA,CAAAA,kBAAsC,CA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D2B,CAA/B,CA4DA,GAAM0D,CAAAA,cAAc,CAAG3E,eAAM4E,OAAN,CAAc,UAAM,CACvC,MAAOzE,CAAAA,QAAQ,CAAG0E,MAAM,CAACC,iBAAV,CAA8BD,MAAM,CAACE,eAApD,CACH,CAFsB,CAEpB,CAAC5E,QAAD,CAFoB,CAAvB,CAIA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CAAC0E,MAAM,CAACG,SAAR,CAAmBL,cAAnB,CAAmCvE,KAAnC,CADX,CAEI,YAAY,CAAEc,YAFlB,CAGI,UAAU,CAAEC,UAHhB,8EAKI,6BAAC,4CAAD,0BACQX,sBADR,EAEI,OAAO,CAAEK,OAFb,CAGI,cAAc,CAAE6C,sBAHpB,gFAKK3D,KAAK,CAACkF,QALX,CALJ,CADJ,CAeH,CAxPD,CA0PO,GAAMC,CAAAA,iBAAiB,CAAGpF,kBAA1B,C,4CAEP,GAAM+E,CAAAA,MAAM,CAAGM,wBAAWC,MAAX,CAAkB,CAC7BJ,SAAS,CAAE,CACPK,IAAI,CAAE,CADC,CAEPC,QAAQ,CAAE,QAFH,CADkB,CAK7BP,eAAe,CAAE,CACbQ,aAAa,CAAE,QADF,CALY,CAQ7BT,iBAAiB,CAAE,CACfS,aAAa,CAAE,KADA,CARU,CAAlB,CAAf","sourcesContent":["import React from 'react';\nimport { StyleProp, StyleSheet, ViewStyle } from 'react-native';\nimport {\n PanGestureHandler,\n PanGestureHandlerGestureEvent,\n} from 'react-native-gesture-handler';\nimport Animated, {\n cancelAnimation,\n runOnJS,\n useAnimatedGestureHandler,\n useAnimatedReaction,\n useDerivedValue,\n useSharedValue,\n withDecay,\n} from 'react-native-reanimated';\nimport { Easing } from './constants';\nimport { CTX } from './store';\nimport type { WithTimingAnimation } from './types';\nimport { dealWithAnimation } from './utils/dealWithAnimation';\n\ntype GestureContext = {\n panOffset: number;\n max: number;\n};\n\ninterface Props {\n size: number;\n infinite?: boolean;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n onTouchBegin?: () => void;\n onTouchEnd?: () => void;\n style?: StyleProp<ViewStyle>;\n translation: Animated.SharedValue<number>;\n}\n\nconst IScrollViewGesture: React.FC<Props> = (props) => {\n const {\n props: {\n vertical,\n style,\n data,\n pagingEnabled,\n snapEnabled,\n panGestureHandlerProps,\n loop: infinite,\n scrollAnimationDuration,\n withAnimation,\n enabled,\n },\n } = React.useContext(CTX);\n\n const {\n translation,\n size,\n onScrollBegin,\n onScrollEnd,\n onTouchBegin,\n onTouchEnd,\n } = props;\n\n const maxPage = data.length;\n const isHorizontal = useDerivedValue(() => !vertical, [vertical]);\n const touching = useSharedValue(false);\n const scrollEndTranslation = useSharedValue(0);\n const scrollEndVelocity = useSharedValue(0);\n\n const _withSpring = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: {\n duration: scrollAnimationDuration,\n easing: Easing.easeOutQuart,\n },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [scrollAnimationDuration, withAnimation]\n );\n\n const endWithSpring = React.useCallback(\n (onFinished?: () => void) => {\n 'worklet';\n const origin = translation.value;\n const velocity = scrollEndVelocity.value;\n if (!pagingEnabled) {\n if (snapEnabled) {\n const nextPage =\n Math.round((origin + velocity * 0.4) / size) * size;\n translation.value = _withSpring(nextPage, onFinished);\n return;\n }\n translation.value = withDecay({\n velocity,\n deceleration: 0.999,\n });\n return;\n }\n const page = Math.round(-translation.value / size);\n const velocityPage = Math.round(\n -(translation.value + scrollEndVelocity.value) / size\n );\n let finalPage = Math.min(\n page + 1,\n Math.max(page - 1, velocityPage)\n );\n if (!infinite) {\n finalPage = Math.min(maxPage - 1, Math.max(0, finalPage));\n }\n\n translation.value = _withSpring(-finalPage * size, onFinished);\n },\n [\n infinite,\n _withSpring,\n translation,\n scrollEndVelocity,\n size,\n maxPage,\n pagingEnabled,\n snapEnabled,\n ]\n );\n\n const onFinish = React.useCallback(\n (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n touching.value = false;\n onScrollEnd && runOnJS(onScrollEnd)();\n }\n },\n [onScrollEnd, touching]\n );\n\n const activeDecay = React.useCallback(() => {\n 'worklet';\n touching.value = true;\n translation.value = withDecay(\n { velocity: scrollEndVelocity.value },\n (isFinished) => onFinish(isFinished as boolean)\n );\n }, [onFinish, scrollEndVelocity.value, touching, translation]);\n\n const resetBoundary = React.useCallback(() => {\n 'worklet';\n if (touching.value) {\n return;\n }\n\n if (translation.value > 0) {\n if (scrollEndTranslation.value < 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(0);\n return;\n }\n }\n\n if (translation.value < -((maxPage - 1) * size)) {\n if (scrollEndTranslation.value > 0) {\n activeDecay();\n return;\n }\n if (!infinite) {\n translation.value = _withSpring(-((maxPage - 1) * size));\n return;\n }\n }\n }, [\n touching.value,\n translation,\n maxPage,\n size,\n scrollEndTranslation.value,\n infinite,\n activeDecay,\n _withSpring,\n ]);\n\n useAnimatedReaction(\n () => translation.value,\n () => {\n if (!pagingEnabled) {\n resetBoundary();\n }\n },\n [pagingEnabled, resetBoundary]\n );\n\n const panGestureEventHandler = useAnimatedGestureHandler<\n PanGestureHandlerGestureEvent,\n GestureContext\n >(\n {\n onStart: (_, ctx) => {\n touching.value = true;\n cancelAnimation(translation);\n onScrollBegin && runOnJS(onScrollBegin)();\n ctx.max = (maxPage - 1) * size;\n ctx.panOffset = translation.value;\n },\n onActive: (e, ctx) => {\n touching.value = true;\n const { translationX, translationY } = e;\n let panTranslation = isHorizontal.value\n ? translationX\n : translationY;\n\n if (\n !infinite &&\n (translation.value > 0 || translation.value < -ctx.max)\n ) {\n const boundary = translation.value > 0 ? 0 : -ctx.max;\n const fixed = boundary - ctx.panOffset;\n const dynamic = panTranslation - fixed;\n translation.value = boundary + dynamic * 0.5;\n return;\n }\n\n translation.value = ctx.panOffset + panTranslation;\n },\n onEnd: (e) => {\n const { velocityX, velocityY, translationX, translationY } = e;\n scrollEndVelocity.value = isHorizontal.value\n ? velocityX\n : velocityY;\n scrollEndTranslation.value = isHorizontal.value\n ? translationX\n : translationY;\n\n endWithSpring(onScrollEnd);\n\n if (!infinite) {\n touching.value = false;\n }\n },\n },\n [\n pagingEnabled,\n isHorizontal.value,\n infinite,\n maxPage,\n size,\n snapEnabled,\n onScrollBegin,\n onScrollEnd,\n ]\n );\n\n const directionStyle = React.useMemo(() => {\n return vertical ? styles.contentHorizontal : styles.contentVertical;\n }, [vertical]);\n\n return (\n <Animated.View\n style={[styles.container, directionStyle, style]}\n onTouchStart={onTouchBegin}\n onTouchEnd={onTouchEnd}\n >\n <PanGestureHandler\n {...panGestureHandlerProps}\n enabled={enabled}\n onGestureEvent={panGestureEventHandler}\n >\n {props.children}\n </PanGestureHandler>\n </Animated.View>\n );\n};\n\nexport const ScrollViewGesture = IScrollViewGesture;\n\nconst styles = StyleSheet.create({\n container: {\n flex: 1,\n overflow: 'hidden',\n },\n contentVertical: {\n flexDirection: 'column',\n },\n contentHorizontal: {\n flexDirection: 'row',\n },\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"sources":["index.ts"],"names":["DATA_LENGTH","Easing","easeOutQuart","_Easing","bezier"],"mappings":"mGAAA,8D,GAEYA,CAAAA,W,2CAAAA,W,EAAAA,W,CAAAA,W,iCAAAA,W,CAAAA,W,oCAAAA,W,uBAAAA,W,MAKL,GAAMC,CAAAA,MAAM,CAAG,CAClBC,YAAY,CAAEC,8BAAQC,MAAR,CAAe,IAAf,CAAqB,CAArB,CAAwB,GAAxB,CAA6B,CAA7B,CADI,CAAf,C","sourcesContent":["import { Easing as _Easing } from 'react-native-reanimated';\n\nexport enum DATA_LENGTH {\n SINGLE_ITEM = 1,\n DOUBLE_ITEM = 2,\n}\n\nexport const Easing = {\n easeOutQuart: _Easing.bezier(0.25, 1, 0.5, 1),\n};\n"]}
1
+ {"version":3,"sources":["index.ts"],"names":["DATA_LENGTH","Easing","easeOutQuart","_Easing","bezier"],"mappings":"mGAAA,8D,GAEYA,CAAAA,W,2CAAAA,W,EAAAA,W,CAAAA,W,iCAAAA,W,CAAAA,W,oCAAAA,W,uBAAAA,W,MAKL,GAAMC,CAAAA,MAAM,CAAG,CAClBC,YAAY,CAAEC,8BAAQC,MAAR,CACV,IADU,CAEV,CAFU,CAGV,GAHU,CAIV,CAJU,CADI,CAAf,C","sourcesContent":["import Animated, { Easing as _Easing } from 'react-native-reanimated';\n\nexport enum DATA_LENGTH {\n SINGLE_ITEM = 1,\n DOUBLE_ITEM = 2,\n}\n\nexport const Easing = {\n easeOutQuart: _Easing.bezier(\n 0.25,\n 1,\n 0.5,\n 1\n ) as unknown as Animated.EasingFunction,\n};\n"]}
@@ -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,2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AO,CACnC,GAAQC,CAAAA,KAAR,CAAgDD,IAAhD,CAAQC,KAAR,iBAAgDD,IAAhD,CAAeE,QAAf,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,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 WithAnimation,\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: WithAnimation = {\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","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,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tC8B,CAAAA,IAAsC,2DAAP,EAAO,CACnC,GAAQC,CAAAA,KAAR,CAAgDD,IAAhD,CAAQC,KAAR,iBAAgDD,IAAhD,CAAeE,QAAf,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,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"]}
@@ -0,0 +1,2 @@
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCheckMounted=useCheckMounted;var _react=_interopRequireDefault(require("react"));function useCheckMounted(){var mounted=_react.default.useRef(false);_react.default.useEffect(function(){mounted.current=true;return function(){mounted.current=false;};},[]);return mounted;}
2
+ //# sourceMappingURL=useCheckMounted.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useCheckMounted.ts"],"names":["useCheckMounted","mounted","React","useRef","useEffect","current"],"mappings":"oLAAA,oDAEO,QAASA,CAAAA,eAAT,EAA2B,CAC9B,GAAMC,CAAAA,OAAO,CAAGC,eAAMC,MAAN,CAAa,KAAb,CAAhB,CAEAD,eAAME,SAAN,CAAgB,UAAM,CAClBH,OAAO,CAACI,OAAR,CAAkB,IAAlB,CACA,MAAO,WAAM,CACTJ,OAAO,CAACI,OAAR,CAAkB,KAAlB,CACH,CAFD,CAGH,CALD,CAKG,EALH,EAOA,MAAOJ,CAAAA,OAAP,CACH","sourcesContent":["import React from 'react';\n\nexport function useCheckMounted() {\n const mounted = React.useRef(false);\n\n React.useEffect(() => {\n mounted.current = true;\n return () => {\n mounted.current = false;\n };\n }, []);\n\n return mounted;\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);if(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=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{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 _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});}
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":"4QAAA,oDACA,uC,2yBAqBO,QAASA,CAAAA,YAAT,CACHC,KADG,CAEwB,uBAC3B,wBAaIA,KAbJ,CACIC,YADJ,CACIA,YADJ,8BACmB,CADnB,iCAaID,KAbJ,CAEIE,IAFJ,CAEUC,OAFV,sBAEoB,EAFpB,yBAaIH,KAbJ,CAGII,IAHJ,CAGIA,IAHJ,sBAGW,IAHX,4BAaIJ,KAbJ,CAIIK,OAJJ,CAIIA,OAJJ,yBAIc,IAJd,sCAaIL,KAbJ,CAKIM,gBALJ,CAKsBC,iBALtB,gCAK0C,IAL1C,6CAaIP,KAbJ,CAMIQ,uBANJ,CAMIA,uBANJ,gCAM8B,GAN9B,oCAaIR,KAbJ,CAOIS,KAPJ,CAOIA,KAPJ,uBAOY,EAPZ,oCAaIT,KAbJ,CAQIU,sBARJ,CAQIA,sBARJ,gCAQ6B,EAR7B,4CAaIV,KAbJ,CASIW,aATJ,CASIA,aATJ,+BASoB,IATpB,yCAaIX,KAbJ,CAUIY,WAVJ,CAU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CACI7B,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","snapEnabled","enableSnap","_width","width","_height","height","Math","round","max","React","useMemo","length","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","mode","modeConfig","showLength"],"mappings":"4QAAA,oDACA,uC,kxBAqBO,QAASA,CAAAA,YAAT,CACHC,KADG,CAEwB,uBAC3B,wBAaIA,KAbJ,CACIC,YADJ,CACIA,YADJ,8BACmB,CADnB,iCAaID,KAbJ,CAEIE,IAFJ,CAEUC,OAFV,sBAEoB,EAFpB,yBAaIH,KAbJ,CAGII,IAHJ,CAGIA,IAHJ,sBAGW,IAHX,4BAaIJ,KAbJ,CAIIK,OAJJ,CAIIA,OAJJ,yBAIc,IAJd,sCAaIL,KAbJ,CAKIM,gBALJ,CAKsBC,iBALtB,gCAK0C,IAL1C,6CAaIP,KAbJ,CAMIQ,uBANJ,CAMIA,uBANJ,gCAM8B,GAN9B,oCAaIR,KAbJ,CAOIS,KAPJ,CAOIA,KAPJ,uBAOY,EAPZ,oCAaIT,KAbJ,CAQIU,sBARJ,CAQIA,sBARJ,gCAQ6B,EAR7B,4CAaIV,KAbJ,CASIW,aATJ,CASIA,aATJ,+BASoB,IATpB,yCAaIX,KAbJ,CAUIY,WA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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,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.BaseLayout=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _store=require("../store");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.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);if(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=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var BaseLayout=function BaseLayout(props){var handlerOffsetX=props.handlerOffsetX,index=props.index,children=props.children,visibleRanges=props.visibleRanges,animationStyle=props.animationStyle;var context=_react.default.useContext(_store.CTX);var _context$props=context.props,loop=_context$props.loop,data=_context$props.data,width=_context$props.width,height=_context$props.height,vertical=_context$props.vertical,customConfig=_context$props.customConfig,mode=_context$props.mode,modeConfig=_context$props.modeConfig;var size=vertical?height:width;var _React$useState=_react.default.useState(false),_React$useState2=(0,_slicedToArray2.default)(_React$useState,2),shouldUpdate=_React$useState2[0],setShouldUpdate=_React$useState2[1];var offsetXConfig=_objectSpread({handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop},typeof customConfig==='function'?customConfig():{});if(mode==='horizontal-stack'){var _ref=modeConfig,snapDirection=_ref.snapDirection,showLength=_ref.showLength;offsetXConfig={handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop,type:snapDirection==='right'?'negative':'positive',viewCount:showLength};}var x=(0,_useOffsetX.useOffsetX)(offsetXConfig,visibleRanges);var animationValue=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){return x.value/size;};_f._closure={x:x,size:size};_f.asString="function _f(){const{x,size}=jsThis._closure;{return x.value/size;}}";_f.__workletHash=9077192607952;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (69:43)";global.__reanimatedWorkletInit(_f);return _f;}(),[x,size]);var animatedStyle=(0,_reactNativeReanimated.useAnimatedStyle)(function(){var _f=function _f(){return animationStyle(x.value/size);};_f._closure={animationStyle:animationStyle,x:x,size:size};_f.asString="function _f(){const{animationStyle,x,size}=jsThis._closure;{return animationStyle(x.value/size);}}";_f.__workletHash=3916054905053;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (72:8)";_f.__optimalization=2;global.__reanimatedWorkletInit(_f);return _f;}(),[animationStyle]);var updateView=_react.default.useCallback(function(negativeRange,positiveRange){setShouldUpdate(index>=negativeRange[0]&&index<=negativeRange[1]||index>=positiveRange[0]&&index<=positiveRange[1]);},[index]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return visibleRanges.value;};_f._closure={visibleRanges:visibleRanges};_f.asString="function _f(){const{visibleRanges}=jsThis._closure;{return visibleRanges.value;}}";_f.__workletHash=15231519758579;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (87:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(){(0,_reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,updateView:updateView,visibleRanges:visibleRanges};_f.asString="function _f(){const{runOnJS,updateView,visibleRanges}=jsThis._closure;{runOnJS(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);}}";_f.__workletHash=6352504350554;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (88:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[visibleRanges.value]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[{width:width||'100%',height:height||'100%',position:'absolute'},animatedStyle],__self:_this,__source:{fileName:_jsxFileName,lineNumber:98,columnNumber:9}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:108,columnNumber:13}},children({animationValue:animationValue})));};exports.BaseLayout=BaseLayout;
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.BaseLayout=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useCheckMounted=require("../hooks/useCheckMounted");var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _store=require("../store");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.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 BaseLayout=function BaseLayout(props){var mounted=(0,_useCheckMounted.useCheckMounted)();var handlerOffsetX=props.handlerOffsetX,index=props.index,children=props.children,visibleRanges=props.visibleRanges,animationStyle=props.animationStyle;var context=_react.default.useContext(_store.CTX);var _context$props=context.props,loop=_context$props.loop,data=_context$props.data,width=_context$props.width,height=_context$props.height,vertical=_context$props.vertical,customConfig=_context$props.customConfig,mode=_context$props.mode,modeConfig=_context$props.modeConfig;var size=vertical?height:width;var _React$useState=_react.default.useState(false),_React$useState2=(0,_slicedToArray2.default)(_React$useState,2),shouldUpdate=_React$useState2[0],setShouldUpdate=_React$useState2[1];var offsetXConfig=_objectSpread({handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop},typeof customConfig==='function'?customConfig():{});if(mode==='horizontal-stack'){var _ref=modeConfig,snapDirection=_ref.snapDirection,showLength=_ref.showLength;offsetXConfig={handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop,type:snapDirection==='right'?'negative':'positive',viewCount:showLength};}var x=(0,_useOffsetX.useOffsetX)(offsetXConfig,visibleRanges);var animationValue=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){return x.value/size;};_f._closure={x:x,size:size};_f.asString="function _f(){const{x,size}=jsThis._closure;{return x.value/size;}}";_f.__workletHash=9077192607952;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (71:43)";global.__reanimatedWorkletInit(_f);return _f;}(),[x,size]);var animatedStyle=(0,_reactNativeReanimated.useAnimatedStyle)(function(){var _f=function _f(){return animationStyle(x.value/size);};_f._closure={animationStyle:animationStyle,x:x,size:size};_f.asString="function _f(){const{animationStyle,x,size}=jsThis._closure;{return animationStyle(x.value/size);}}";_f.__workletHash=3916054905053;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (74:8)";_f.__optimalization=2;global.__reanimatedWorkletInit(_f);return _f;}(),[animationStyle]);var updateView=_react.default.useCallback(function(negativeRange,positiveRange){mounted.current&&setShouldUpdate(index>=negativeRange[0]&&index<=negativeRange[1]||index>=positiveRange[0]&&index<=positiveRange[1]);},[index,mounted]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return visibleRanges.value;};_f._closure={visibleRanges:visibleRanges};_f.asString="function _f(){const{visibleRanges}=jsThis._closure;{return visibleRanges.value;}}";_f.__workletHash=15231519758579;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (90:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(){(0,_reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,updateView:updateView,visibleRanges:visibleRanges};_f.asString="function _f(){const{runOnJS,updateView,visibleRanges}=jsThis._closure;{runOnJS(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);}}";_f.__workletHash=6352504350554;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (91:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[visibleRanges.value]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[{width:width||'100%',height:height||'100%',position:'absolute'},animatedStyle],__self:_this,__source:{fileName:_jsxFileName,lineNumber:101,columnNumber:9}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:111,columnNumber:13}},children({animationValue:animationValue})));};exports.BaseLayout=BaseLayout;
2
2
  //# sourceMappingURL=BaseLayout.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","handlerOffsetX","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","data","width","height","vertical","customConfig","mode","modeConfig","size","useState","shouldUpdate","setShouldUpdate","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","runOnJS","position"],"mappings":"gWAAA,oDAEA,uFAOA,+CAEA,qCACA,+B,u5DAKO,GAAMA,CAAAA,UAQX,CAAG,QARQA,CAAAA,UAQR,CAACC,KAAD,CAAW,CACZ,GAAQC,CAAAA,cAAR,CACID,KADJ,CAAQC,cAAR,CAAwBC,KAAxB,CACIF,KADJ,CAAwBE,KAAxB,CAA+BC,QAA/B,CACIH,KADJ,CAA+BG,QAA/B,CAAyCC,aAAzC,CACIJ,KADJ,CAAyCI,aAAzC,CAAwDC,cAAxD,CACIL,KADJ,CAAwDK,cAAxD,CAGA,GAAMC,CAAAA,OAAO,CAAGC,eAAMC,UAAN,CAAiBC,UAAjB,CAAhB,CACA,mBAWIH,OAXJ,CACIN,KADJ,CAEQU,IAFR,gBAEQA,IAFR,CAGQC,IAHR,gBAGQA,IAHR,CAIQC,KAJR,gBAIQA,KAJR,CAKQC,MALR,gBAKQA,MALR,CAMQC,QANR,gBAMQA,QANR,CAOQC,YAPR,gBAOQA,YAPR,CAQQC,IARR,gBAQQA,IARR,CASQC,UATR,gBASQA,UATR,CAYA,GAAMC,CAAAA,IAAI,CAAGJ,QAAQ,CAAGD,MAAH,CAAYD,KAAj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aAA1B,CAAsD,CAClDb,eAAe,CACVnB,KAAK,EAAI+B,aAAa,CAAC,CAAD,CAAtB,EAA6B/B,KAAK,EAAI+B,aAAa,CAAC,CAAD,CAApD,EACK/B,KAAK,EAAIgC,aAAa,CAAC,CAAD,CAAtB,EAA6BhC,KAAK,EAAIgC,aAAa,CAAC,CAAD,CAF7C,CAAf,CAIH,CANc,CAOf,CAAChC,KAAD,CAPe,CAAnB,CAUA,iEACI,oBAAME,CAAAA,aAAa,CAACyB,KAApB,EADJ,4BApFGzB,aAoFH,6TAEU,CACF,mCAAQ2B,UAAR,EACI3B,aAAa,CAACyB,KAAd,CAAoBI,aADxB,CAEI7B,aAAa,CAACyB,KAAd,CAAoBK,aAFxB,EAIH,CAPL,sBAnFFC,8BAmFE,YAnFMJ,UAmFN,eAnFqD3B,aAmFrD,8WAQI,CAACA,aAAa,CAACyB,KAAf,CARJ,EAWA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CACH,CACIjB,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAGIuB,QAAQ,CAAE,UAHd,CADG,CAMHN,aANG,CADX,6EAUI,6BAAC,kBAAD,EAAU,YAAY,CAAEV,YAAxB,+EACKjB,QAAQ,CAAC,CAAEyB,cAAc,CAAdA,cAAF,CAAD,CADb,CAVJ,CADJ,CAgBH,CA/FM,C","sourcesContent":["import React from 'react';\nimport type { ViewStyle } from 'react-native';\nimport Animated, {\n AnimatedStyleProp,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from 'react-native-reanimated';\nimport { IOpts, useOffsetX } from '../hooks/useOffsetX';\nimport type { IVisibleRanges } from '../hooks/useVisibleRanges';\nimport { LazyView } from '../LazyView';\nimport { CTX } from '../store';\nimport type { ILayoutConfig } from './stack';\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number;\n handlerOffsetX: Animated.SharedValue<number>;\n visibleRanges: IVisibleRanges;\n animationStyle: TAnimationStyle;\n children: (ctx: {\n animationValue: Animated.SharedValue<number>;\n }) => React.ReactElement;\n}> = (props) => {\n const { handlerOffsetX, index, children, visibleRanges, animationStyle } =\n props;\n\n const context = React.useContext(CTX);\n const {\n props: {\n loop,\n data,\n width,\n height,\n vertical,\n customConfig,\n mode,\n modeConfig,\n },\n } = context;\n const size = vertical ? height : width;\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n let offsetXConfig: IOpts = {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n ...(typeof customConfig === 'function' ? customConfig() : {}),\n };\n\n if (mode === 'horizontal-stack') {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n type: snapDirection === 'right' ? 'negative' : 'positive',\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n // @ts-ignore\n () => animationStyle(x.value / size),\n [animationStyle]\n );\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1]) ||\n (index >= positiveRange[0] && index <= positiveRange[1])\n );\n },\n [index]\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange\n );\n },\n [visibleRanges.value]\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || '100%',\n height: height || '100%',\n position: 'absolute',\n },\n animatedStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
1
+ {"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","mounted","handlerOffsetX","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","data","width","height","vertical","customConfig","mode","modeConfig","size","useState","shouldUpdate","setShouldUpdate","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","current","runOnJS","position"],"mappings":"gWAAA,oDAEA,uFAOA,yDACA,+CAEA,qCACA,+B,83DAKO,GAAMA,CAAAA,UAQX,CAAG,QARQA,CAAAA,UAQR,CAACC,KAAD,CAAW,CACZ,GAAMC,CAAAA,OAAO,CAAG,sCAAhB,CACA,GAAQC,CAAAA,cAAR,CACIF,KADJ,CAAQE,cAAR,CAAwBC,KAAxB,CACIH,KADJ,CAAwBG,KAAxB,CAA+BC,QAA/B,CACIJ,KADJ,CAA+BI,QAA/B,CAAyCC,aAAzC,CACIL,KADJ,CAAyCK,aAAzC,CAAwDC,cAAxD,CACIN,KADJ,CAAwDM,cAAxD,CAGA,GAAMC,CAAAA,OAAO,CAAGC,eAAMC,UAAN,CAAiBC,UAAjB,CAAhB,CACA,mBAWIH,OAXJ,CACIP,KADJ,CAEQW,IAFR,gBAEQA,IAFR,CAGQC,IAHR,gBAGQA,IAHR,CAIQC,KAJR,gBAIQA,KAJR,CAKQC,MALR,gBAKQA,MALR,CAMQC,QANR,gBAMQA,QANR,CAOQC,YAPR,gBAOQA,YAPR,CAQQC,IARR,gBAQQA,IARR,CASQC,UATR,gBASQA,UATR,CAYA,GAAMC,CAAAA,IAAI,CAAGJ,QAAQ,CAAGD,MAAH,CAAYD,KAAjC,CACA,oBAAwCL,eAAMY,QAAN,CAAe,KAAf,CAAxC,iEAAOC,YAAP,qBAAqBC,eAArB,qBACA,GAAIC,CAAAA,aAAoB,gBACpBrB,cAAc,CAAdA,cADoB,CAEpBC,KAAK,CAALA,KAFoB,CAGpBgB,IAAI,CAAJA,IAHoB,CAIpBP,IAAI,CAAJA,IAJoB,CAKpBD,IAAI,CAAJA,IALoB,EAMhB,MAAOK,CAAAA,YAAP,GAAwB,UAAxB,CAAqCA,YA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WA,iEACI,oBAAMI,CAAAA,aAAa,CAACyB,KAApB,EADJ,4BAvFGzB,aAuFH,6TAEU,CACF,mCAAQ2B,UAAR,EACI3B,aAAa,CAACyB,KAAd,CAAoBI,aADxB,CAEI7B,aAAa,CAACyB,KAAd,CAAoBK,aAFxB,EAIH,CAPL,sBAtFFE,8BAsFE,YAtFML,UAsFN,eAtFqD3B,aAsFrD,8WAQI,CAACA,aAAa,CAACyB,KAAf,CARJ,EAWA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CACH,CACIjB,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAGIwB,QAAQ,CAAE,UAHd,CADG,CAMHP,aANG,CADX,8EAUI,6BAAC,kBAAD,EAAU,YAAY,CAAEV,YAAxB,+EACKjB,QAAQ,CAAC,CAAEyB,cAAc,CAAdA,cAAF,CAAD,CADb,CAVJ,CADJ,CAgBH,CAjGM,C","sourcesContent":["import React from 'react';\nimport type { ViewStyle } from 'react-native';\nimport Animated, {\n AnimatedStyleProp,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from 'react-native-reanimated';\nimport { useCheckMounted } from 'src/hooks/useCheckMounted';\nimport { IOpts, useOffsetX } from '../hooks/useOffsetX';\nimport type { IVisibleRanges } from '../hooks/useVisibleRanges';\nimport { LazyView } from '../LazyView';\nimport { CTX } from '../store';\nimport type { ILayoutConfig } from './stack';\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number;\n handlerOffsetX: Animated.SharedValue<number>;\n visibleRanges: IVisibleRanges;\n animationStyle: TAnimationStyle;\n children: (ctx: {\n animationValue: Animated.SharedValue<number>;\n }) => React.ReactElement;\n}> = (props) => {\n const mounted = useCheckMounted();\n const { handlerOffsetX, index, children, visibleRanges, animationStyle } =\n props;\n\n const context = React.useContext(CTX);\n const {\n props: {\n loop,\n data,\n width,\n height,\n vertical,\n customConfig,\n mode,\n modeConfig,\n },\n } = context;\n const size = vertical ? height : width;\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n let offsetXConfig: IOpts = {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n ...(typeof customConfig === 'function' ? customConfig() : {}),\n };\n\n if (mode === 'horizontal-stack') {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n type: snapDirection === 'right' ? 'negative' : 'positive',\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n // @ts-ignore\n () => animationStyle(x.value / size),\n [animationStyle]\n );\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n mounted.current &&\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1]) ||\n (index >= positiveRange[0] && index <= positiveRange[1])\n );\n },\n [index, mounted]\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange\n );\n },\n [visibleRanges.value]\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || '100%',\n height: height || '100%',\n position: 'absolute',\n },\n animatedStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
@@ -1,2 +1,2 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.ParallaxLayout=void 0;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.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;}var ParallaxLayout=function ParallaxLayout(props){var handlerOffsetX=props.handlerOffsetX,_props$parallaxScroll=props.parallaxScrollingOffset,parallaxScrollingOffset=_props$parallaxScroll===void 0?100:_props$parallaxScroll,_props$parallaxScroll2=props.parallaxScrollingScale,parallaxScrollingScale=_props$parallaxScroll2===void 0?0.8:_props$parallaxScroll2,index=props.index,width=props.width,height=props.height,loop=props.loop,data=props.data,children=props.children,visibleRanges=props.visibleRanges,vertical=props.vertical;var _React$useState=_react.default.useState(false),_React$useState2=(0,_slicedToArray2.default)(_React$useState,2),shouldUpdate=_React$useState2[0],setShouldUpdate=_React$useState2[1];var size=props.vertical?props.height:props.width;var x=(0,_useOffsetX.useOffsetX)({handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop},visibleRanges);var offsetXStyle=(0,_reactNativeReanimated.useAnimatedStyle)(function(){var _f=function _f(){var value=x.value/size;var translate=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset],_reactNativeReanimated.Extrapolate.EXTEND);var zIndex=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[0,size,0],_reactNativeReanimated.Extrapolate.CLAMP);var scale=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[Math.pow(parallaxScrollingScale,2),parallaxScrollingScale,Math.pow(parallaxScrollingScale,2)],_reactNativeReanimated.Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};};_f._closure={x:x,size:size,interpolate:_reactNativeReanimated.interpolate,parallaxScrollingOffset:parallaxScrollingOffset,Extrapolate:{EXTEND:_reactNativeReanimated.Extrapolate.EXTEND,CLAMP:_reactNativeReanimated.Extrapolate.CLAMP},parallaxScrollingScale:parallaxScrollingScale,vertical:vertical};_f.asString="function _f(){const{x,size,interpolate,parallaxScrollingOffset,Extrapolate,parallaxScrollingScale,vertical}=jsThis._closure;{const value=x.value/size;const translate=interpolate(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset],Extrapolate.EXTEND);const zIndex=interpolate(value,[-1,0,1],[0,size,0],Extrapolate.CLAMP);const scale=interpolate(value,[-1,0,1],[Math.pow(parallaxScrollingScale,2),parallaxScrollingScale,Math.pow(parallaxScrollingScale,2)],Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};}}";_f.__workletHash=17002584047503;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (54:42)";_f.__optimalization=2;global.__reanimatedWorkletInit(_f);return _f;}(),[loop,vertical,parallaxScrollingOffset]);var updateView=_react.default.useCallback(function(negativeRange,positiveRange){setShouldUpdate(index>=negativeRange[0]&&index<=negativeRange[1]||index>=positiveRange[0]&&index<=positiveRange[1]);},[index]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return visibleRanges.value;};_f._closure={visibleRanges:visibleRanges};_f.asString="function _f(){const{visibleRanges}=jsThis._closure;{return visibleRanges.value;}}";_f.__workletHash=15231519758579;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (114:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(){(0,_reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,updateView:updateView,visibleRanges:visibleRanges};_f.asString="function _f(){const{runOnJS,updateView,visibleRanges}=jsThis._closure;{runOnJS(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);}}";_f.__workletHash=6352504350554;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (115:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[visibleRanges.value]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[{width:width||'100%',height:height||'100%',position:'absolute'},offsetXStyle],__self:_this,__source:{fileName:_jsxFileName,lineNumber:125,columnNumber:9}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:135,columnNumber:13}},children));};exports.ParallaxLayout=ParallaxLayout;
1
+ var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.ParallaxLayout=void 0;var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.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;}var ParallaxLayout=function ParallaxLayout(props){var handlerOffsetX=props.handlerOffsetX,_props$parallaxScroll=props.parallaxScrollingOffset,parallaxScrollingOffset=_props$parallaxScroll===void 0?100:_props$parallaxScroll,_props$parallaxScroll2=props.parallaxScrollingScale,parallaxScrollingScale=_props$parallaxScroll2===void 0?0.8:_props$parallaxScroll2,_props$parallaxAdjace=props.parallaxAdjacentItemScale,parallaxAdjacentItemScale=_props$parallaxAdjace===void 0?Math.pow(parallaxScrollingScale,2):_props$parallaxAdjace,index=props.index,width=props.width,height=props.height,loop=props.loop,data=props.data,children=props.children,visibleRanges=props.visibleRanges,vertical=props.vertical;var _React$useState=_react.default.useState(false),_React$useState2=(0,_slicedToArray2.default)(_React$useState,2),shouldUpdate=_React$useState2[0],setShouldUpdate=_React$useState2[1];var size=props.vertical?props.height:props.width;var x=(0,_useOffsetX.useOffsetX)({handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop},visibleRanges);var offsetXStyle=(0,_reactNativeReanimated.useAnimatedStyle)(function(){var _f=function _f(){var value=x.value/size;var translate=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset],_reactNativeReanimated.Extrapolate.EXTEND);var zIndex=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[0,size,0],_reactNativeReanimated.Extrapolate.CLAMP);var scale=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[parallaxAdjacentItemScale,parallaxScrollingScale,parallaxAdjacentItemScale],_reactNativeReanimated.Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};};_f._closure={x:x,size:size,interpolate:_reactNativeReanimated.interpolate,parallaxScrollingOffset:parallaxScrollingOffset,Extrapolate:{EXTEND:_reactNativeReanimated.Extrapolate.EXTEND,CLAMP:_reactNativeReanimated.Extrapolate.CLAMP},parallaxAdjacentItemScale:parallaxAdjacentItemScale,parallaxScrollingScale:parallaxScrollingScale,vertical:vertical};_f.asString="function _f(){const{x,size,interpolate,parallaxScrollingOffset,Extrapolate,parallaxAdjacentItemScale,parallaxScrollingScale,vertical}=jsThis._closure;{const value=x.value/size;const translate=interpolate(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset],Extrapolate.EXTEND);const zIndex=interpolate(value,[-1,0,1],[0,size,0],Extrapolate.CLAMP);const scale=interpolate(value,[-1,0,1],[parallaxAdjacentItemScale,parallaxScrollingScale,parallaxAdjacentItemScale],Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};}}";_f.__workletHash=10412925648231;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (56:42)";_f.__optimalization=3;global.__reanimatedWorkletInit(_f);return _f;}(),[loop,vertical,parallaxScrollingOffset]);var updateView=_react.default.useCallback(function(negativeRange,positiveRange){setShouldUpdate(index>=negativeRange[0]&&index<=negativeRange[1]||index>=positiveRange[0]&&index<=positiveRange[1]);},[index]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return visibleRanges.value;};_f._closure={visibleRanges:visibleRanges};_f.asString="function _f(){const{visibleRanges}=jsThis._closure;{return visibleRanges.value;}}";_f.__workletHash=15231519758579;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (116:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(){(0,_reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,updateView:updateView,visibleRanges:visibleRanges};_f.asString="function _f(){const{runOnJS,updateView,visibleRanges}=jsThis._closure;{runOnJS(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);}}";_f.__workletHash=6352504350554;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (117:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[visibleRanges.value]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[{width:width||'100%',height:height||'100%',position:'absolute'},offsetXStyle],__self:_this,__source:{fileName:_jsxFileName,lineNumber:127,columnNumber:9}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:137,columnNumber:13}},children));};exports.ParallaxLayout=ParallaxLayout;
2
2
  //# sourceMappingURL=ParallaxLayout.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["ParallaxLayout.tsx"],"names":["ParallaxLayout","props","handlerOffsetX","parallaxScrollingOffset","parallaxScrollingScale","index","width","height","loop","data","children","visibleRanges","vertical","React","useState","shouldUpdate","setShouldUpdate","size","x","offsetXStyle","value","translate","Extrapolate","EXTEND","zIndex","CLAMP","scale","Math","pow","transform","translateY","translateX","interpolate","updateView","useCallback","negativeRange","positiveRange","runOnJS","position"],"mappings":"sQAAA,oDACA,uFAQA,+CAEA,qC,gnCAEO,GAAMA,CAAAA,cAUZ,CAAG,QAVSA,CAAAA,cAUT,CAACC,KAAD,CAAW,CACX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AAMM,CAAAA,aAAa,CAACS,KAApB,EADJ,4BA/GGT,aA+GH,kUAEU,CACF,mCAAQsB,UAAR,EACItB,aAAa,CAACS,KAAd,CAAoBe,aADxB,CAEIxB,aAAa,CAACS,KAAd,CAAoBgB,aAFxB,EAIH,CAPL,sBA9GFC,8BA8GE,YA9GMJ,UA8GN,eA9GqDtB,aA8GrD,mXAQI,CAACA,aAAa,CAACS,KAAf,CARJ,EAWA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CACH,CACId,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAGI+B,QAAQ,CAAE,UAHd,CADG,CAMHnB,YANG,CADX,8EAUI,6BAAC,kBAAD,EAAU,YAAY,CAAEJ,YAAxB,+EAAuCL,QAAvC,CAVJ,CADJ,CAcH,CA5HM,C","sourcesContent":["import React from 'react';\nimport Animated, {\n Extrapolate,\n interpolate,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n} from 'react-native-reanimated';\nimport type { ComputedDirectionTypes } from 'src/types';\nimport { useOffsetX } from '../hooks/useOffsetX';\nimport type { IVisibleRanges } from '../hooks/useVisibleRanges';\nimport { LazyView } from '../LazyView';\n\nexport const ParallaxLayout: React.FC<\n ComputedDirectionTypes<{\n loop?: boolean;\n parallaxScrollingOffset?: number;\n parallaxScrollingScale?: number;\n handlerOffsetX: Animated.SharedValue<number>;\n index: number;\n data: unknown[];\n visibleRanges: IVisibleRanges;\n }>\n> = (props) => {\n const {\n handlerOffsetX,\n parallaxScrollingOffset = 100,\n parallaxScrollingScale = 0.8,\n index,\n width,\n height,\n loop,\n data,\n children,\n visibleRanges,\n vertical,\n } = props;\n\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n\n const size = props.vertical ? props.height : props.width;\n\n const x = useOffsetX(\n {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n },\n visibleRanges\n );\n\n const offsetXStyle = useAnimatedStyle(() => {\n const value = x.value / size;\n\n const translate = interpolate(\n value,\n [-1, 0, 1],\n [\n -size + parallaxScrollingOffset,\n 0,\n size - parallaxScrollingOffset,\n ],\n Extrapolate.EXTEND\n );\n\n const zIndex = interpolate(\n value,\n [-1, 0, 1],\n [0, size, 0],\n Extrapolate.CLAMP\n );\n\n const scale = interpolate(\n value,\n [-1, 0, 1],\n [\n Math.pow(parallaxScrollingScale, 2),\n parallaxScrollingScale,\n Math.pow(parallaxScrollingScale, 2),\n ],\n Extrapolate.CLAMP\n );\n\n return {\n transform: [\n vertical\n ? {\n translateY: translate,\n }\n : {\n translateX: translate,\n },\n {\n scale,\n },\n ],\n zIndex,\n };\n }, [loop, vertical, parallaxScrollingOffset]);\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1]) ||\n (index >= positiveRange[0] && index <= positiveRange[1])\n );\n },\n [index]\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange\n );\n },\n [visibleRanges.value]\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || '100%',\n height: height || '100%',\n position: 'absolute',\n },\n offsetXStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>{children}</LazyView>\n </Animated.View>\n );\n};\n"]}
1
+ {"version":3,"sources":["ParallaxLayout.tsx"],"names":["ParallaxLayout","props","handlerOffsetX","parallaxScrollingOffset","parallaxScrollingScale","parallaxAdjacentItemScale","Math","pow","index","width","height","loop","data","children","visibleRanges","vertical","React","useState","shouldUpdate","setShouldUpdate","size","x","offsetXStyle","value","translate","Extrapolate","EXTEND","zIndex","CLAMP","scale","transform","translateY","translateX","interpolate","updateView","useCallback","negativeRange","positiveRange","runOnJS","position"],"mappings":"sQAAA,oDACA,uFAQA,+CAEA,qC,gnCAGO,GAAMA,CAAAA,cAUZ,CAAG,QAVSA,CAAAA,c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,CAIH,CANc,CAOf,CAAC7B,KAAD,CAPe,CAAnB,CAUA,iEACI,oBAAMM,CAAAA,aAAa,CAACS,KAApB,EADJ,4BAjHGT,aAiHH,kUAEU,CACF,mCAAQoB,UAAR,EACIpB,aAAa,CAACS,KAAd,CAAoBa,aADxB,CAEItB,aAAa,CAACS,KAAd,CAAoBc,aAFxB,EAIH,CAPL,sBAhHFC,8BAgHE,YAhHMJ,UAgHN,eAhHqDpB,aAgHrD,mXAQI,CAACA,aAAa,CAACS,KAAf,CARJ,EAWA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CACH,CACId,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAGI6B,QAAQ,CAAE,UAHd,CADG,CAMHjB,YANG,CADX,8EAUI,6BAAC,kBAAD,EAAU,YAAY,CAAEJ,YAAxB,+EAAuCL,QAAvC,CAVJ,CADJ,CAcH,CA7HM,C","sourcesContent":["import React from 'react';\nimport Animated, {\n Extrapolate,\n interpolate,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n} from 'react-native-reanimated';\nimport type { ComputedDirectionTypes } from 'src/types';\nimport { useOffsetX } from '../hooks/useOffsetX';\nimport type { IVisibleRanges } from '../hooks/useVisibleRanges';\nimport { LazyView } from '../LazyView';\nimport type { ILayoutConfig } from './parallax';\n\nexport const ParallaxLayout: React.FC<\n ComputedDirectionTypes<\n {\n loop?: boolean;\n handlerOffsetX: Animated.SharedValue<number>;\n index: number;\n data: unknown[];\n visibleRanges: IVisibleRanges;\n } & ILayoutConfig\n >\n> = (props) => {\n const {\n handlerOffsetX,\n parallaxScrollingOffset = 100,\n parallaxScrollingScale = 0.8,\n parallaxAdjacentItemScale = Math.pow(parallaxScrollingScale, 2),\n index,\n width,\n height,\n loop,\n data,\n children,\n visibleRanges,\n vertical,\n } = props;\n\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n\n const size = props.vertical ? props.height : props.width;\n\n const x = useOffsetX(\n {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n },\n visibleRanges\n );\n\n const offsetXStyle = useAnimatedStyle(() => {\n const value = x.value / size;\n\n const translate = interpolate(\n value,\n [-1, 0, 1],\n [\n -size + parallaxScrollingOffset,\n 0,\n size - parallaxScrollingOffset,\n ],\n Extrapolate.EXTEND\n );\n\n const zIndex = interpolate(\n value,\n [-1, 0, 1],\n [0, size, 0],\n Extrapolate.CLAMP\n );\n\n const scale = interpolate(\n value,\n [-1, 0, 1],\n [\n parallaxAdjacentItemScale,\n parallaxScrollingScale,\n parallaxAdjacentItemScale,\n ],\n Extrapolate.CLAMP\n );\n\n return {\n transform: [\n vertical\n ? {\n translateY: translate,\n }\n : {\n translateX: translate,\n },\n {\n scale,\n },\n ],\n zIndex,\n };\n }, [loop, vertical, parallaxScrollingOffset]);\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1]) ||\n (index >= positiveRange[0] && index <= positiveRange[1])\n );\n },\n [index]\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange\n );\n },\n [visibleRanges.value]\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || '100%',\n height: height || '100%',\n position: 'absolute',\n },\n offsetXStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>{children}</LazyView>\n </Animated.View>\n );\n};\n"]}
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.parallaxLayout=parallaxLayout;var _reactNativeReanimated=require("react-native-reanimated");function parallaxLayout(baseConfig){var modeConfig=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var size=baseConfig.size,vertical=baseConfig.vertical;var _modeConfig$parallaxS=modeConfig.parallaxScrollingOffset,parallaxScrollingOffset=_modeConfig$parallaxS===void 0?100:_modeConfig$parallaxS,_modeConfig$parallaxS2=modeConfig.parallaxScrollingScale,parallaxScrollingScale=_modeConfig$parallaxS2===void 0?0.8:_modeConfig$parallaxS2;return function(){var _f=function _f(value){var translate=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset]);var zIndex=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[0,size,0],_reactNativeReanimated.Extrapolate.CLAMP);var scale=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[Math.pow(parallaxScrollingScale,2),parallaxScrollingScale,Math.pow(parallaxScrollingScale,2)],_reactNativeReanimated.Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};};_f._closure={interpolate:_reactNativeReanimated.interpolate,size:size,parallaxScrollingOffset:parallaxScrollingOffset,Extrapolate:{CLAMP:_reactNativeReanimated.Extrapolate.CLAMP},parallaxScrollingScale:parallaxScrollingScale,vertical:vertical};_f.asString="function _f(value){const{interpolate,size,parallaxScrollingOffset,Extrapolate,parallaxScrollingScale,vertical}=jsThis._closure;{const translate=interpolate(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset]);const zIndex=interpolate(value,[-1,0,1],[0,size,0],Extrapolate.CLAMP);const scale=interpolate(value,[-1,0,1],[Math.pow(parallaxScrollingScale,2),parallaxScrollingScale,Math.pow(parallaxScrollingScale,2)],Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};}}";_f.__workletHash=4897118335602;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/parallax.ts (38:11)";global.__reanimatedWorkletInit(_f);return _f;}();}
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.parallaxLayout=parallaxLayout;var _reactNativeReanimated=require("react-native-reanimated");function parallaxLayout(baseConfig){var modeConfig=arguments.length>1&&arguments[1]!==undefined?arguments[1]:{};var size=baseConfig.size,vertical=baseConfig.vertical;var _modeConfig$parallaxS=modeConfig.parallaxScrollingOffset,parallaxScrollingOffset=_modeConfig$parallaxS===void 0?100:_modeConfig$parallaxS,_modeConfig$parallaxS2=modeConfig.parallaxScrollingScale,parallaxScrollingScale=_modeConfig$parallaxS2===void 0?0.8:_modeConfig$parallaxS2,_modeConfig$parallaxA=modeConfig.parallaxAdjacentItemScale,parallaxAdjacentItemScale=_modeConfig$parallaxA===void 0?Math.pow(parallaxScrollingScale,2):_modeConfig$parallaxA;return function(){var _f=function _f(value){var translate=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset]);var zIndex=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[0,size,0],_reactNativeReanimated.Extrapolate.CLAMP);var scale=(0,_reactNativeReanimated.interpolate)(value,[-1,0,1],[parallaxAdjacentItemScale,parallaxScrollingScale,parallaxAdjacentItemScale],_reactNativeReanimated.Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};};_f._closure={interpolate:_reactNativeReanimated.interpolate,size:size,parallaxScrollingOffset:parallaxScrollingOffset,Extrapolate:{CLAMP:_reactNativeReanimated.Extrapolate.CLAMP},parallaxAdjacentItemScale:parallaxAdjacentItemScale,parallaxScrollingScale:parallaxScrollingScale,vertical:vertical};_f.asString="function _f(value){const{interpolate,size,parallaxScrollingOffset,Extrapolate,parallaxAdjacentItemScale,parallaxScrollingScale,vertical}=jsThis._closure;{const translate=interpolate(value,[-1,0,1],[-size+parallaxScrollingOffset,0,size-parallaxScrollingOffset]);const zIndex=interpolate(value,[-1,0,1],[0,size,0],Extrapolate.CLAMP);const scale=interpolate(value,[-1,0,1],[parallaxAdjacentItemScale,parallaxScrollingScale,parallaxAdjacentItemScale],Extrapolate.CLAMP);return{transform:[vertical?{translateY:translate}:{translateX:translate},{scale:scale}],zIndex:zIndex};}}";_f.__workletHash=942233491674;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/parallax.ts (46:11)";global.__reanimatedWorkletInit(_f);return _f;}();}
2
2
  //# sourceMappingURL=parallax.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["parallax.ts"],"names":["parallaxLayout","baseConfig","modeConfig","size","vertical","parallaxScrollingOffset","parallaxScrollingScale","value","translate","zIndex","Extrapolate","CLAMP","scale","Math","pow","transform","translateY","translateX","interpolate"],"mappings":"+FAAA,8DA6BO,QAASA,CAAAA,cAAT,CACHC,UADG,CAGL,IADEC,CAAAA,UACF,2DAD8B,EAC9B,CACE,GAAQC,CAAAA,IAAR,CAA2BF,UAA3B,CAAQE,IAAR,CAAcC,QAAd,CAA2BH,UAA3B,CAAcG,QAAd,CACA,0BACIF,UADJ,CAAQG,uBAAR,CAAQA,uBAAR,gCAAkC,GAAlC,8CACIH,UADJ,CAAuCI,sBAAvC,CAAuCA,sBAAvC,iCAAgE,GAAhE,wBAGA,qCAAQC,KAAR,CAA0B,CAEtB,GAAMC,CAAAA,SAAS,CAAG,uCACdD,KADc,CAEd,CAAC,CAAC,CAAF,CAAK,CAAL,CAAQ,CAAR,CAFc,CAGd,CAAC,CAACJ,IAAD,CAAQE,uBAAT,CAAkC,CAAlC,CAAqCF,IAAI,CAAGE,uBAA5C,CAHc,CAAlB,CAMA,GAAMI,CAAAA,MAAM,CAAG,uCACXF,KADW,CAEX,CAAC,CAAC,CAAF,CAAK,CAAL,CAAQ,CAAR,CAFW,CAGX,CAAC,CAAD,CAAIJ,IAAJ,CAAU,CAAV,CAHW,CAIXO,mCAAYC,KAJD,CAAf,CAOA,GAAMC,CAAAA,KAAK,CAAG,uCACVL,KADU,CAEV,CAAC,CAAC,CAAF,CAAK,CAAL,CAAQ,CAAR,CAFU,CAGV,CACIM,IAAI,CAACC,GAAL,CAASR,sBAAT,CAAiC,CAAjC,CADJ,CAEIA,sBAFJ,CAGIO,IAAI,CAACC,GAAL,CAASR,sBAAT,CAAiC,CAAjC,CAHJ,CAHU,CAQVI,mCAAYC,KARF,CAAd,CAWA,MAAO,CACHI,SAAS,CAAE,CACPX,QAAQ,CACF,CACIY,UAAU,CAAER,SADhB,CADE,CAIF,CACIS,UAAU,CAAET,SADhB,CALC,CAQP,CACII,KAAK,CAALA,KADJ,CARO,CADR,CAaHH,MAAM,CAANA,MAbG,CAAP,CAeH,CAzCD,0BAjCYS,kCAiCZ,MAlCgDf,IAkChD,yBAnC2FE,uBAmC3F,oBAjC+IK,mCAAYC,KAiC3J,yBAjCkHL,sBAiClH,UA/BYF,QA+BZ,6vBA0CH","sourcesContent":["import { Extrapolate, interpolate } from 'react-native-reanimated';\nimport type { ComputedDirectionTypes } from '../types';\n\ntype TBaseConfig = {\n size: number;\n vertical: boolean;\n};\n\ninterface ILayoutConfig {\n /**\n * When use default Layout props,this prop can be control prev/next item offset.\n * @default 100\n */\n parallaxScrollingOffset?: number;\n /**\n * When use default Layout props,this prop can be control prev/next item offset.\n * @default 0.8\n */\n parallaxScrollingScale?: number;\n}\n\nexport type TParallaxModeProps = ComputedDirectionTypes<{\n /**\n * Carousel Animated transitions.\n */\n mode?: 'parallax';\n modeConfig?: ILayoutConfig;\n}>;\n\nexport function parallaxLayout(\n baseConfig: TBaseConfig,\n modeConfig: ILayoutConfig = {}\n) {\n const { size, vertical } = baseConfig;\n const { parallaxScrollingOffset = 100, parallaxScrollingScale = 0.8 } =\n modeConfig;\n\n return (value: number) => {\n 'worklet';\n const translate = interpolate(\n value,\n [-1, 0, 1],\n [-size + parallaxScrollingOffset, 0, size - parallaxScrollingOffset]\n );\n\n const zIndex = interpolate(\n value,\n [-1, 0, 1],\n [0, size, 0],\n Extrapolate.CLAMP\n );\n\n const scale = interpolate(\n value,\n [-1, 0, 1],\n [\n Math.pow(parallaxScrollingScale, 2),\n parallaxScrollingScale,\n Math.pow(parallaxScrollingScale, 2),\n ],\n Extrapolate.CLAMP\n );\n\n return {\n transform: [\n vertical\n ? {\n translateY: translate,\n }\n : {\n translateX: translate,\n },\n {\n scale,\n },\n ],\n zIndex,\n };\n };\n}\n"]}
1
+ {"version":3,"sources":["parallax.ts"],"names":["parallaxLayout","baseConfig","modeConfig","size","vertical","parallaxScrollingOffset","parallaxScrollingScale","parallaxAdjacentItemScale","Math","pow","value","translate","zIndex","Extrapolate","CLAMP","scale","transform","translateY","translateX","interpolate"],"mappings":"+FAAA,8DAkCO,QAASA,CAAAA,cAAT,CACHC,UADG,CAGL,IADEC,CAAAA,UACF,2DAD8B,EAC9B,CACE,GAAQC,CAAAA,IAAR,CAA2BF,UAA3B,CAAQE,IAAR,CAAcC,QAAd,CAA2BH,UAA3B,CAAcG,QAAd,CACA,0BAIIF,UAJJ,CACIG,uBADJ,CACIA,uBADJ,gCAC8B,GAD9B,8CAIIH,UAJJ,CAEII,sBAFJ,CAEIA,sBAFJ,iCAE6B,GAF7B,8CAIIJ,UAJJ,CAGIK,yBAHJ,CAGIA,yBAHJ,gCAGgCC,IAAI,CAACC,GAAL,CAASH,sBAAT,CAAiC,CAAjC,CAHhC,uBAMA,qCAAQI,KAAR,CAA0B,CAEtB,GAAMC,CAAAA,SAAS,CAAG,uCACdD,KADc,CAEd,CAAC,CAAC,CAAF,CAAK,CAAL,CAAQ,CAAR,CAFc,CAGd,CAAC,CAACP,IAAD,CAAQE,uBAAT,CAAkC,CAAlC,CAAqCF,IAAI,CAAGE,uBAA5C,CAHc,CAAlB,CAMA,GAAMO,CAAAA,MAAM,CAAG,uCACXF,KADW,CAEX,CAAC,CAAC,CAAF,CAAK,CAAL,CAAQ,CAAR,CAFW,CAGX,CAAC,CAAD,CAAIP,IAAJ,CAAU,CAAV,CAHW,CAIXU,mCAAYC,KAJD,CAAf,CAOA,GAAMC,CAAAA,KAAK,CAAG,uCACVL,KADU,CAEV,CAAC,CAAC,CAAF,CAAK,CAAL,CAAQ,CAAR,CAFU,CAGV,CACIH,yBADJ,CAEID,sBAFJ,CAGIC,yBAHJ,CAHU,CAQVM,mCAAYC,KARF,CAAd,CAWA,MAAO,CACHE,SAAS,CAAE,CACPZ,QAAQ,CACF,CACIa,UAAU,CAAEN,SADhB,CADE,CAIF,CACIO,UAAU,CAAEP,SADhB,CALC,CAQP,CACII,KAAK,CAALA,KADJ,CARO,CADR,CAaHH,MAAM,CAANA,MAbG,CAAP,CAeH,CAzCD,0BAzCYO,kCAyCZ,MA1CgDhB,IA0ChD,yBA3C2FE,uBA2C3F,oBAzC2HQ,mCAAYC,KAyCvI,4BAzC+FP,yBAyC/F,wBAzCuED,sBAyCvE,UAvCYF,QAuCZ,owBA0CH","sourcesContent":["import { Extrapolate, interpolate } from 'react-native-reanimated';\nimport type { ComputedDirectionTypes } from '../types';\n\ntype TBaseConfig = {\n size: number;\n vertical: boolean;\n};\n\nexport interface ILayoutConfig {\n /**\n * control prev/next item offset.\n * @default 100\n */\n parallaxScrollingOffset?: number;\n /**\n * control prev/current/next item offset.\n * @default 0.8\n */\n parallaxScrollingScale?: number;\n /**\n * control prev/next item offset.\n * @default Math.pow(parallaxScrollingScale, 2)\n */\n parallaxAdjacentItemScale?: number;\n}\n\nexport type TParallaxModeProps = ComputedDirectionTypes<{\n /**\n * Carousel Animated transitions.\n */\n mode?: 'parallax';\n modeConfig?: ILayoutConfig;\n}>;\n\nexport function parallaxLayout(\n baseConfig: TBaseConfig,\n modeConfig: ILayoutConfig = {}\n) {\n const { size, vertical } = baseConfig;\n const {\n parallaxScrollingOffset = 100,\n parallaxScrollingScale = 0.8,\n parallaxAdjacentItemScale = Math.pow(parallaxScrollingScale, 2),\n } = modeConfig;\n\n return (value: number) => {\n 'worklet';\n const translate = interpolate(\n value,\n [-1, 0, 1],\n [-size + parallaxScrollingOffset, 0, size - parallaxScrollingOffset]\n );\n\n const zIndex = interpolate(\n value,\n [-1, 0, 1],\n [0, size, 0],\n Extrapolate.CLAMP\n );\n\n const scale = interpolate(\n value,\n [-1, 0, 1],\n [\n parallaxAdjacentItemScale,\n parallaxScrollingScale,\n parallaxAdjacentItemScale,\n ],\n Extrapolate.CLAMP\n );\n\n return {\n transform: [\n vertical\n ? {\n translateY: translate,\n }\n : {\n translateX: translate,\n },\n {\n scale,\n },\n ],\n zIndex,\n };\n };\n}\n"]}