react-native-reanimated-carousel 2.2.2 → 2.2.5-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/commonjs/Carousel.js +1 -221
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/LazyView.js +1 -25
- package/lib/commonjs/LazyView.js.map +1 -1
- package/lib/commonjs/ScrollViewGesture.js +1 -217
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/constants/index.js +1 -21
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +1 -61
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -194
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +1 -36
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +1 -70
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +1 -39
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +1 -54
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +1 -38
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -37
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js +1 -42
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/index.js +1 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -100
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +1 -82
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/index.js +1 -20
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +1 -27
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +1 -36
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +1 -219
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js +1 -14
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/types.js +1 -5
- package/lib/commonjs/utils/dealWithAnimation.js +2 -0
- package/lib/commonjs/utils/dealWithAnimation.js.map +1 -0
- package/lib/commonjs/utils/log.js +1 -14
- package/lib/commonjs/utils/log.js.map +1 -1
- package/lib/module/Carousel.js +14 -10
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +46 -29
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useAutoPlay.js +5 -1
- package/lib/module/hooks/useAutoPlay.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +21 -7
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +2 -1
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/stack.js.map +1 -1
- package/lib/module/utils/dealWithAnimation.js +17 -0
- package/lib/module/utils/dealWithAnimation.js.map +1 -0
- package/lib/typescript/Carousel.d.ts +3 -4
- package/lib/typescript/ScrollViewGesture.d.ts +3 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +2 -1
- package/lib/typescript/layouts/BaseLayout.d.ts +2 -2
- package/lib/typescript/layouts/stack.d.ts +1 -1
- package/lib/typescript/types.d.ts +14 -2
- package/lib/typescript/utils/dealWithAnimation.d.ts +2 -0
- package/package.json +12 -2
- package/src/Carousel.tsx +203 -188
- package/src/ScrollViewGesture.tsx +70 -33
- package/src/hooks/useAutoPlay.ts +4 -1
- package/src/hooks/useCarouselController.tsx +28 -12
- package/src/layouts/BaseLayout.tsx +3 -3
- package/src/layouts/stack.ts +1 -1
- package/src/types.ts +22 -4
- package/src/utils/dealWithAnimation.ts +22 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useInitProps.ts"],"names":["useInitProps","props","defaultIndex","data","rawData","loop","autoPlayInterval","_autoPlayInterval","scrollAnimationDuration","style","panGestureHandlerProps","pagingEnabled","enableSnap","
|
|
1
|
+
{"version":3,"sources":["useInitProps.ts"],"names":["useInitProps","props","defaultIndex","data","rawData","loop","autoPlayInterval","_autoPlayInterval","scrollAnimationDuration","style","panGestureHandlerProps","pagingEnabled","enableSnap","_width","width","_height","height","Math","round","max","React","useMemo","length","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","mode","modeConfig","showLength"],"mappings":"4QAAA,oDACA,uC,2yBAqBO,QAASA,CAAAA,YAAT,CACHC,KADG,CAEwB,CAC3B,wBAYIA,KAZJ,CACIC,YADJ,CACIA,YADJ,8BACmB,CADnB,iCAYID,KAZJ,CAEIE,IAFJ,CAEUC,OAFV,sBAEoB,EAFpB,yBAYIH,KAZJ,CAGII,IAHJ,CAGIA,IAHJ,sBAGW,IAHX,mCAYIJ,KAZJ,CAIIK,gBAJJ,CAIsBC,iBAJtB,gCAI0C,IAJ1C,6CAYIN,KAZJ,CAKIO,uBALJ,CAKIA,uBALJ,gCAK8B,GAL9B,oCAYIP,KAZJ,CAMIQ,KANJ,CAMIA,KANJ,uBAMY,EANZ,oCAYIR,KAZJ,CAOIS,sBAPJ,CAOIA,sBAPJ,gCAO6B,EAP7B,4CAYIT,KAZJ,CAQIU,aARJ,CAQIA,aARJ,+BAQoB,IARpB,wCAYIV,KAZJ,CASIW,UATJ,CASIA,UATJ,4BASiB,IATjB,mBAUWC,MAVX,CAYIZ,KAZJ,CAUIa,KAVJ,CAWYC,OAXZ,CAYId,KAZJ,CAWIe,MAXJ,CAcA,G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,CAAJA,IAHJ,CAIIC,OAAO,CAAPA,OAJJ,CAKIC,IAAI,CAAJA,IALJ,CAMIC,gBAAgB,CAAhBA,gBANJ,CAOIE,uBAAuB,CAAvBA,uBAPJ,CAQIC,KAAK,CAALA,KARJ,CASIC,sBAAsB,CAAtBA,sBATJ,CAUIC,aAAa,CAAbA,aAVJ,CAWIC,UAAU,CAAVA,UAXJ,CAYIE,KAAK,CAALA,KAZJ,CAaIE,MAAM,CAANA,MAbJ,GAeH","sourcesContent":["import React from 'react';\nimport { DATA_LENGTH } from '../constants';\nimport type { TCarouselProps } from '../types';\n\ntype TGetRequiredProps<P extends keyof TCarouselProps> = Record<\n P,\n Required<TCarouselProps>[P]\n>;\n\nexport type TInitializeCarouselProps<T> = TCarouselProps<T> &\n TGetRequiredProps<\n | 'defaultIndex'\n | 'loop'\n | 'width'\n | 'height'\n | 'scrollAnimationDuration'\n | 'autoPlayInterval'\n > & {\n // Raw data that has not been processed\n rawData: T[];\n };\n\nexport function useInitProps<T>(\n props: TCarouselProps<T>\n): TInitializeCarouselProps<T> {\n const {\n defaultIndex = 0,\n data: rawData = [],\n loop = true,\n autoPlayInterval: _autoPlayInterval = 1000,\n scrollAnimationDuration = 500,\n style = {},\n panGestureHandlerProps = {},\n pagingEnabled = true,\n enableSnap = true,\n width: _width,\n height: _height,\n } = props;\n\n const width = Math.round(_width || 0);\n const height = Math.round(_height || 0);\n const autoPlayInterval = Math.max(_autoPlayInterval, 0);\n\n const data = React.useMemo<T[]>(() => {\n if (!loop) return rawData;\n\n if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {\n return [rawData[0], rawData[0], rawData[0]];\n }\n\n if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {\n return [rawData[0], rawData[1], rawData[0], rawData[1]];\n }\n\n return rawData;\n }, [rawData, loop]);\n\n if (props.mode === 'vertical-stack' || props.mode === 'horizontal-stack') {\n if (!props.modeConfig) {\n props.modeConfig = {};\n }\n props.modeConfig.showLength =\n props.modeConfig?.showLength ?? data.length - 1;\n }\n return {\n ...props,\n defaultIndex,\n data,\n rawData,\n loop,\n autoPlayInterval,\n scrollAnimationDuration,\n style,\n panGestureHandlerProps,\n pagingEnabled,\n enableSnap,\n width,\n height,\n };\n}\n"]}
|
|
@@ -1,40 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useLayoutConfig = useLayoutConfig;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _layouts = require("../layouts");
|
|
11
|
-
|
|
12
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
-
|
|
14
|
-
function useLayoutConfig(opts) {
|
|
15
|
-
const {
|
|
16
|
-
size,
|
|
17
|
-
vertical
|
|
18
|
-
} = opts;
|
|
19
|
-
return _react.default.useMemo(() => {
|
|
20
|
-
const baseConfig = {
|
|
21
|
-
size,
|
|
22
|
-
vertical
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
switch (opts.mode) {
|
|
26
|
-
case 'parallax':
|
|
27
|
-
return _layouts.Layouts.parallax(baseConfig, opts.modeConfig);
|
|
28
|
-
|
|
29
|
-
case 'horizontal-stack':
|
|
30
|
-
return _layouts.Layouts.horizontalStack(opts.modeConfig);
|
|
31
|
-
|
|
32
|
-
case 'vertical-stack':
|
|
33
|
-
return _layouts.Layouts.verticalStack(opts.modeConfig);
|
|
34
|
-
|
|
35
|
-
default:
|
|
36
|
-
return _layouts.Layouts.normal(baseConfig);
|
|
37
|
-
}
|
|
38
|
-
}, [opts.mode, opts.modeConfig, size, vertical]);
|
|
39
|
-
}
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useLayoutConfig=useLayoutConfig;var _react=_interopRequireDefault(require("react"));var _layouts=require("../layouts");function useLayoutConfig(opts){var _ref=opts,size=_ref.size,vertical=_ref.vertical;return _react.default.useMemo(function(){var baseConfig={size:size,vertical:vertical};switch(opts.mode){case'parallax':return _layouts.Layouts.parallax(baseConfig,opts.modeConfig);case'horizontal-stack':return _layouts.Layouts.horizontalStack(opts.modeConfig);case'vertical-stack':return _layouts.Layouts.verticalStack(opts.modeConfig);default:return _layouts.Layouts.normal(baseConfig);}},[opts.mode,opts.modeConfig,size,vertical]);}
|
|
40
2
|
//# sourceMappingURL=useLayoutConfig.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useLayoutConfig.ts"],"names":["useLayoutConfig","opts","size","vertical","React","useMemo","baseConfig","mode","Layouts","parallax","modeConfig","horizontalStack","verticalStack","normal"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["useLayoutConfig.ts"],"names":["useLayoutConfig","opts","size","vertical","React","useMemo","baseConfig","mode","Layouts","parallax","modeConfig","horizontalStack","verticalStack","normal"],"mappings":"oLAAA,oDAEA,mCAKO,QAASA,CAAAA,eAAT,CACHC,IADG,CAEY,CACf,SAA2BA,IAA3B,CAAQC,IAAR,MAAQA,IAAR,CAAcC,QAAd,MAAcA,QAAd,CAEA,MAAOC,gBAAMC,OAAN,CAAc,UAAM,CACvB,GAAMC,CAAAA,UAAU,CAAG,CAAEJ,IAAI,CAAJA,IAAF,CAAQC,QAAQ,CAARA,QAAR,CAAnB,CACA,OAAQF,IAAI,CAACM,IAAb,EACI,IAAK,UAAL,CACI,MAAOC,kBAAQC,QAAR,CAAiBH,UAAjB,CAA6BL,IAAI,CAACS,UAAlC,CAAP,CACJ,IAAK,kBAAL,CACI,MAAOF,kBAAQG,eAAR,CAAwBV,IAAI,CAACS,UAA7B,CAAP,CACJ,IAAK,gBAAL,CACI,MAAOF,kBAAQI,aAAR,CAAsBX,IAAI,CAACS,UAA3B,CAAP,CACJ,QACI,MAAOF,kBAAQK,MAAR,CAAeP,UAAf,CAAP,CARR,CAUH,CAZM,CAYJ,CAACL,IAAI,CAACM,IAAN,CAAYN,IAAI,CAACS,UAAjB,CAA6BR,IAA7B,CAAmCC,QAAnC,CAZI,CAAP,CAaH","sourcesContent":["import React from 'react';\nimport type { TAnimationStyle } from 'src/layouts/BaseLayout';\nimport { Layouts } from '../layouts';\nimport type { TInitializeCarouselProps } from './useInitProps';\n\ntype TLayoutConfigOpts<T> = TInitializeCarouselProps<T> & { size: number };\n\nexport function useLayoutConfig<T>(\n opts: TLayoutConfigOpts<T>\n): TAnimationStyle {\n const { size, vertical } = opts as Required<TLayoutConfigOpts<T>>;\n\n return React.useMemo(() => {\n const baseConfig = { size, vertical };\n switch (opts.mode) {\n case 'parallax':\n return Layouts.parallax(baseConfig, opts.modeConfig);\n case 'horizontal-stack':\n return Layouts.horizontalStack(opts.modeConfig);\n case 'vertical-stack':\n return Layouts.verticalStack(opts.modeConfig);\n default:\n return Layouts.normal(baseConfig);\n }\n }, [opts.mode, opts.modeConfig, size, vertical]);\n}\n"]}
|
|
@@ -1,55 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useOffsetX = void 0;
|
|
7
|
-
|
|
8
|
-
var _reactNativeReanimated = require("react-native-reanimated");
|
|
9
|
-
|
|
10
|
-
const useOffsetX = (opts, visibleRanges) => {
|
|
11
|
-
const {
|
|
12
|
-
handlerOffsetX,
|
|
13
|
-
index,
|
|
14
|
-
size,
|
|
15
|
-
loop,
|
|
16
|
-
data,
|
|
17
|
-
type = 'positive',
|
|
18
|
-
viewCount = Math.round((data.length - 1) / 2)
|
|
19
|
-
} = opts;
|
|
20
|
-
const ITEM_LENGTH = data.length;
|
|
21
|
-
const VALID_LENGTH = ITEM_LENGTH - 1;
|
|
22
|
-
const TOTAL_WIDTH = size * ITEM_LENGTH;
|
|
23
|
-
const HALF_WIDTH = 0.5 * size;
|
|
24
|
-
const positiveCount = type === 'positive' ? viewCount : VALID_LENGTH - viewCount;
|
|
25
|
-
let startPos = size * index;
|
|
26
|
-
|
|
27
|
-
if (index > positiveCount) {
|
|
28
|
-
startPos = (index - ITEM_LENGTH) * size;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const MAX = positiveCount * size;
|
|
32
|
-
const MIN = -((VALID_LENGTH - positiveCount) * size);
|
|
33
|
-
const x = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
34
|
-
const {
|
|
35
|
-
negativeRange,
|
|
36
|
-
positiveRange
|
|
37
|
-
} = visibleRanges.value;
|
|
38
|
-
|
|
39
|
-
if ((index < negativeRange[0] || index > negativeRange[1]) && (index < positiveRange[0] || index > positiveRange[1])) {
|
|
40
|
-
return Number.MAX_SAFE_INTEGER;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
if (loop) {
|
|
44
|
-
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];
|
|
45
|
-
const outputRange = [startPos, MAX + HALF_WIDTH - Number.MIN_VALUE, MIN - HALF_WIDTH, startPos, MAX + HALF_WIDTH, MIN - HALF_WIDTH + Number.MIN_VALUE, startPos];
|
|
46
|
-
return (0, _reactNativeReanimated.interpolate)(handlerOffsetX.value, inputRange, outputRange, _reactNativeReanimated.Extrapolate.CLAMP);
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
return handlerOffsetX.value + size * index;
|
|
50
|
-
}, [loop, data, viewCount, type, size, visibleRanges]);
|
|
51
|
-
return x;
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
exports.useOffsetX = useOffsetX;
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.useOffsetX=void 0;var _reactNativeReanimated=require("react-native-reanimated");var useOffsetX=function useOffsetX(opts,visibleRanges){var handlerOffsetX=opts.handlerOffsetX,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)(handlerOffsetX.value,inputRange,outputRange,_reactNativeReanimated.Extrapolate.CLAMP);}return handlerOffsetX.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,handlerOffsetX:handlerOffsetX,Extrapolate:{CLAMP:_reactNativeReanimated.Extrapolate.CLAMP},size:size};_f.asString="function _f(){const{visibleRanges,index,loop,TOTAL_WIDTH,MIN,HALF_WIDTH,startPos,MAX,interpolate,handlerOffsetX,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(handlerOffsetX.value,inputRange,outputRange,Extrapolate.CLAMP);}return handlerOffsetX.value+size*index;}}";_f.__workletHash=12723241758918;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOffsetX.ts (45:30)";global.__reanimatedWorkletInit(_f);return _f;}(),[loop,data,viewCount,type,size,visibleRanges]);return x;};exports.useOffsetX=useOffsetX;
|
|
55
2
|
//# sourceMappingURL=useOffsetX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOffsetX.ts"],"names":["useOffsetX","opts","visibleRanges","handlerOffsetX","index","size","loop","data","type","viewCount","Math","round","length","ITEM_LENGTH","VALID_LENGTH","TOTAL_WIDTH","HALF_WIDTH","positiveCount","startPos","MAX","MIN","x","
|
|
1
|
+
{"version":3,"sources":["useOffsetX.ts"],"names":["useOffsetX","opts","visibleRanges","handlerOffsetX","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","CL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mCAAYC,KA8BpE,OA3BkB1B,IA2BlB,0/BAuCP,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 handlerOffsetX: 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 handlerOffsetX,\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 handlerOffsetX.value,\n inputRange,\n outputRange,\n Extrapolate.CLAMP\n );\n }\n\n return handlerOffsetX.value + size * index;\n }, [loop, data, viewCount, type, size, visibleRanges]);\n\n return x;\n};\n"]}
|
|
@@ -1,39 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useOnProgressChange = useOnProgressChange;
|
|
7
|
-
|
|
8
|
-
var _reactNativeReanimated = require("react-native-reanimated");
|
|
9
|
-
|
|
10
|
-
var _constants = require("../constants");
|
|
11
|
-
|
|
12
|
-
function useOnProgressChange(opts) {
|
|
13
|
-
const {
|
|
14
|
-
offsetX,
|
|
15
|
-
rawData,
|
|
16
|
-
size,
|
|
17
|
-
onProgressChange
|
|
18
|
-
} = opts;
|
|
19
|
-
(0, _reactNativeReanimated.useAnimatedReaction)(() => offsetX.value, _value => {
|
|
20
|
-
let value = _value;
|
|
21
|
-
|
|
22
|
-
if (rawData.length === _constants.DATA_LENGTH.SINGLE_ITEM) {
|
|
23
|
-
value = value % size;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (rawData.length === _constants.DATA_LENGTH.DOUBLE_ITEM) {
|
|
27
|
-
value = value % (size * 2);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
let absoluteProgress = Math.abs(value / size);
|
|
31
|
-
|
|
32
|
-
if (value > 0) {
|
|
33
|
-
absoluteProgress = rawData.length - absoluteProgress;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
!!onProgressChange && (0, _reactNativeReanimated.runOnJS)(onProgressChange)(value, absoluteProgress);
|
|
37
|
-
}, [onProgressChange, rawData]);
|
|
38
|
-
}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.useOnProgressChange=useOnProgressChange;var _reactNativeReanimated=require("react-native-reanimated");var _constants=require("../constants");function useOnProgressChange(opts){var offsetX=opts.offsetX,rawData=opts.rawData,size=opts.size,onProgressChange=opts.onProgressChange;(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return offsetX.value;};_f._closure={offsetX:offsetX};_f.asString="function _f(){const{offsetX}=jsThis._closure;{return offsetX.value;}}";_f.__workletHash=11091407603539;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOnProgressChange.ts (17:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(_value){var value=_value;if(rawData.length===_constants.DATA_LENGTH.SINGLE_ITEM){value=value%size;}if(rawData.length===_constants.DATA_LENGTH.DOUBLE_ITEM){value=value%(size*2);}var absoluteProgress=Math.abs(value/size);if(value>0){absoluteProgress=rawData.length-absoluteProgress;}!!onProgressChange&&(0,_reactNativeReanimated.runOnJS)(onProgressChange)(value,absoluteProgress);};_f._closure={rawData:rawData,DATA_LENGTH:{SINGLE_ITEM:_constants.DATA_LENGTH.SINGLE_ITEM,DOUBLE_ITEM:_constants.DATA_LENGTH.DOUBLE_ITEM},size:size,onProgressChange:onProgressChange,runOnJS:_reactNativeReanimated.runOnJS};_f.asString="function _f(_value){const{rawData,DATA_LENGTH,size,onProgressChange,runOnJS}=jsThis._closure;{let value=_value;if(rawData.length===DATA_LENGTH.SINGLE_ITEM){value=value%size;}if(rawData.length===DATA_LENGTH.DOUBLE_ITEM){value=value%(size*2);}let absoluteProgress=Math.abs(value/size);if(value>0){absoluteProgress=rawData.length-absoluteProgress;}!!onProgressChange&&runOnJS(onProgressChange)(value,absoluteProgress);}}";_f.__workletHash=13494249100112;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useOnProgressChange.ts (18:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[onProgressChange,rawData]);}
|
|
39
2
|
//# sourceMappingURL=useOnProgressChange.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOnProgressChange.ts"],"names":["useOnProgressChange","opts","offsetX","rawData","size","onProgressChange","value","_value","length","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","absoluteProgress","Math","abs"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["useOnProgressChange.ts"],"names":["useOnProgressChange","opts","offsetX","rawData","size","onProgressChange","value","_value","length","DATA_LENGTH","SINGLE_ITEM","DOUBLE_ITEM","absoluteProgress","Math","abs","runOnJS"],"mappings":"yGAAA,8DAIA,uCAGO,QAASA,CAAAA,mBAAT,CACHC,IADG,CAML,CACE,GAAQC,CAAAA,OAAR,CAAqDD,IAArD,CAAQC,OAAR,CAAiBC,OAAjB,CAAqDF,IAArD,CAAiBE,OAAjB,CAA0BC,IAA1B,CAAqDH,IAArD,CAA0BG,IAA1B,CAAgCC,gBAAhC,CAAqDJ,IAArD,CAAgCI,gBAAhC,CACA,iEACI,oBAAMH,CAAAA,OAAO,CAACI,KAAd,EADJ,sBAdGJ,OAcH,sTAEKK,MAFL,CAEgB,CACR,GAAID,CAAAA,KAAK,CAAGC,MAAZ,CAEA,GAAIJ,OAAO,CAACK,MAAR,GAAmBC,uBAAYC,WAAnC,CAAgD,CAC5CJ,KAAK,CAAGA,KAAK,CAAGF,IAAhB,CACH,CAED,GAAID,OAAO,CAACK,MAAR,GAAmBC,uBAAYE,WAAnC,CAAgD,CAC5CL,KAAK,CAAGA,KAAK,EAAIF,IAAI,CAAG,CAAX,CAAb,CACH,CAED,GAAIQ,CAAAA,gBAAgB,CAAGC,IAAI,CAACC,GAAL,CAASR,KAAK,CAAGF,IAAjB,CAAvB,CAEA,GAAIE,KAAK,CAAG,CAAZ,CAAe,CACXM,gBAAgB,CAAGT,OAAO,CAACK,MAAR,CAAiBI,gBAApC,CACH,CAED,CAAC,CAACP,gBAAF,EACI,mCAAQA,gBAAR,EAA0BC,KAA1B,CAAiCM,gBAAjC,CADJ,CAEH,CArBL,sBAAmBT,OAAnB,0BAXqBM,uBAAYC,WAWjC,aAPqBD,uBAAYE,WAOjC,OAHsCP,IAGtC,kBAG4BC,gBAH5B,SAGoBU,8BAHpB,onBAsBI,CAACV,gBAAD,CAAmBF,OAAnB,CAtBJ,EAwBH","sourcesContent":["import Animated, {\n runOnJS,\n useAnimatedReaction,\n} from 'react-native-reanimated';\nimport { DATA_LENGTH } from '../constants';\nimport type { TCarouselProps } from '../types';\n\nexport function useOnProgressChange(\n opts: {\n size: number;\n offsetX: Animated.SharedValue<number>;\n rawData: TCarouselProps['data'];\n } & Pick<TCarouselProps, 'onProgressChange'>\n) {\n const { offsetX, rawData, size, onProgressChange } = opts;\n useAnimatedReaction(\n () => offsetX.value,\n (_value) => {\n let value = _value;\n\n if (rawData.length === DATA_LENGTH.SINGLE_ITEM) {\n value = value % size;\n }\n\n if (rawData.length === DATA_LENGTH.DOUBLE_ITEM) {\n value = value % (size * 2);\n }\n\n let absoluteProgress = Math.abs(value / size);\n\n if (value > 0) {\n absoluteProgress = rawData.length - absoluteProgress;\n }\n\n !!onProgressChange &&\n runOnJS(onProgressChange)(value, absoluteProgress);\n },\n [onProgressChange, rawData]\n );\n}\n"]}
|
|
@@ -1,38 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.usePropsErrorBoundary = usePropsErrorBoundary;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
function usePropsErrorBoundary(props) {
|
|
13
|
-
_react.default.useEffect(() => {
|
|
14
|
-
const {
|
|
15
|
-
defaultIndex,
|
|
16
|
-
data
|
|
17
|
-
} = props;
|
|
18
|
-
const viewCount = data.length;
|
|
19
|
-
|
|
20
|
-
if (typeof defaultIndex === 'number' && viewCount > 0) {
|
|
21
|
-
if (defaultIndex < 0 || defaultIndex >= viewCount) {
|
|
22
|
-
throw Error('DefaultIndex must be in the range of data length.');
|
|
23
|
-
}
|
|
24
|
-
} // TODO
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (!props.mode || props.mode === 'parallax') {
|
|
28
|
-
if (!props.vertical && !props.width) {
|
|
29
|
-
throw Error('`width` must be specified for vertical carousels.');
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
if (props.vertical && !props.height) {
|
|
33
|
-
throw Error('`height` must be specified for vertical carousels.');
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}, [props]);
|
|
37
|
-
}
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.usePropsErrorBoundary=usePropsErrorBoundary;var _react=_interopRequireDefault(require("react"));function usePropsErrorBoundary(props){_react.default.useEffect(function(){var defaultIndex=props.defaultIndex,data=props.data;var viewCount=data.length;if(typeof defaultIndex==='number'&&viewCount>0){if(defaultIndex<0||defaultIndex>=viewCount){throw Error('DefaultIndex must be in the range of data length.');}}if(!props.mode||props.mode==='parallax'){if(!props.vertical&&!props.width){throw Error('`width` must be specified for vertical carousels.');}if(props.vertical&&!props.height){throw Error('`height` must be specified for vertical carousels.');}}},[props]);}
|
|
38
2
|
//# sourceMappingURL=usePropsErrorBoundary.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["usePropsErrorBoundary.ts"],"names":["usePropsErrorBoundary","props","React","useEffect","defaultIndex","data","viewCount","length","Error","mode","vertical","width","height"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["usePropsErrorBoundary.ts"],"names":["usePropsErrorBoundary","props","React","useEffect","defaultIndex","data","viewCount","length","Error","mode","vertical","width","height"],"mappings":"gMAAA,oDAGO,QAASA,CAAAA,qBAAT,CAA+BC,KAA/B,CAAsD,CACzDC,eAAMC,SAAN,CAAgB,UAAM,CAClB,GAAQC,CAAAA,YAAR,CAA+BH,KAA/B,CAAQG,YAAR,CAAsBC,IAAtB,CAA+BJ,KAA/B,CAAsBI,IAAtB,CAEA,GAAMC,CAAAA,SAAS,CAAGD,IAAI,CAACE,MAAvB,CACA,GAAI,MAAOH,CAAAA,YAAP,GAAwB,QAAxB,EAAoCE,SAAS,CAAG,CAApD,CAAuD,CACnD,GAAIF,YAAY,CAAG,CAAf,EAAoBA,YAAY,EAAIE,SAAxC,CAAmD,CAC/C,KAAME,CAAAA,KAAK,CACP,mDADO,CAAX,CAGH,CACJ,CAGD,GAAI,CAACP,KAAK,CAACQ,IAAP,EAAeR,KAAK,CAACQ,IAAN,GAAe,UAAlC,CAA8C,CAC1C,GAAI,CAACR,KAAK,CAACS,QAAP,EAAmB,CAACT,KAAK,CAACU,KAA9B,CAAqC,CACjC,KAAMH,CAAAA,KAAK,CACP,mDADO,CAAX,CAGH,CACD,GAAIP,KAAK,CAACS,QAAN,EAAkB,CAACT,KAAK,CAACW,MAA7B,CAAqC,CACjC,KAAMJ,CAAAA,KAAK,CACP,oDADO,CAAX,CAGH,CACJ,CACJ,CAzBD,CAyBG,CAACP,KAAD,CAzBH,EA0BH","sourcesContent":["import React from 'react';\nimport type { TCarouselProps } from 'src/types';\n\nexport function usePropsErrorBoundary(props: TCarouselProps) {\n React.useEffect(() => {\n const { defaultIndex, data } = props;\n\n const viewCount = data.length;\n if (typeof defaultIndex === 'number' && viewCount > 0) {\n if (defaultIndex < 0 || defaultIndex >= viewCount) {\n throw Error(\n 'DefaultIndex must be in the range of data length.'\n );\n }\n }\n\n // TODO\n if (!props.mode || props.mode === 'parallax') {\n if (!props.vertical && !props.width) {\n throw Error(\n '`width` must be specified for vertical carousels.'\n );\n }\n if (props.vertical && !props.height) {\n throw Error(\n '`height` must be specified for vertical carousels.'\n );\n }\n }\n }, [props]);\n}\n"]}
|
|
@@ -1,43 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.useVisibleRanges = useVisibleRanges;
|
|
7
|
-
|
|
8
|
-
var _reactNativeReanimated = require("react-native-reanimated");
|
|
9
|
-
|
|
10
|
-
function useVisibleRanges(options) {
|
|
11
|
-
const {
|
|
12
|
-
total = 0,
|
|
13
|
-
viewSize,
|
|
14
|
-
translation,
|
|
15
|
-
windowSize: _windowSize = 0
|
|
16
|
-
} = options;
|
|
17
|
-
const windowSize = total <= _windowSize ? total : _windowSize;
|
|
18
|
-
const ranges = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
19
|
-
const positiveCount = Math.round(windowSize / 2);
|
|
20
|
-
const negativeCount = windowSize - positiveCount;
|
|
21
|
-
let curIndex = Math.round(-translation.value / viewSize);
|
|
22
|
-
curIndex = curIndex < 0 ? curIndex % total + total : curIndex;
|
|
23
|
-
const negativeRange = [(curIndex - negativeCount + total) % total, (curIndex - 1 + total) % total];
|
|
24
|
-
const positiveRange = [(curIndex + total) % total, (curIndex + positiveCount + total) % total];
|
|
25
|
-
|
|
26
|
-
if (negativeRange[0] < total && negativeRange[0] > negativeRange[1]) {
|
|
27
|
-
negativeRange[1] = total - 1;
|
|
28
|
-
positiveRange[0] = 0;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (positiveRange[0] > positiveRange[1]) {
|
|
32
|
-
negativeRange[1] = total - 1;
|
|
33
|
-
positiveRange[0] = 0;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return {
|
|
37
|
-
negativeRange,
|
|
38
|
-
positiveRange
|
|
39
|
-
};
|
|
40
|
-
}, [total, windowSize, translation]);
|
|
41
|
-
return ranges;
|
|
42
|
-
}
|
|
1
|
+
Object.defineProperty(exports,"__esModule",{value:true});exports.useVisibleRanges=useVisibleRanges;var _reactNativeReanimated=require("react-native-reanimated");function useVisibleRanges(options){var _options$total=options.total,total=_options$total===void 0?0:_options$total,viewSize=options.viewSize,translation=options.translation,_options$windowSize=options.windowSize,_windowSize=_options$windowSize===void 0?0:_options$windowSize;var windowSize=total<=_windowSize?total:_windowSize;var ranges=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){var positiveCount=Math.round(windowSize/2);var negativeCount=windowSize-positiveCount;var curIndex=Math.round(-translation.value/viewSize);curIndex=curIndex<0?curIndex%total+total:curIndex;var negativeRange=[(curIndex-negativeCount+total)%total,(curIndex-1+total)%total];var positiveRange=[(curIndex+total)%total,(curIndex+positiveCount+total)%total];if(negativeRange[0]<total&&negativeRange[0]>negativeRange[1]){negativeRange[1]=total-1;positiveRange[0]=0;}if(positiveRange[0]>positiveRange[1]){negativeRange[1]=total-1;positiveRange[0]=0;}return{negativeRange:negativeRange,positiveRange:positiveRange};};_f._closure={windowSize:windowSize,translation:translation,viewSize:viewSize,total:total};_f.asString="function _f(){const{windowSize,translation,viewSize,total}=jsThis._closure;{const positiveCount=Math.round(windowSize/2);const negativeCount=windowSize-positiveCount;let curIndex=Math.round(-translation.value/viewSize);curIndex=curIndex<0?curIndex%total+total:curIndex;const negativeRange=[(curIndex-negativeCount+total)%total,(curIndex-1+total)%total];const positiveRange=[(curIndex+total)%total,(curIndex+positiveCount+total)%total];if(negativeRange[0]<total&&negativeRange[0]>negativeRange[1]){negativeRange[1]=total-1;positiveRange[0]=0;}if(positiveRange[0]>positiveRange[1]){negativeRange[1]=total-1;positiveRange[0]=0;}return{negativeRange:negativeRange,positiveRange:positiveRange};}}";_f.__workletHash=15212293827170;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/hooks/useVisibleRanges.tsx (24:35)";global.__reanimatedWorkletInit(_f);return _f;}(),[total,windowSize,translation]);return ranges;}
|
|
43
2
|
//# sourceMappingURL=useVisibleRanges.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useVisibleRanges.tsx"],"names":["useVisibleRanges","options","total","viewSize","translation","windowSize","_windowSize","ranges","positiveCount","Math","round","negativeCount","curIndex","value","negativeRange","positiveRange"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["useVisibleRanges.tsx"],"names":["useVisibleRanges","options","total","viewSize","translation","windowSize","_windowSize","ranges","positiveCount","Math","round","negativeCount","curIndex","value","negativeRange","positiveRange"],"mappings":"mGACA,8DAOO,QAASA,CAAAA,gBAAT,CAA0BC,OAA1B,CAKY,CACf,mBAKIA,OALJ,CACIC,KADJ,CACIA,KADJ,yBACY,CADZ,gBAEIC,QAFJ,CAKIF,OALJ,CAEIE,QAFJ,CAGIC,WAHJ,CAKIH,OALJ,CAGIG,WAHJ,qBAKIH,OALJ,CAIII,UAJJ,CAIgBC,WAJhB,8BAI8B,CAJ9B,qBAOA,GAAMD,CAAAA,UAAU,CAAGH,KAAK,EAAII,WAAT,CAAuBJ,KAAvB,CAA+BI,WAAlD,CAEA,GAAMC,CAAAA,MAAM,CAAG,0EAAsB,CACjC,GAAMC,CAAAA,aAAa,CAAGC,IAAI,CAACC,KAAL,CAAWL,UAAU,CAAG,CAAxB,CAAtB,CACA,GAAMM,CAAAA,aAAa,CAAGN,UAAU,CAAGG,aAAnC,CACA,GAAII,CAAAA,QAAQ,CAAGH,IAAI,CAACC,KAAL,CAAW,CAACN,WAAW,CAACS,KAAb,CAAqBV,QAAhC,CAAf,CACAS,QAAQ,CAAGA,QAAQ,CAAG,CAAX,CAAgBA,QAAQ,CAAGV,KAAZ,CAAqBA,KAApC,CAA4CU,QAAvD,CACA,GAAME,CAAAA,aAAa,CAAG,CAClB,CAACF,QAAQ,CAAGD,aAAX,CAA2BT,KAA5B,EAAqCA,KADnB,CAElB,CAACU,QAAQ,CAAG,CAAX,CAAeV,KAAhB,EAAyBA,KAFP,CAAtB,CAIA,GAAMa,CAAAA,aAAa,CAAG,CAClB,CAACH,QAAQ,CAAGV,KAAZ,EAAqBA,KADH,CAElB,CAACU,QAAQ,CAAGJ,aAAX,CAA2BN,KAA5B,EAAqCA,KAFnB,CAAtB,CAIA,GAAIY,aAAa,CAAC,CAAD,CAAb,CAAmBZ,KAAnB,EAA4BY,aAAa,CAAC,CAAD,CAAb,CAAmBA,aAAa,CAAC,CAAD,CAAhE,CAAqE,CACjEA,aAAa,CAAC,CAAD,CAAb,CAAmBZ,KAAK,CAAG,CAA3B,CACAa,aAAa,CAAC,CAAD,CAAb,CAAmB,CAAnB,CACH,CACD,GAAIA,aAAa,CAAC,CAAD,CAAb,CAAmBA,aAAa,CAAC,CAAD,CAApC,CAAyC,CACrCD,aAAa,CAAC,CAAD,CAAb,CAAmBZ,KAAK,CAAG,CAA3B,CACAa,aAAa,CAAC,CAAD,CAAb,CAAmB,CAAnB,CACH,CACD,MAAO,CAAED,aAAa,CAAbA,aAAF,CAAiBC,aAAa,CAAbA,aAAjB,CAAP,CACH,CAtBc,yBApBKV,UAoBL,aAnBUD,WAmBV,UAnB8BD,QAmB9B,OARID,KAQJ,q4BAsBZ,CAACA,KAAD,CAAQG,UAAR,CAAoBD,WAApB,CAtBY,CAAf,CAwBA,MAAOG,CAAAA,MAAP,CACH","sourcesContent":["import type Animated from 'react-native-reanimated';\nimport { useDerivedValue } from 'react-native-reanimated';\n\nexport type IVisibleRanges = Animated.SharedValue<{\n negativeRange: number[];\n positiveRange: number[];\n}>;\n\nexport function useVisibleRanges(options: {\n total: number;\n viewSize: number;\n windowSize?: number;\n translation: Animated.SharedValue<number>;\n}): IVisibleRanges {\n const {\n total = 0,\n viewSize,\n translation,\n windowSize: _windowSize = 0,\n } = options;\n\n const windowSize = total <= _windowSize ? total : _windowSize;\n\n const ranges = useDerivedValue(() => {\n const positiveCount = Math.round(windowSize / 2);\n const negativeCount = windowSize - positiveCount;\n let curIndex = Math.round(-translation.value / viewSize);\n curIndex = curIndex < 0 ? (curIndex % total) + total : curIndex;\n const negativeRange = [\n (curIndex - negativeCount + total) % total,\n (curIndex - 1 + total) % total,\n ];\n const positiveRange = [\n (curIndex + total) % total,\n (curIndex + positiveCount + total) % total,\n ];\n if (negativeRange[0] < total && negativeRange[0] > negativeRange[1]) {\n negativeRange[1] = total - 1;\n positiveRange[0] = 0;\n }\n if (positiveRange[0] > positiveRange[1]) {\n negativeRange[1] = total - 1;\n positiveRange[0] = 0;\n }\n return { negativeRange, positiveRange };\n }, [total, windowSize, translation]);\n\n return ranges;\n}\n"]}
|
package/lib/commonjs/index.js
CHANGED
|
@@ -1,14 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
|
|
8
|
-
var _Carousel = _interopRequireDefault(require("./Carousel"));
|
|
9
|
-
|
|
10
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
|
-
|
|
12
|
-
var _default = _Carousel.default;
|
|
13
|
-
exports.default = _default;
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _Carousel=_interopRequireDefault(require("./Carousel"));var _default=_Carousel.default;exports.default=_default;
|
|
14
2
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Carousel"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Carousel"],"mappings":"mKACA,4D,aAEeA,iB","sourcesContent":["export type { TCarouselProps, ICarouselInstance } from './types';\nimport Carousel from './Carousel';\n\nexport default Carousel;\n"]}
|
|
@@ -1,101 +1,2 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BaseLayout = void 0;
|
|
7
|
-
|
|
8
|
-
var _react = _interopRequireDefault(require("react"));
|
|
9
|
-
|
|
10
|
-
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
11
|
-
|
|
12
|
-
var _useOffsetX = require("../hooks/useOffsetX");
|
|
13
|
-
|
|
14
|
-
var _LazyView = require("../LazyView");
|
|
15
|
-
|
|
16
|
-
var _store = require("../store");
|
|
17
|
-
|
|
18
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
19
|
-
|
|
20
|
-
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; }
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
const BaseLayout = props => {
|
|
25
|
-
const {
|
|
26
|
-
handlerOffsetX,
|
|
27
|
-
index,
|
|
28
|
-
children,
|
|
29
|
-
visibleRanges,
|
|
30
|
-
animationStyle
|
|
31
|
-
} = props;
|
|
32
|
-
|
|
33
|
-
const context = _react.default.useContext(_store.CTX);
|
|
34
|
-
|
|
35
|
-
const {
|
|
36
|
-
props: {
|
|
37
|
-
loop,
|
|
38
|
-
data,
|
|
39
|
-
width,
|
|
40
|
-
height,
|
|
41
|
-
vertical,
|
|
42
|
-
customConfig,
|
|
43
|
-
mode,
|
|
44
|
-
modeConfig
|
|
45
|
-
}
|
|
46
|
-
} = context;
|
|
47
|
-
const size = vertical ? height : width;
|
|
48
|
-
|
|
49
|
-
const [shouldUpdate, setShouldUpdate] = _react.default.useState(false);
|
|
50
|
-
|
|
51
|
-
let offsetXConfig = {
|
|
52
|
-
handlerOffsetX,
|
|
53
|
-
index,
|
|
54
|
-
size,
|
|
55
|
-
data,
|
|
56
|
-
loop,
|
|
57
|
-
...(typeof customConfig === 'function' ? customConfig() : {})
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
if (mode === 'horizontal-stack') {
|
|
61
|
-
const {
|
|
62
|
-
snapDirection,
|
|
63
|
-
showLength
|
|
64
|
-
} = modeConfig;
|
|
65
|
-
offsetXConfig = {
|
|
66
|
-
handlerOffsetX,
|
|
67
|
-
index,
|
|
68
|
-
size,
|
|
69
|
-
data,
|
|
70
|
-
loop,
|
|
71
|
-
type: snapDirection === 'right' ? 'negative' : 'positive',
|
|
72
|
-
viewCount: showLength
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
const x = (0, _useOffsetX.useOffsetX)(offsetXConfig, visibleRanges);
|
|
77
|
-
const animationValue = (0, _reactNativeReanimated.useDerivedValue)(() => x.value / size, [x, size]);
|
|
78
|
-
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => animationStyle(x.value / size), [animationStyle]);
|
|
79
|
-
|
|
80
|
-
const updateView = _react.default.useCallback((negativeRange, positiveRange) => {
|
|
81
|
-
setShouldUpdate(index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1]);
|
|
82
|
-
}, [index]);
|
|
83
|
-
|
|
84
|
-
(0, _reactNativeReanimated.useAnimatedReaction)(() => visibleRanges.value, () => {
|
|
85
|
-
(0, _reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange, visibleRanges.value.positiveRange);
|
|
86
|
-
}, [visibleRanges.value]);
|
|
87
|
-
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
88
|
-
style: [{
|
|
89
|
-
width: width || '100%',
|
|
90
|
-
height: height || '100%',
|
|
91
|
-
position: 'absolute'
|
|
92
|
-
}, animatedStyle]
|
|
93
|
-
}, /*#__PURE__*/_react.default.createElement(_LazyView.LazyView, {
|
|
94
|
-
shouldUpdate: shouldUpdate
|
|
95
|
-
}, children({
|
|
96
|
-
animationValue
|
|
97
|
-
})));
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
exports.BaseLayout = BaseLayout;
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.BaseLayout=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _store=require("../store");var _this=this,_jsxFileName="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx";function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function ownKeys(object,enumerableOnly){var keys=Object.keys(object);if(Object.getOwnPropertySymbols){var symbols=Object.getOwnPropertySymbols(object);if(enumerableOnly){symbols=symbols.filter(function(sym){return Object.getOwnPropertyDescriptor(object,sym).enumerable;});}keys.push.apply(keys,symbols);}return keys;}function _objectSpread(target){for(var i=1;i<arguments.length;i++){var source=arguments[i]!=null?arguments[i]:{};if(i%2){ownKeys(Object(source),true).forEach(function(key){(0,_defineProperty2.default)(target,key,source[key]);});}else if(Object.getOwnPropertyDescriptors){Object.defineProperties(target,Object.getOwnPropertyDescriptors(source));}else{ownKeys(Object(source)).forEach(function(key){Object.defineProperty(target,key,Object.getOwnPropertyDescriptor(source,key));});}}return target;}var BaseLayout=function BaseLayout(props){var handlerOffsetX=props.handlerOffsetX,index=props.index,children=props.children,visibleRanges=props.visibleRanges,animationStyle=props.animationStyle;var context=_react.default.useContext(_store.CTX);var _context$props=context.props,loop=_context$props.loop,data=_context$props.data,width=_context$props.width,height=_context$props.height,vertical=_context$props.vertical,customConfig=_context$props.customConfig,mode=_context$props.mode,modeConfig=_context$props.modeConfig;var size=vertical?height:width;var _React$useState=_react.default.useState(false),_React$useState2=(0,_slicedToArray2.default)(_React$useState,2),shouldUpdate=_React$useState2[0],setShouldUpdate=_React$useState2[1];var offsetXConfig=_objectSpread({handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop},typeof customConfig==='function'?customConfig():{});if(mode==='horizontal-stack'){var _ref=modeConfig,snapDirection=_ref.snapDirection,showLength=_ref.showLength;offsetXConfig={handlerOffsetX:handlerOffsetX,index:index,size:size,data:data,loop:loop,type:snapDirection==='right'?'negative':'positive',viewCount:showLength};}var x=(0,_useOffsetX.useOffsetX)(offsetXConfig,visibleRanges);var animationValue=(0,_reactNativeReanimated.useDerivedValue)(function(){var _f=function _f(){return x.value/size;};_f._closure={x:x,size:size};_f.asString="function _f(){const{x,size}=jsThis._closure;{return x.value/size;}}";_f.__workletHash=9077192607952;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (69:43)";global.__reanimatedWorkletInit(_f);return _f;}(),[x,size]);var animatedStyle=(0,_reactNativeReanimated.useAnimatedStyle)(function(){var _f=function _f(){return animationStyle(x.value/size);};_f._closure={animationStyle:animationStyle,x:x,size:size};_f.asString="function _f(){const{animationStyle,x,size}=jsThis._closure;{return animationStyle(x.value/size);}}";_f.__workletHash=3916054905053;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (72:8)";_f.__optimalization=2;global.__reanimatedWorkletInit(_f);return _f;}(),[animationStyle]);var updateView=_react.default.useCallback(function(negativeRange,positiveRange){setShouldUpdate(index>=negativeRange[0]&&index<=negativeRange[1]||index>=positiveRange[0]&&index<=positiveRange[1]);},[index]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){return visibleRanges.value;};_f._closure={visibleRanges:visibleRanges};_f.asString="function _f(){const{visibleRanges}=jsThis._closure;{return visibleRanges.value;}}";_f.__workletHash=15231519758579;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (87:8)";global.__reanimatedWorkletInit(_f);return _f;}(),function(){var _f=function _f(){(0,_reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,updateView:updateView,visibleRanges:visibleRanges};_f.asString="function _f(){const{runOnJS,updateView,visibleRanges}=jsThis._closure;{runOnJS(updateView)(visibleRanges.value.negativeRange,visibleRanges.value.positiveRange);}}";_f.__workletHash=6352504350554;_f.__location="/Users/zhaodonghao/code/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (88:8)";global.__reanimatedWorkletInit(_f);return _f;}(),[visibleRanges.value]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[{width:width||'100%',height:height||'100%',position:'absolute'},animatedStyle],__self:_this,__source:{fileName:_jsxFileName,lineNumber:98,columnNumber:9}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:108,columnNumber:13}},children({animationValue:animationValue})));};exports.BaseLayout=BaseLayout;
|
|
101
2
|
//# sourceMappingURL=BaseLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","handlerOffsetX","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","data","width","height","vertical","customConfig","mode","modeConfig","size","
|
|
1
|
+
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","handlerOffsetX","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","data","width","height","vertical","customConfig","mode","modeConfig","size","useState","shouldUpdate","setShouldUpdate","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","runOnJS","position"],"mappings":"gWAAA,oDAEA,uFAOA,+CAEA,qCACA,+B,u5DAKO,GAAMA,CAAAA,UAQX,CAAG,QARQA,CAAAA,UAQR,CAACC,KAAD,CAAW,CACZ,GAAQC,CAAAA,cAAR,CACID,KADJ,CAAQC,cAAR,CAAwBC,KAAxB,CACIF,KADJ,CAAwBE,KAAxB,CAA+BC,QAA/B,CACIH,KADJ,CAA+BG,QAA/B,CAAyCC,aAAzC,CACIJ,KADJ,CAAyCI,aAAzC,CAAwDC,cAAxD,CACIL,KADJ,CAAwDK,cAAxD,CAGA,GAAMC,CAAAA,OAAO,CAAGC,eAAMC,UAAN,CAAiBC,UAAjB,CAAhB,CACA,mBAWIH,OAXJ,CACIN,KADJ,CAEQU,IAFR,gBAEQA,IAFR,CAGQC,IAHR,gBAGQA,IAHR,CAIQC,KAJR,gBAIQA,KAJR,CAKQC,MALR,gBAKQA,MALR,CAMQC,QANR,gBAMQA,QANR,CAOQC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sB,CAmEK,MAnEKT,IAmEL,oUAGlB,CAACb,cAAD,CAHkB,CAAtB,CAMA,GAAM0B,CAAAA,UAAU,CAAGxB,eAAMyB,WAAN,CACf,SAACC,aAAD,CAA0BC,aAA1B,CAAsD,CAClDb,eAAe,CACVnB,KAAK,EAAI+B,aAAa,CAAC,CAAD,CAAtB,EAA6B/B,KAAK,EAAI+B,aAAa,CAAC,CAAD,CAApD,EACK/B,KAAK,EAAIgC,aAAa,CAAC,CAAD,CAAtB,EAA6BhC,KAAK,EAAIgC,aAAa,CAAC,CAAD,CAF7C,CAAf,CAIH,CANc,CAOf,CAAChC,KAAD,CAPe,CAAnB,CAUA,iEACI,oBAAME,CAAAA,aAAa,CAACyB,KAApB,EADJ,4BApFGzB,aAoFH,6TAEU,CACF,mCAAQ2B,UAAR,EACI3B,aAAa,CAACyB,KAAd,CAAoBI,aADxB,CAEI7B,aAAa,CAACyB,KAAd,CAAoBK,aAFxB,EAIH,CAPL,sBAnFFC,8BAmFE,YAnFMJ,UAmFN,eAnFqD3B,aAmFrD,8WAQI,CAACA,aAAa,CAACyB,KAAf,CARJ,EAWA,MACI,8BAAC,8BAAD,CAAU,IAAV,EACI,KAAK,CAAE,CACH,CACIjB,KAAK,CAAEA,KAAK,EAAI,MADpB,CAEIC,MAAM,CAAEA,MAAM,EAAI,MAFtB,CAGIuB,QAAQ,CAAE,UAHd,CADG,CAMHN,aANG,CADX,6EAUI,6BAAC,kBAAD,EAAU,YAAY,CAAEV,YAAxB,+EACKjB,QAAQ,CAAC,CAAEyB,cAAc,CAAdA,cAAF,CAAD,CADb,CAVJ,CADJ,CAgBH,CA/FM,C","sourcesContent":["import React from 'react';\nimport type { ViewStyle } from 'react-native';\nimport Animated, {\n AnimatedStyleProp,\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from 'react-native-reanimated';\nimport { IOpts, useOffsetX } from '../hooks/useOffsetX';\nimport type { IVisibleRanges } from '../hooks/useVisibleRanges';\nimport { LazyView } from '../LazyView';\nimport { CTX } from '../store';\nimport type { ILayoutConfig } from './stack';\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number;\n handlerOffsetX: Animated.SharedValue<number>;\n visibleRanges: IVisibleRanges;\n animationStyle: TAnimationStyle;\n children: (ctx: {\n animationValue: Animated.SharedValue<number>;\n }) => React.ReactElement;\n}> = (props) => {\n const { handlerOffsetX, index, children, visibleRanges, animationStyle } =\n props;\n\n const context = React.useContext(CTX);\n const {\n props: {\n loop,\n data,\n width,\n height,\n vertical,\n customConfig,\n mode,\n modeConfig,\n },\n } = context;\n const size = vertical ? height : width;\n const [shouldUpdate, setShouldUpdate] = React.useState(false);\n let offsetXConfig: IOpts = {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n ...(typeof customConfig === 'function' ? customConfig() : {}),\n };\n\n if (mode === 'horizontal-stack') {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffsetX,\n index,\n size,\n data,\n loop,\n type: snapDirection === 'right' ? 'negative' : 'positive',\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n // @ts-ignore\n () => animationStyle(x.value / size),\n [animationStyle]\n );\n\n const updateView = React.useCallback(\n (negativeRange: number[], positiveRange: number[]) => {\n setShouldUpdate(\n (index >= negativeRange[0] && index <= negativeRange[1]) ||\n (index >= positiveRange[0] && index <= positiveRange[1])\n );\n },\n [index]\n );\n\n useAnimatedReaction(\n () => visibleRanges.value,\n () => {\n runOnJS(updateView)(\n visibleRanges.value.negativeRange,\n visibleRanges.value.positiveRange\n );\n },\n [visibleRanges.value]\n );\n\n return (\n <Animated.View\n style={[\n {\n width: width || '100%',\n height: height || '100%',\n position: 'absolute',\n },\n animatedStyle,\n ]}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
|