react-native-reanimated-carousel 3.0.6 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/lib/commonjs/Carousel.js +1 -1
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +1 -1
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/module/Carousel.js +7 -7
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +23 -23
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +10 -6
- package/lib/module/hooks/useCommonVariables.js.map +1 -1
- package/lib/module/hooks/useOffsetX.js +3 -3
- package/lib/module/hooks/useOffsetX.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +3 -3
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/ParallaxLayout.js +2 -2
- package/lib/module/layouts/ParallaxLayout.js.map +1 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +1 -1
- package/lib/typescript/hooks/useCommonVariables.d.ts +1 -1
- package/lib/typescript/hooks/useOffsetX.d.ts +1 -1
- package/lib/typescript/layouts/BaseLayout.d.ts +1 -1
- package/lib/typescript/layouts/ParallaxLayout.d.ts +1 -1
- package/lib/typescript/types.d.ts +6 -2
- package/package.json +1 -1
- package/src/Carousel.tsx +7 -7
- package/src/hooks/useCarouselController.tsx +24 -27
- package/src/hooks/useCommonVariables.ts +15 -7
- package/src/hooks/useOffsetX.ts +4 -4
- package/src/layouts/BaseLayout.tsx +4 -4
- package/src/layouts/ParallaxLayout.tsx +3 -3
- package/src/types.ts +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# [3.1.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v3.0.6...v3.1.0) (2022-10-19)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Features
|
|
5
|
+
|
|
6
|
+
* add new props to control or get information for carousel animation ([2a39346](https://github.com/dohooo/react-native-reanimated-carousel/commit/2a3934647ca6558fdd1e213d79f5e64baaff3984)), closes [#285](https://github.com/dohooo/react-native-reanimated-carousel/issues/285)
|
|
7
|
+
|
|
1
8
|
## [3.0.6](https://github.com/dohooo/react-native-reanimated-carousel/compare/v3.0.5...v3.0.6) (2022-09-27)
|
|
2
9
|
|
|
3
10
|
|
package/lib/commonjs/Carousel.js
CHANGED
|
@@ -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=require("react-native-reanimated");var _useCarouselController=require("./hooks/useCarouselController");var _useAutoPlay2=require("./hooks/useAutoPlay");var _usePropsErrorBoundary=require("./hooks/usePropsErrorBoundary");var _ScrollViewGesture=require("./ScrollViewGesture");var _useVisibleRanges=require("./hooks/useVisibleRanges");var _reactNative=require("react-native");var _BaseLayout=require("./layouts/BaseLayout");var _useLayoutConfig=require("./hooks/useLayoutConfig");var _useInitProps=require("./hooks/useInitProps");var _store=require("./store");var _useCommonVariables=require("./hooks/useCommonVariables");var _useOnProgressChange=require("./hooks/useOnProgressChange");var _computedWithAutoFillData=require("./utils/computedWithAutoFillData");var _this=this,_jsxFileName="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/Carousel.tsx";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 testID=props.testID,data=props.data,rawData=props.rawData,loop=props.loop,autoFillData=props.autoFillData,mode=props.mode,style=props.style,width=props.width,height=props.height,vertical=props.vertical,autoPlay=props.autoPlay,windowSize=props.windowSize,autoPlayReverse=props.autoPlayReverse,autoPlayInterval=props.autoPlayInterval,scrollAnimationDuration=props.scrollAnimationDuration,withAnimation=props.withAnimation,renderItem=props.renderItem,onScrollEnd=props.onScrollEnd,onSnapToItem=props.onSnapToItem,_onScrollBegin=props.onScrollBegin,onProgressChange=props.onProgressChange,customAnimation=props.customAnimation,defaultIndex=props.defaultIndex;var commonVariables=(0,_useCommonVariables.useCommonVariables)(props);var size=commonVariables.size,
|
|
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=require("react-native-reanimated");var _useCarouselController=require("./hooks/useCarouselController");var _useAutoPlay2=require("./hooks/useAutoPlay");var _usePropsErrorBoundary=require("./hooks/usePropsErrorBoundary");var _ScrollViewGesture=require("./ScrollViewGesture");var _useVisibleRanges=require("./hooks/useVisibleRanges");var _reactNative=require("react-native");var _BaseLayout=require("./layouts/BaseLayout");var _useLayoutConfig=require("./hooks/useLayoutConfig");var _useInitProps=require("./hooks/useInitProps");var _store=require("./store");var _useCommonVariables=require("./hooks/useCommonVariables");var _useOnProgressChange=require("./hooks/useOnProgressChange");var _computedWithAutoFillData=require("./utils/computedWithAutoFillData");var _this=this,_jsxFileName="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/Carousel.tsx";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 testID=props.testID,data=props.data,rawData=props.rawData,loop=props.loop,autoFillData=props.autoFillData,mode=props.mode,style=props.style,width=props.width,height=props.height,vertical=props.vertical,autoPlay=props.autoPlay,windowSize=props.windowSize,autoPlayReverse=props.autoPlayReverse,autoPlayInterval=props.autoPlayInterval,scrollAnimationDuration=props.scrollAnimationDuration,withAnimation=props.withAnimation,renderItem=props.renderItem,onScrollEnd=props.onScrollEnd,onSnapToItem=props.onSnapToItem,_onScrollBegin=props.onScrollBegin,onProgressChange=props.onProgressChange,customAnimation=props.customAnimation,defaultIndex=props.defaultIndex;var commonVariables=(0,_useCommonVariables.useCommonVariables)(props);var size=commonVariables.size,handlerOffset=commonVariables.handlerOffset;var dataLength=data.length;var offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var totalSize=size*dataLength;var x=handlerOffset.value%totalSize;if(!loop){return handlerOffset.value;}return isNaN(x)?0:x;};_f._closure={size:size,dataLength:dataLength,handlerOffset:handlerOffset,loop:loop};_f.asString="function _f(){const{size,dataLength,handlerOffset,loop}=jsThis._closure;{const totalSize=size*dataLength;const x=handlerOffset.value%totalSize;if(!loop){return handlerOffset.value;}return isNaN(x)?0:x;}}";_f.__workletHash=15716230031535;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/Carousel.tsx (54:40)";return _f;}(),[loop,size,dataLength]);(0,_usePropsErrorBoundary.usePropsErrorBoundary)(props);(0,_useOnProgressChange.useOnProgressChange)({autoFillData:autoFillData,loop:loop,size:size,offsetX:offsetX,rawData:rawData,onProgressChange:onProgressChange});var carouselController=(0,_useCarouselController.useCarouselController)({loop:loop,size:size,data:data,autoFillData:autoFillData,handlerOffset:handlerOffset,withAnimation:withAnimation,defaultIndex:defaultIndex,onScrollEnd:function onScrollEnd(){return(0,_reactNativeReanimated.runOnJS)(_onScrollEnd)();},onScrollBegin:function onScrollBegin(){return!!_onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(_onScrollBegin)();},duration:scrollAnimationDuration});var next=carouselController.next,prev=carouselController.prev,scrollTo=carouselController.scrollTo,getSharedIndex=carouselController.getSharedIndex,getCurrentIndex=carouselController.getCurrentIndex;var _useAutoPlay=(0,_useAutoPlay2.useAutoPlay)({autoPlay:autoPlay,autoPlayInterval:autoPlayInterval,autoPlayReverse:autoPlayReverse,carouselController:carouselController}),startAutoPlay=_useAutoPlay.start,pauseAutoPlay=_useAutoPlay.pause;var _onScrollEnd=_react.default.useCallback(function(){var _sharedIndex=Math.round(getSharedIndex());var realIndex=(0,_computedWithAutoFillData.computedRealIndexWithAutoFillData)({index:_sharedIndex,dataLength:rawData.length,loop:loop,autoFillData:autoFillData});if(onSnapToItem){onSnapToItem(realIndex);}if(onScrollEnd){onScrollEnd(realIndex);}},[loop,autoFillData,rawData.length,getSharedIndex,onSnapToItem,onScrollEnd]);var scrollViewGestureOnScrollBegin=_react.default.useCallback(function(){pauseAutoPlay();_onScrollBegin==null?void 0:_onScrollBegin();},[_onScrollBegin,pauseAutoPlay]);var scrollViewGestureOnScrollEnd=_react.default.useCallback(function(){startAutoPlay();_onScrollEnd();},[_onScrollEnd,startAutoPlay]);var scrollViewGestureOnTouchBegin=_react.default.useCallback(pauseAutoPlay,[pauseAutoPlay]);var scrollViewGestureOnTouchEnd=_react.default.useCallback(startAutoPlay,[startAutoPlay]);_react.default.useImperativeHandle(ref,function(){return{next:next,prev:prev,getCurrentIndex:getCurrentIndex,scrollTo:scrollTo};},[getCurrentIndex,next,prev,scrollTo]);var visibleRanges=(0,_useVisibleRanges.useVisibleRanges)({total:data.length,viewSize:size,translation:handlerOffset,windowSize:windowSize});var layoutConfig=(0,_useLayoutConfig.useLayoutConfig)(_objectSpread(_objectSpread({},props),{},{size:size}));var renderLayout=_react.default.useCallback(function(item,i){var realIndex=(0,_computedWithAutoFillData.computedRealIndexWithAutoFillData)({index:i,dataLength:rawData.length,loop:loop,autoFillData:autoFillData});return _react.default.createElement(_BaseLayout.BaseLayout,{key:i,index:i,handlerOffset:offsetX,visibleRanges:visibleRanges,animationStyle:customAnimation||layoutConfig,__self:_this,__source:{fileName:_jsxFileName,lineNumber:170,columnNumber:21}},function(_ref){var animationValue=_ref.animationValue;return renderItem({item:item,index:realIndex,animationValue:animationValue});});},[loop,rawData,offsetX,visibleRanges,autoFillData,renderItem,layoutConfig,customAnimation]);return _react.default.createElement(_store.CTX.Provider,{value:{props:props,common:commonVariables},__self:_this,__source:{fileName:_jsxFileName,lineNumber:200,columnNumber:13}},_react.default.createElement(_ScrollViewGesture.ScrollViewGesture,{key:mode,size:size,translation:handlerOffset,style:[styles.container,{width:width||'100%',height:height||'100%'},style,vertical?styles.itemsVertical:styles.itemsHorizontal],testID:testID,onScrollBegin:scrollViewGestureOnScrollBegin,onScrollEnd:scrollViewGestureOnScrollEnd,onTouchBegin:scrollViewGestureOnTouchBegin,onTouchEnd:scrollViewGestureOnTouchEnd,__self:_this,__source:{fileName:_jsxFileName,lineNumber:201,columnNumber:17}},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","testID","data","rawData","loop","autoFillData","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffsetX","dataLength","length","offsetX","totalSize","x","value","isNaN","carouselController","_onScrollEnd","duration","next","prev","scrollTo","getSharedIndex","getCurrentIndex","startAutoPlay","start","pauseAutoPlay","pause","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","i","animationValue","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":"iQAAA,oDACA,8DAEA,oEACA,iDACA,oEACA,sDACA,0DAGA,yCACA,gDACA,wDACA,kDACA,8BACA,8DACA,gEACA,0E,i4BAEA,GAAMA,CAAAA,QAAQ,CAAGC,eAAMC,UAAN,CACb,SAACC,MAAD,CAASC,GAAT,CAAiB,CACb,GAAMC,CAAAA,KAAK,CAAG,+BAAaF,MAAb,CAAd,CAEA,GACIG,CAAAA,MADJ,CAwBID,KAxBJ,CACIC,MADJ,CAEIC,IAFJ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AA,UAAU,CAAC,CACP8C,IAAI,CAAJA,IADO,CAEPZ,KAAK,CAAED,SAFA,CAGPe,cAAc,CAAdA,cAHO,CAAD,CADb,EAPL,CADJ,CAiBH,CA1BgB,CA2BjB,CACI7D,IADJ,CAEID,OAFJ,CAGI0B,OAHJ,CAII4B,aAJJ,CAKIpD,YALJ,CAMIY,UANJ,CAOI4C,YAPJ,CAQIvC,eARJ,CA3BiB,CAArB,CAuCA,MACI,8BAAC,UAAD,CAAK,QAAL,EAAc,KAAK,CAAE,CAAEtB,KAAK,CAALA,KAAF,CAASkE,MAAM,CAAE1C,eAAjB,CAArB,+EACI,6BAAC,oCAAD,EACI,GAAG,CAAElB,IADT,CAEI,IAAI,CAAEmB,IAFV,CAGI,WAAW,CAAEC,cAHjB,CAII,KAAK,CAAE,CACHyC,MAAM,CAACC,SADJ,CAEH,CACI5D,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAFG,CAMHF,KANG,CAOHG,QAAQ,CACFyD,MAAM,CAACE,aADL,CAEFF,MAAM,CAACG,eATV,CAJX,CAeI,MAAM,CAAErE,MAfZ,CAgBI,aAAa,CAAEmD,8BAhBnB,CAiBI,WAAW,CAAEC,4BAjBjB,CAkBI,YAAY,CAAEC,6BAlBlB,CAmBI,UAAU,CAAEC,2BAnBhB,+EAqBKrD,IAAI,CAACqE,GAAL,CAAST,YAAT,CArBL,CADJ,CADJ,CA2BH,CA9MY,CAAjB,C,aAiNenE,Q,0BAIf,GAAMwE,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 { 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 } from 'react-native';\nimport { BaseLayout } from './layouts/BaseLayout';\nimport { useLayoutConfig } from './hooks/useLayoutConfig';\nimport { useInitProps } from './hooks/useInitProps';\nimport { CTX } from './store';\nimport { useCommonVariables } from './hooks/useCommonVariables';\nimport { useOnProgressChange } from './hooks/useOnProgressChange';\nimport { computedRealIndexWithAutoFillData } from './utils/computedWithAutoFillData';\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n data,\n rawData,\n loop,\n autoFillData,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffsetX } = commonVariables;\n const dataLength = data.length;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffsetX.value % totalSize;\n\n if (!loop) {\n return handlerOffsetX.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary(props);\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawData,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n data,\n autoFillData,\n handlerOffsetX,\n withAnimation,\n defaultIndex,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n duration: scrollAnimationDuration,\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex } =\n carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawData.length,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem) {\n onSnapToItem(realIndex);\n }\n if (onScrollEnd) {\n onScrollEnd(realIndex);\n }\n }, [\n loop,\n autoFillData,\n rawData.length,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pauseAutoPlay();\n onScrollBegin?.();\n }, [onScrollBegin, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n }),\n [getCurrentIndex, next, prev, scrollTo]\n );\n\n const visibleRanges = useVisibleRanges({\n total: data.length,\n viewSize: size,\n translation: handlerOffsetX,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index: i,\n dataLength: rawData.length,\n loop,\n autoFillData,\n });\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffsetX={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n loop,\n rawData,\n offsetX,\n visibleRanges,\n autoFillData,\n renderItem,\n layoutConfig,\n customAnimation,\n ]\n );\n\n return (\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffsetX}\n style={[\n styles.container,\n {\n width: width || '100%',\n height: height || '100%',\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n {data.map(renderLayout)}\n </ScrollViewGesture>\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","testID","data","rawData","loop","autoFillData","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffset","dataLength","length","offsetX","totalSize","x","value","isNaN","carouselController","_onScrollEnd","duration","next","prev","scrollTo","getSharedIndex","getCurrentIndex","startAutoPlay","start","pauseAutoPlay","pause","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","i","animationValue","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":"iQ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Q,0BAIf,GAAMwE,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 { 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 } from 'react-native';\nimport { BaseLayout } from './layouts/BaseLayout';\nimport { useLayoutConfig } from './hooks/useLayoutConfig';\nimport { useInitProps } from './hooks/useInitProps';\nimport { CTX } from './store';\nimport { useCommonVariables } from './hooks/useCommonVariables';\nimport { useOnProgressChange } from './hooks/useOnProgressChange';\nimport { computedRealIndexWithAutoFillData } from './utils/computedWithAutoFillData';\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n data,\n rawData,\n loop,\n autoFillData,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffset } = commonVariables;\n const dataLength = data.length;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n\n if (!loop) {\n return handlerOffset.value;\n }\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary(props);\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawData,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n data,\n autoFillData,\n handlerOffset,\n withAnimation,\n defaultIndex,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n duration: scrollAnimationDuration,\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex } =\n carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawData.length,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem) {\n onSnapToItem(realIndex);\n }\n if (onScrollEnd) {\n onScrollEnd(realIndex);\n }\n }, [\n loop,\n autoFillData,\n rawData.length,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pauseAutoPlay();\n onScrollBegin?.();\n }, [onScrollBegin, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n }),\n [getCurrentIndex, next, prev, scrollTo]\n );\n\n const visibleRanges = useVisibleRanges({\n total: data.length,\n viewSize: size,\n translation: handlerOffset,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index: i,\n dataLength: rawData.length,\n loop,\n autoFillData,\n });\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffset={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n loop,\n rawData,\n offsetX,\n visibleRanges,\n autoFillData,\n renderItem,\n layoutConfig,\n customAnimation,\n ]\n );\n\n return (\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffset}\n style={[\n styles.container,\n {\n width: width || '100%',\n height: height || '100%',\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n {data.map(renderLayout)}\n </ScrollViewGesture>\n </CTX.Provider>\n );\n }\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: 'hidden',\n },\n itemsHorizontal: {\n flexDirection: 'row',\n },\n itemsVertical: {\n flexDirection: 'column',\n },\n});\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireWildcard(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _log=require("../utils/log");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 useCarouselController(options){var size=options.size,data=options.data,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex,duration=options.duration,autoFillData=options.autoFillData;var dataInfo=_react.default.useMemo(function(){return{length:data.length,disable:!data.length,originalLength:data.length};},[data]);var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=(0,_react.useRef)(defaultIndex);var sharedPreIndex=(0,_react.useRef)(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%dataInfo.length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?dataInfo.length-fixed:0));},[handlerOffsetX,dataInfo,size,loop]);function setSharedIndex(newSharedIndex){sharedIndex.current=newSharedIndex;}(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){var handlerOffsetXValue=handlerOffsetX.value;var toInt=(0,_log.round)(handlerOffsetXValue/size)%dataInfo.length;var isPositive=handlerOffsetXValue<=0;var i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);var newSharedIndexValue=(0,_computedWithAutoFillData.convertToSharedIndex)({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};};_f._closure={handlerOffsetX:handlerOffsetX,round:_log.round,size:size,dataInfo:dataInfo,convertToSharedIndex:_computedWithAutoFillData.convertToSharedIndex,loop:loop,autoFillData:autoFillData};_f.asString="function _f(){const{handlerOffsetX,round,size,dataInfo,convertToSharedIndex,loop,autoFillData}=jsThis._closure;{const handlerOffsetXValue=handlerOffsetX.value;const toInt=round(handlerOffsetXValue/size)%dataInfo.length;const isPositive=handlerOffsetXValue<=0;const i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);const newSharedIndexValue=convertToSharedIndex({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};}}";_f.__workletHash=14011541648783;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (83:8)";return _f;}(),function(){var _f=function _f(_ref){var i=_ref.i,newSharedIndexValue=_ref.newSharedIndexValue;index.value=i;(0,_reactNativeReanimated.runOnJS)(setSharedIndex)(newSharedIndexValue);};_f._closure={index:index,runOnJS:_reactNativeReanimated.runOnJS,setSharedIndex:setSharedIndex};_f.asString="function _f({i:i,newSharedIndexValue:newSharedIndexValue}){const{index,runOnJS,setSharedIndex}=jsThis._closure;{index.value=i;runOnJS(setSharedIndex)(newSharedIndexValue);}}";_f.__workletHash=16638491076412;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (103:8)";return _f;}(),[sharedPreIndex,sharedIndex,size,dataInfo,index,loop,autoFillData,handlerOffsetX]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!dataInfo.disable;},[dataInfo]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (138:29)";return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (136:8)";return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,dataInfo:dataInfo,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,dataInfo,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=1734401141936;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (160:8)";return _f;}(),[canSliding,loop,index,dataInfo,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(opts){var i=opts.i,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(i===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var isPositiveZero=Object.is(handlerOffsetX.value,+0);var isNegativeZero=Object.is(handlerOffsetX.value,-0);var direction=isPositiveZero?1:isNegativeZero?-1:Math.sign(handlerOffsetX.value);var offset=i*size*direction;var totalSize=dataInfo.length*size;var isCloseToNextLoop=false;if(loop){isCloseToNextLoop=Math.abs(handlerOffsetX.value%totalSize)/totalSize>=0.5;}var finalOffset=(Math.floor(Math.abs(handlerOffsetX.value/totalSize))+(isCloseToNextLoop?1:0))*totalSize*direction+offset;if(animated){index.value=i;handlerOffsetX.value=scrollWithTiming(finalOffset,onFinished);}else{handlerOffsetX.value=finalOffset;index.value=i;onFinished==null?void 0:onFinished();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,dataInfo.length,loop,scrollWithTiming]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var i=opts.index,count=opts.count,_opts$animated4=opts.animated,animated=_opts$animated4===void 0?false:_opts$animated4,onFinished=opts.onFinished;if(typeof i==='number'&&i>-1){to({i:i,animated:animated,onFinished:onFinished});return;}if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next,to]);return{next:next,prev:prev,scrollTo:scrollTo,getCurrentIndex:getCurrentIndex,getSharedIndex:function getSharedIndex(){return sharedIndex.current;}};}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireWildcard(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _log=require("../utils/log");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 useCarouselController(options){var size=options.size,data=options.data,loop=options.loop,handlerOffset=options.handlerOffset,withAnimation=options.withAnimation,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex,duration=options.duration,autoFillData=options.autoFillData;var dataInfo=_react.default.useMemo(function(){return{length:data.length,disable:!data.length,originalLength:data.length};},[data]);var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=(0,_react.useRef)(defaultIndex);var sharedPreIndex=(0,_react.useRef)(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffset.value/size);}var fixed=handlerOffset.value/size%dataInfo.length;return Math.round(handlerOffset.value<=0?Math.abs(fixed):Math.abs(fixed>0?dataInfo.length-fixed:0));},[handlerOffset,dataInfo,size,loop]);function setSharedIndex(newSharedIndex){sharedIndex.current=newSharedIndex;}(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){var handlerOffsetValue=handlerOffset.value;var toInt=(0,_log.round)(handlerOffsetValue/size)%dataInfo.length;var isPositive=handlerOffsetValue<=0;var i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);var newSharedIndexValue=(0,_computedWithAutoFillData.convertToSharedIndex)({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};};_f._closure={handlerOffset:handlerOffset,round:_log.round,size:size,dataInfo:dataInfo,convertToSharedIndex:_computedWithAutoFillData.convertToSharedIndex,loop:loop,autoFillData:autoFillData};_f.asString="function _f(){const{handlerOffset,round,size,dataInfo,convertToSharedIndex,loop,autoFillData}=jsThis._closure;{const handlerOffsetValue=handlerOffset.value;const toInt=round(handlerOffsetValue/size)%dataInfo.length;const isPositive=handlerOffsetValue<=0;const i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);const newSharedIndexValue=convertToSharedIndex({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};}}";_f.__workletHash=442719064151;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (83:8)";return _f;}(),function(){var _f=function _f(_ref){var i=_ref.i,newSharedIndexValue=_ref.newSharedIndexValue;index.value=i;(0,_reactNativeReanimated.runOnJS)(setSharedIndex)(newSharedIndexValue);};_f._closure={index:index,runOnJS:_reactNativeReanimated.runOnJS,setSharedIndex:setSharedIndex};_f.asString="function _f({i:i,newSharedIndexValue:newSharedIndexValue}){const{index,runOnJS,setSharedIndex}=jsThis._closure;{index.value=i;runOnJS(setSharedIndex)(newSharedIndexValue);}}";_f.__workletHash=16638491076412;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (103:8)";return _f;}(),[sharedPreIndex,sharedIndex,size,dataInfo,index,loop,autoFillData,handlerOffset]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!dataInfo.disable;},[dataInfo]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (138:29)";return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (136:8)";return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffset.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffset.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,dataInfo:dataInfo,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffset:handlerOffset,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,dataInfo,onScrollBegin,currentFixedPage,handlerOffset,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffset.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffset.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=10530429864168;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (160:8)";return _f;}(),[canSliding,loop,index,dataInfo,onScrollBegin,handlerOffset,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffset.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffset.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffset,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(opts){var i=opts.i,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(i===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var isPositiveZero=Object.is(handlerOffset.value,+0);var isNegativeZero=Object.is(handlerOffset.value,-0);var direction=isPositiveZero?1:isNegativeZero?-1:Math.sign(handlerOffset.value);var offset=i*size*direction;var totalSize=dataInfo.length*size;var isCloseToNextLoop=false;if(loop){isCloseToNextLoop=Math.abs(handlerOffset.value%totalSize)/totalSize>=0.5;}var finalOffset=(Math.floor(Math.abs(handlerOffset.value/totalSize))+(isCloseToNextLoop?1:0))*totalSize*direction+offset;if(animated){index.value=i;handlerOffset.value=scrollWithTiming(finalOffset,onFinished);}else{handlerOffset.value=finalOffset;index.value=i;onFinished==null?void 0:onFinished();}},[index,canSliding,onScrollBegin,handlerOffset,size,dataInfo.length,loop,scrollWithTiming]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var i=opts.index,count=opts.count,_opts$animated4=opts.animated,animated=_opts$animated4===void 0?false:_opts$animated4,onFinished=opts.onFinished;if(typeof i==='number'&&i>-1){to({i:i,animated:animated,onFinished:onFinished});return;}if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next,to]);return{next:next,prev:prev,scrollTo:scrollTo,getCurrentIndex:getCurrentIndex,getSharedIndex:function getSharedIndex(){return sharedIndex.current;}};}
|
|
2
2
|
//# sourceMappingURL=useCarouselController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","React","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","convertToSharedIndex","runOnJS","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","isPositiveZero","Object","is","isNegativeZero","direction","sign","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"6GAAA,qDAEA,uCACA,8DAUA,6DACA,2EACA,iC,0/BAuBO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CASID,OATJ,CACIC,IADJ,CAEIC,IAFJ,CASIF,OATJ,CAEIE,IAFJ,CAGIC,IAHJ,CASIH,OATJ,CAGIG,IAHJ,CAIIC,cAJJ,CASIJ,OATJ,CAIII,cAJJ,CAKIC,aALJ,CASIL,OATJ,CAKIK,aALJ,uBASIL,OATJ,CAMIM,YANJ,CAMIA,YANJ,gCAMmB,CANnB,uBAOIC,QAPJ,CASIP,OATJ,CAOIO,QAPJ,CAQIC,YARJ,CASIR,OATJ,CAQIQ,YARJ,CAWA,GAAMC,CAAAA,QAAQ,CAAGC,eAAMC,OAAN,CACb,iBAAO,CACHC,MAAM,CAAEV,IAAI,CAACU,MADV,CAEHC,O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,CAAQtC,KAAR,CAAkBuC,KAAlB,CAA0DD,IAA1D,CAAkBC,KAAlB,iBAA0DD,IAA1D,CAAyBE,QAAzB,CAAyBA,QAAzB,0BAAoC,KAApC,iBAA2Cb,UAA3C,CAA0DW,IAA1D,CAA2CX,UAA3C,CACA,GAAI,MAAOX,CAAAA,CAAP,GAAa,QAAb,EAAyBA,CAAC,CAAG,CAAC,CAAlC,CAAqC,CACjC4B,EAAE,CAAC,CAAE5B,CAAC,CAADA,CAAF,CAAKwB,QAAQ,CAARA,QAAL,CAAeb,UAAU,CAAVA,UAAf,CAAD,CAAF,CACA,OACH,CAED,GAAI,CAACY,KAAL,CAAY,CACR,OACH,CAED,GAAMkB,CAAAA,CAAC,CAAGpD,IAAI,CAACC,KAAL,CAAWiC,KAAX,CAAV,CAEA,GAAIkB,CAAC,CAAG,CAAR,CAAW,CACPf,IAAI,CAAC,CAAEH,KAAK,CAAElC,IAAI,CAACI,GAAL,CAASgD,CAAT,CAAT,CAAsBjB,QAAQ,CAARA,QAAtB,CAAgCb,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHU,IAAI,CAAC,CAAEE,KAAK,CAAEkB,CAAT,CAAYjB,QAAQ,CAARA,QAAZ,CAAsBb,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAnBY,CAoBb,CAACe,IAAD,CAAOL,IAAP,CAAaO,EAAb,CApBa,CAAjB,CAuBA,MAAO,CACHP,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHc,QAAQ,CAARA,QAHG,CAIHnC,eAAe,CAAfA,eAJG,CAKHqC,cAAc,CAAE,gCAAMzD,CAAAA,WAAW,CAACW,OAAlB,EALb,CAAP,CAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\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 >= dataInfo.length - 1))\n 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 dataInfo,\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 (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const isPositiveZero = Object.is(handlerOffsetX.value, +0);\n const isNegativeZero = Object.is(handlerOffsetX.value, -0);\n const direction = isPositiveZero\n ? 1\n : isNegativeZero\n ? -1\n : Math.sign(handlerOffsetX.value);\n\n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffsetX.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffsetX.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(\n finalOffset,\n onFinished\n );\n } else {\n handlerOffsetX.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\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, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","data","loop","handlerOffset","withAnimation","defaultIndex","duration","autoFillData","dataInfo","React","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","convertToSharedIndex","runOnJS","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","isPositiveZero","Object","is","isNegativeZero","direction","sign","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"6GAAA,qDAEA,uCACA,8DAUA,6DACA,2EACA,iC,0/BAuBO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CASID,OATJ,CACIC,IADJ,CAEIC,IAFJ,CASIF,OATJ,CAEIE,IAFJ,CAGIC,IAHJ,CASIH,OATJ,CAGIG,IAHJ,CAIIC,aAJJ,CASIJ,OATJ,CAIII,aAJJ,CAKIC,aALJ,CASIL,OATJ,CAKIK,aALJ,uBASIL,OATJ,CAMIM,YANJ,CAMIA,YANJ,gCAMmB,CANnB,uBAOIC,QAPJ,CASIP,OATJ,CAOIO,QAPJ,CAQIC,YARJ,CASIR,OATJ,CAQIQ,YARJ,CAWA,GAAMC,CAAAA,QAAQ,CAAGC,eAAMC,OAAN,CACb,iBAAO,CACHC,MAAM,CAAEV,IAAI,CAACU,MADV,CAEHC,OAAO,C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R,CAAkBuC,KAAlB,CAA0DD,IAA1D,CAAkBC,KAAlB,iBAA0DD,IAA1D,CAAyBE,QAAzB,CAAyBA,QAAzB,0BAAoC,KAApC,iBAA2Cb,UAA3C,CAA0DW,IAA1D,CAA2CX,UAA3C,CACA,GAAI,MAAOX,CAAAA,CAAP,GAAa,QAAb,EAAyBA,CAAC,CAAG,CAAC,CAAlC,CAAqC,CACjC4B,EAAE,CAAC,CAAE5B,CAAC,CAADA,CAAF,CAAKwB,QAAQ,CAARA,QAAL,CAAeb,UAAU,CAAVA,UAAf,CAAD,CAAF,CACA,OACH,CAED,GAAI,CAACY,KAAL,CAAY,CACR,OACH,CAED,GAAMkB,CAAAA,CAAC,CAAGpD,IAAI,CAACC,KAAL,CAAWiC,KAAX,CAAV,CAEA,GAAIkB,CAAC,CAAG,CAAR,CAAW,CACPf,IAAI,CAAC,CAAEH,KAAK,CAAElC,IAAI,CAACI,GAAL,CAASgD,CAAT,CAAT,CAAsBjB,QAAQ,CAARA,QAAtB,CAAgCb,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHU,IAAI,CAAC,CAAEE,KAAK,CAAEkB,CAAT,CAAYjB,QAAQ,CAARA,QAAZ,CAAsBb,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAnBY,CAoBb,CAACe,IAAD,CAAOL,IAAP,CAAaO,EAAb,CApBa,CAAjB,CAuBA,MAAO,CACHP,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHc,QAAQ,CAARA,QAHG,CAIHnC,eAAe,CAAfA,eAJG,CAKHqC,cAAc,CAAE,gCAAMzD,CAAAA,WAAW,CAACW,OAAlB,EALb,CAAP,CAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffset: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffset,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffset.value / size);\n }\n\n const fixed = (handlerOffset.value / size) % dataInfo.length;\n return Math.round(\n handlerOffset.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffset, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetValue = handlerOffset.value;\n const toInt = round(handlerOffsetValue / size) % dataInfo.length;\n const isPositive = handlerOffsetValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffset,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\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 >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffset.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffset.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffset,\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 handlerOffset.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffset.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffset,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const isPositiveZero = Object.is(handlerOffset.value, +0);\n const isNegativeZero = Object.is(handlerOffset.value, -0);\n const direction = isPositiveZero\n ? 1\n : isNegativeZero\n ? -1\n : Math.sign(handlerOffset.value);\n\n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffset.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffset.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffset.value = scrollWithTiming(finalOffset, onFinished);\n } else {\n handlerOffset.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffset,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\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, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCommonVariables=useCommonVariables;var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=require("react-native-reanimated");function useCommonVariables(props){var vertical=props.vertical,height=props.height,width=props.width,data=props.data,defaultIndex=props.defaultIndex;var size=vertical?height:width;var validLength=data.length-1;var
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCommonVariables=useCommonVariables;var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=require("react-native-reanimated");function useCommonVariables(props){var vertical=props.vertical,height=props.height,width=props.width,data=props.data,defaultIndex=props.defaultIndex,defaultScrollOffsetValue=props.defaultScrollOffsetValue;var size=vertical?height:width;var validLength=data.length-1;var defaultHandlerOffsetValue=-Math.abs(defaultIndex*size);var _handlerOffset=(0,_reactNativeReanimated.useSharedValue)(defaultHandlerOffsetValue);var handlerOffset=defaultScrollOffsetValue!=null?defaultScrollOffsetValue:_handlerOffset;_react.default.useEffect(function(){handlerOffset.value=defaultHandlerOffsetValue;},[vertical,handlerOffset,defaultHandlerOffsetValue]);return{size:size,validLength:validLength,handlerOffset:handlerOffset};}
|
|
2
2
|
//# sourceMappingURL=useCommonVariables.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useCommonVariables.ts"],"names":["useCommonVariables","props","vertical","height","width","data","defaultIndex","size","validLength","length","
|
|
1
|
+
{"version":3,"sources":["useCommonVariables.ts"],"names":["useCommonVariables","props","vertical","height","width","data","defaultIndex","defaultScrollOffsetValue","size","validLength","length","defaultHandlerOffsetValue","Math","abs","_handlerOffset","handlerOffset","React","useEffect","value"],"mappings":"0LAAA,oDACA,8DASO,QAASA,CAAAA,kBAAT,CACHC,KADG,CAEa,CAChB,GACIC,CAAAA,QADJ,CAOID,KAPJ,CACIC,QADJ,CAEIC,MAFJ,CAOIF,KAPJ,CAEIE,MAFJ,CAGIC,KAHJ,CAOIH,KAPJ,CAGIG,KAHJ,CAIIC,IAJJ,CAOIJ,KAPJ,CAIII,IAJJ,CAKIC,YALJ,CAOIL,KAPJ,CAKIK,YALJ,CAMIC,wBANJ,CAOIN,KAPJ,CAMIM,wBANJ,CAQA,GAAMC,CAAAA,IAAI,CAAGN,QAAQ,CAAGC,MAAH,CAAYC,KAAjC,CACA,GAAMK,CAAAA,WAAW,CAAGJ,IAAI,CAACK,MAAL,CAAc,CAAlC,CACA,GAAMC,CAAAA,yBAAyB,CAAG,CAACC,IAAI,CAACC,GAAL,CAASP,YAAY,CAAGE,IAAxB,CAAnC,CACA,GAAMM,CAAAA,cAAc,CAAG,0CAAuBH,yBAAvB,CAAvB,CACA,GAAMI,CAAAA,aAAa,CAAGR,wBAAH,OAAGA,wBAAH,CAA+BO,cAAlD,CAEAE,eAAMC,SAAN,CAAgB,UAAM,CAClBF,aAAa,CAACG,KAAd,CAAsBP,yBAAtB,CACH,CAFD,CAEG,CAACT,QAAD,CAAWa,aAAX,CAA0BJ,yBAA1B,CAFH,EAIA,MAAO,CACHH,IAAI,CAAJA,IADG,CAEHC,WAAW,CAAXA,WAFG,CAGHM,aAAa,CAAbA,aAHG,CAAP,CAKH","sourcesContent":["import React from 'react';\nimport Animated, { useSharedValue } from 'react-native-reanimated';\nimport type { TInitializeCarouselProps } from './useInitProps';\n\ninterface ICommonVariables {\n size: number;\n validLength: number;\n handlerOffset: Animated.SharedValue<number>;\n}\n\nexport function useCommonVariables(\n props: TInitializeCarouselProps<any>\n): ICommonVariables {\n const {\n vertical,\n height,\n width,\n data,\n defaultIndex,\n defaultScrollOffsetValue,\n } = props;\n const size = vertical ? height : width;\n const validLength = data.length - 1;\n const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);\n const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);\n const handlerOffset = defaultScrollOffsetValue ?? _handlerOffset;\n\n React.useEffect(() => {\n handlerOffset.value = defaultHandlerOffsetValue;\n }, [vertical, handlerOffset, defaultHandlerOffsetValue]);\n\n return {\n size,\n validLength,\n handlerOffset,\n };\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,"__esModule",{value:true});exports.useOffsetX=void 0;var _reactNativeReanimated=require("react-native-reanimated");var useOffsetX=function useOffsetX(opts,visibleRanges){var
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.useOffsetX=void 0;var _reactNativeReanimated=require("react-native-reanimated");var useOffsetX=function useOffsetX(opts,visibleRanges){var handlerOffset=opts.handlerOffset,index=opts.index,size=opts.size,loop=opts.loop,data=opts.data,_opts$type=opts.type,type=_opts$type===void 0?'positive':_opts$type,_opts$viewCount=opts.viewCount,viewCount=_opts$viewCount===void 0?Math.round((data.length-1)/2):_opts$viewCount;var ITEM_LENGTH=data.length;var VALID_LENGTH=ITEM_LENGTH-1;var TOTAL_WIDTH=size*ITEM_LENGTH;var HALF_WIDTH=0.5*size;var positiveCount=type==='positive'?viewCount:VALID_LENGTH-viewCount;var startPos=size*index;if(index>positiveCount){startPos=(index-ITEM_LENGTH)*size;}var MAX=positiveCount*size;var MIN=-((VALID_LENGTH-positiveCount)*size);var x=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var _visibleRanges$value=visibleRanges.value,negativeRange=_visibleRanges$value.negativeRange,positiveRange=_visibleRanges$value.positiveRange;if((index<negativeRange[0]||index>negativeRange[1])&&(index<positiveRange[0]||index>positiveRange[1])){return Number.MAX_SAFE_INTEGER;}if(loop){var inputRange=[-TOTAL_WIDTH,MIN-HALF_WIDTH-startPos-Number.MIN_VALUE,MIN-HALF_WIDTH-startPos,0,MAX+HALF_WIDTH-startPos,MAX+HALF_WIDTH-startPos+Number.MIN_VALUE,TOTAL_WIDTH];var outputRange=[startPos,MAX+HALF_WIDTH-Number.MIN_VALUE,MIN-HALF_WIDTH,startPos,MAX+HALF_WIDTH,MIN-HALF_WIDTH+Number.MIN_VALUE,startPos];return(0,_reactNativeReanimated.interpolate)(handlerOffset.value,inputRange,outputRange,_reactNativeReanimated.Extrapolate.CLAMP);}return handlerOffset.value+size*index;};_f._closure={visibleRanges:visibleRanges,index:index,loop:loop,TOTAL_WIDTH:TOTAL_WIDTH,MIN:MIN,HALF_WIDTH:HALF_WIDTH,startPos:startPos,MAX:MAX,interpolate:_reactNativeReanimated.interpolate,handlerOffset:handlerOffset,Extrapolate:{CLAMP:_reactNativeReanimated.Extrapolate.CLAMP},size:size};_f.asString="function _f(){const{visibleRanges,index,loop,TOTAL_WIDTH,MIN,HALF_WIDTH,startPos,MAX,interpolate,handlerOffset,Extrapolate,size}=jsThis._closure;{const{negativeRange:negativeRange,positiveRange:positiveRange}=visibleRanges.value;if((index<negativeRange[0]||index>negativeRange[1])&&(index<positiveRange[0]||index>positiveRange[1])){return Number.MAX_SAFE_INTEGER;}if(loop){const inputRange=[-TOTAL_WIDTH,MIN-HALF_WIDTH-startPos-Number.MIN_VALUE,MIN-HALF_WIDTH-startPos,0,MAX+HALF_WIDTH-startPos,MAX+HALF_WIDTH-startPos+Number.MIN_VALUE,TOTAL_WIDTH];const outputRange=[startPos,MAX+HALF_WIDTH-Number.MIN_VALUE,MIN-HALF_WIDTH,startPos,MAX+HALF_WIDTH,MIN-HALF_WIDTH+Number.MIN_VALUE,startPos];return interpolate(handlerOffset.value,inputRange,outputRange,Extrapolate.CLAMP);}return handlerOffset.value+size*index;}}";_f.__workletHash=13171900527646;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useOffsetX.ts (45:30)";return _f;}(),[loop,data,viewCount,type,size,visibleRanges]);return x;};exports.useOffsetX=useOffsetX;
|
|
2
2
|
//# sourceMappingURL=useOffsetX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOffsetX.ts"],"names":["useOffsetX","opts","visibleRanges","
|
|
1
|
+
{"version":3,"sources":["useOffsetX.ts"],"names":["useOffsetX","opts","visibleRanges","handlerOffset","index","size","loop","data","type","viewCount","Math","round","length","ITEM_LENGTH","VALID_LENGTH","TOTAL_WIDTH","HALF_WIDTH","positiveCount","startPos","MAX","MIN","x","value","negativeRange","positiveRange","Number","MAX_SAFE_INTEGER","inputRange","MIN_VALUE","outputRange","Extrapolate","CLAMP","interpolate"],"mappings":"mFAAA,8DAiBO,GAAMA,CAAAA,UAAU,CAAG,QAAbA,CAAAA,UAAa,CAACC,IAAD,CAAcC,aAAd,CAAgD,CACtE,GACIC,CAAAA,aADJ,CAQIF,IARJ,CACIE,aADJ,CAEIC,KAFJ,CAQIH,IARJ,CAEIG,KAFJ,CAGIC,IAHJ,CAQIJ,IARJ,CAGII,IAHJ,CAIIC,IAJJ,CAQIL,IARJ,CAIIK,IAJJ,CAKIC,IALJ,CAQIN,IARJ,CAKIM,IALJ,YAQIN,IARJ,CAMIO,IANJ,CAMIA,IANJ,qBAMW,UANX,4BAQIP,IARJ,CAOIQ,SAPJ,CAOIA,SAPJ,0BAOgBC,IAAI,CAACC,KAAL,CAAW,CAACJ,IAAI,CAACK,MAAL,CAAc,CAAf,EAAoB,CAA/B,CAPhB,iBAUA,GAAMC,CAAAA,WAAW,CAAGN,IAAI,CAACK,MAAzB,CACA,GAAME,CAAAA,YAAY,CAAGD,WAAW,CAAG,CAAnC,CACA,GAAME,CAAAA,WAAW,CAAGV,IAAI,CAAGQ,WAA3B,CACA,GAAMG,CAAAA,UAAU,CAAG,IAAMX,IAAzB,CAEA,GAAMY,CAAAA,aAAa,CACfT,IAAI,GAAK,UAAT,CAAsBC,SAAtB,CAAkCK,YAAY,CAAGL,SADrD,CAGA,GAAIS,CAAAA,QAAQ,CAAGb,IAAI,CAAGD,KAAtB,CACA,GAAIA,KAAK,CAAGa,aAAZ,CAA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FG,CAGHE,WAHG,CAIHC,mCAAYC,KAJT,CAAP,CAMH,CAED,MAAO5B,CAAAA,aAAa,CAACmB,KAAd,CAAsBjB,IAAI,CAAGD,KAApC,CACH,CAvCS,4BAvCRF,aAuCQ,OA3BwBE,KA2BxB,MAjCRE,IAiCQ,aAhCqLS,WAgCrL,KA/BwGK,GA+BxG,YA/B8GJ,UA+B9G,UA/B6IE,QA+B7I,KA/BsFC,GA+BtF,aA9BHa,kCA8BG,eA3BL7B,aA2BK,oBA9BuD2B,mCAAYC,KA8BnE,OA3BiB1B,IA2BjB,29BAuCP,CAACC,IAAD,CAAOC,IAAP,CAAaE,SAAb,CAAwBD,IAAxB,CAA8BH,IAA9B,CAAoCH,aAApC,CAvCO,CAAV,CAyCA,MAAOmB,CAAAA,CAAP,CACH,CArEM,C","sourcesContent":["import Animated, {\n Extrapolate,\n interpolate,\n useDerivedValue,\n} from 'react-native-reanimated';\nimport type { IVisibleRanges } from './useVisibleRanges';\n\nexport interface IOpts {\n index: number;\n size: number;\n handlerOffset: Animated.SharedValue<number>;\n data: unknown[];\n type?: 'positive' | 'negative';\n viewCount?: number;\n loop?: boolean;\n}\n\nexport const useOffsetX = (opts: IOpts, visibleRanges: IVisibleRanges) => {\n const {\n handlerOffset,\n index,\n size,\n loop,\n data,\n type = 'positive',\n viewCount = Math.round((data.length - 1) / 2),\n } = opts;\n\n const ITEM_LENGTH = data.length;\n const VALID_LENGTH = ITEM_LENGTH - 1;\n const TOTAL_WIDTH = size * ITEM_LENGTH;\n const HALF_WIDTH = 0.5 * size;\n\n const positiveCount =\n type === 'positive' ? viewCount : VALID_LENGTH - viewCount;\n\n let startPos = size * index;\n if (index > positiveCount) {\n startPos = (index - ITEM_LENGTH) * size;\n }\n\n const MAX = positiveCount * size;\n const MIN = -((VALID_LENGTH - positiveCount) * size);\n\n const x = useDerivedValue(() => {\n const { negativeRange, positiveRange } = visibleRanges.value;\n if (\n (index < negativeRange[0] || index > negativeRange[1]) &&\n (index < positiveRange[0] || index > positiveRange[1])\n ) {\n return Number.MAX_SAFE_INTEGER;\n }\n\n if (loop) {\n const inputRange = [\n -TOTAL_WIDTH,\n MIN - HALF_WIDTH - startPos - Number.MIN_VALUE,\n MIN - HALF_WIDTH - startPos,\n 0,\n MAX + HALF_WIDTH - startPos,\n MAX + HALF_WIDTH - startPos + Number.MIN_VALUE,\n TOTAL_WIDTH,\n ];\n\n const outputRange = [\n startPos,\n MAX + HALF_WIDTH - Number.MIN_VALUE,\n MIN - HALF_WIDTH,\n startPos,\n MAX + HALF_WIDTH,\n MIN - HALF_WIDTH + Number.MIN_VALUE,\n startPos,\n ];\n\n return interpolate(\n handlerOffset.value,\n inputRange,\n outputRange,\n Extrapolate.CLAMP\n );\n }\n\n return handlerOffset.value + size * index;\n }, [loop, data, viewCount, type, size, visibleRanges]);\n\n return x;\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 _useCheckMounted=require("../hooks/useCheckMounted");var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _store=require("../store");var _this=this,_jsxFileName="/Users/zhaodonghao/code/github/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
|
|
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/github/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 handlerOffset=props.handlerOffset,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({handlerOffset:handlerOffset,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={handlerOffset:handlerOffset,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/github/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (71:43)";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/github/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (74:8)";_f.__optimalization=2;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/github/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (90:8)";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/github/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (91:8)";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","mounted","
|
|
1
|
+
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","mounted","handlerOffset","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,q4DAKO,GAAMA,CAAAA,UAQX,CAAG,QARQA,CAAAA,UAQR,CAACC,KAAD,CAAW,CACZ,GAAMC,CAAAA,OAAO,CAAG,sCAAhB,CACA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K,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 '../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 handlerOffset: Animated.SharedValue<number>;\n visibleRanges: IVisibleRanges;\n animationStyle: TAnimationStyle;\n children: (ctx: {\n animationValue: Animated.SharedValue<number>;\n }) => React.ReactElement;\n}> = (props) => {\n const mounted = useCheckMounted();\n const { handlerOffset, 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 handlerOffset: handlerOffset,\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 handlerOffset: handlerOffset,\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/github/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
|
|
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/github/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 handlerOffset=props.handlerOffset,_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)({handlerOffset:handlerOffset,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/github/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (56:42)";_f.__optimalization=3;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/github/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (116:8)";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/github/react-native-reanimated-carousel/src/layouts/ParallaxLayout.tsx (117:8)";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","
|
|
1
|
+
{"version":3,"sources":["ParallaxLayout.tsx"],"names":["ParallaxLayout","props","handlerOffset","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,unCAGO,GAAMA,CAAAA,cAUZ,CAAG,QAVSA,CAAAA,cAUT,CAACC,KAAD,CAAW,CACX,GACIC,CAAAA,aADJ,CAaID,KAbJ,CACIC,aADJ,uBAaID,KAbJ,CAEIE,uBAFJ,CAEIA,uBAFJ,gCAE8B,GAF9B,8CAaIF,KAbJ,CAGIG,sBAHJ,CAGIA,sBAHJ,iCAG6B,GAH7B,8CAaIH,KAbJ,CAIII,yBAJJ,CAIIA,yBAJJ,gCAIgCC,IAAI,CAACC,GAAL,CAASH,sBAAT,CAAiC,CAAjC,CAJhC,uBAKII,KALJ,CAaIP,KAbJ,CAKIO,KALJ,CAMIC,KANJ,CAaIR,KAbJ,CAMIQ,KANJ,CAOIC,MAPJ,CAaIT,KAbJ,CAOIS,MAPJ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,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 { IComputedDirectionTypes } from '../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 IComputedDirectionTypes<\n {\n loop?: boolean;\n handlerOffset: Animated.SharedValue<number>;\n index: number;\n data: unknown[];\n visibleRanges: IVisibleRanges;\n } & ILayoutConfig\n >\n> = (props) => {\n const {\n handlerOffset,\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 handlerOffset: handlerOffset,\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"]}
|
package/lib/module/Carousel.js
CHANGED
|
@@ -43,15 +43,15 @@ const Carousel = /*#__PURE__*/React.forwardRef((_props, ref) => {
|
|
|
43
43
|
const commonVariables = useCommonVariables(props);
|
|
44
44
|
const {
|
|
45
45
|
size,
|
|
46
|
-
|
|
46
|
+
handlerOffset
|
|
47
47
|
} = commonVariables;
|
|
48
48
|
const dataLength = data.length;
|
|
49
49
|
const offsetX = useDerivedValue(() => {
|
|
50
50
|
const totalSize = size * dataLength;
|
|
51
|
-
const x =
|
|
51
|
+
const x = handlerOffset.value % totalSize;
|
|
52
52
|
|
|
53
53
|
if (!loop) {
|
|
54
|
-
return
|
|
54
|
+
return handlerOffset.value;
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
return isNaN(x) ? 0 : x;
|
|
@@ -70,7 +70,7 @@ const Carousel = /*#__PURE__*/React.forwardRef((_props, ref) => {
|
|
|
70
70
|
size,
|
|
71
71
|
data,
|
|
72
72
|
autoFillData,
|
|
73
|
-
|
|
73
|
+
handlerOffset,
|
|
74
74
|
withAnimation,
|
|
75
75
|
defaultIndex,
|
|
76
76
|
onScrollEnd: () => runOnJS(_onScrollEnd)(),
|
|
@@ -133,7 +133,7 @@ const Carousel = /*#__PURE__*/React.forwardRef((_props, ref) => {
|
|
|
133
133
|
const visibleRanges = useVisibleRanges({
|
|
134
134
|
total: data.length,
|
|
135
135
|
viewSize: size,
|
|
136
|
-
translation:
|
|
136
|
+
translation: handlerOffset,
|
|
137
137
|
windowSize
|
|
138
138
|
});
|
|
139
139
|
const layoutConfig = useLayoutConfig({ ...props,
|
|
@@ -149,7 +149,7 @@ const Carousel = /*#__PURE__*/React.forwardRef((_props, ref) => {
|
|
|
149
149
|
return /*#__PURE__*/React.createElement(BaseLayout, {
|
|
150
150
|
key: i,
|
|
151
151
|
index: i,
|
|
152
|
-
|
|
152
|
+
handlerOffset: offsetX,
|
|
153
153
|
visibleRanges: visibleRanges,
|
|
154
154
|
animationStyle: customAnimation || layoutConfig
|
|
155
155
|
}, _ref => {
|
|
@@ -171,7 +171,7 @@ const Carousel = /*#__PURE__*/React.forwardRef((_props, ref) => {
|
|
|
171
171
|
}, /*#__PURE__*/React.createElement(ScrollViewGesture, {
|
|
172
172
|
key: mode,
|
|
173
173
|
size: size,
|
|
174
|
-
translation:
|
|
174
|
+
translation: handlerOffset,
|
|
175
175
|
style: [styles.container, {
|
|
176
176
|
width: width || '100%',
|
|
177
177
|
height: height || '100%'
|