react-native-reanimated-carousel 3.2.0 → 3.3.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/README.md +9 -0
- package/README.zh-CN.md +8 -0
- package/lib/commonjs/hooks/index.test.js +1 -1
- package/lib/commonjs/hooks/index.test.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/module/hooks/index.test.js +0 -1
- package/lib/module/hooks/index.test.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +7 -0
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/package.json +6 -7
- package/src/hooks/index.test.ts +0 -2
- package/src/layouts/BaseLayout.tsx +7 -1
package/README.md
CHANGED
|
@@ -148,6 +148,15 @@ export default Index;
|
|
|
148
148
|
- Working principle
|
|
149
149
|
- [About RNRC](./docs/about.md)
|
|
150
150
|
|
|
151
|
+
- How to run tests in `exampleExpo`
|
|
152
|
+
```shell
|
|
153
|
+
$ yarn prepare
|
|
154
|
+
$ yarn link --global
|
|
155
|
+
$ cd ./exampleExpo
|
|
156
|
+
$ yarn link react-native-reanimated-carousel --global
|
|
157
|
+
$ yarn test
|
|
158
|
+
```
|
|
159
|
+
|
|
151
160
|
## Reason
|
|
152
161
|
|
|
153
162
|
<details>
|
package/README.zh-CN.md
CHANGED
|
@@ -144,6 +144,14 @@ export default Index;
|
|
|
144
144
|
- 如果你使用 EXPO 托管工作流,请确定你的 EXPO SDK 版本大于 41,因为旧的版本并不支持`Reanimated(v2)`。
|
|
145
145
|
- 工作原理
|
|
146
146
|
- [关于RNRC](./docs/about.zh-CN.md)
|
|
147
|
+
- 如何运行`exampleExpo`的测试
|
|
148
|
+
```shell
|
|
149
|
+
$ yarn prepare
|
|
150
|
+
$ yarn link --global
|
|
151
|
+
$ cd ./exampleExpo
|
|
152
|
+
$ yarn link react-native-reanimated-carousel --global
|
|
153
|
+
$ yarn test
|
|
154
|
+
```
|
|
147
155
|
|
|
148
156
|
## 原因
|
|
149
157
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var
|
|
1
|
+
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");var _regenerator=_interopRequireDefault(require("@babel/runtime/regenerator"));var _computeNewIndexWhenDataChanges=require("./computeNewIndexWhenDataChanges");describe("should work as expected",function(){var size=375;var positive=-1;var negative=1;var params=function params(_params){var currentIndex=_params.currentIndex,_direction=_params.direction,previousLength=_params.previousLength,currentLength=_params.currentLength;var direction=_direction==="negative"?negative:positive;return{direction:direction,handlerOffset:size*currentIndex*direction,size:size,previousLength:previousLength,currentLength:currentLength};};it("The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.",function _callee(){var currentIndex,handlerOffset;return _regenerator.default.async(function _callee$(_context){while(1){switch(_context.prev=_context.next){case 0:currentIndex=1;handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:currentIndex,direction:"negative",previousLength:4,currentLength:3}));expect(handlerOffset/size).toBe(2*positive);case 3:case"end":return _context.stop();}}},null,null,null,Promise);});it("The direction is negative, Changing length of data set from 4 to 3, the index remains original.",function _callee2(){var handlerOffset;return _regenerator.default.async(function _callee2$(_context2){while(1){switch(_context2.prev=_context2.next){case 0:handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:2,direction:"negative",previousLength:4,currentLength:3}));expect(handlerOffset/size).toBe(1*negative);case 2:case"end":return _context2.stop();}}},null,null,null,Promise);});it("The direction is positive, Changing length of data set from 4 to 5, the index remains original.",function _callee3(){var handlerOffset;return _regenerator.default.async(function _callee3$(_context3){while(1){switch(_context3.prev=_context3.next){case 0:handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:3,direction:"positive",previousLength:4,currentLength:5}));expect(handlerOffset/size).toBe(3*positive);case 2:case"end":return _context3.stop();}}},null,null,null,Promise);});it("The direction is negative, Changing length of data set from 4 to 5, the index remains original.",function _callee4(){var handlerOffset;return _regenerator.default.async(function _callee4$(_context4){while(1){switch(_context4.prev=_context4.next){case 0:handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:3,direction:"negative",previousLength:4,currentLength:5}));expect(handlerOffset/size).toBe(4*negative);case 2:case"end":return _context4.stop();}}},null,null,null,Promise);});it("Changing length of data set from 0 to 3, the index remains original.",function _callee5(){var handlerOffset;return _regenerator.default.async(function _callee5$(_context5){while(1){switch(_context5.prev=_context5.next){case 0:handlerOffset=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)(params({currentIndex:0,direction:"positive",previousLength:0,currentLength:3}));expect(handlerOffset/size).toBe(0*positive);case 2:case"end":return _context5.stop();}}},null,null,null,Promise);});});
|
|
2
2
|
//# sourceMappingURL=index.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.test.ts"],"names":["size","positive","negative","params","currentIndex","_direction","direction","previousLength","currentLength","handlerOffset","toBe"],"mappings":"kKAAA,
|
|
1
|
+
{"version":3,"sources":["index.test.ts"],"names":["describe","size","positive","negative","params","currentIndex","_direction","direction","previousLength","currentLength","handlerOffset","it","expect","toBe"],"mappings":"kKAAA,gFAEAA,QAAQ,CAAC,yBAAD,CAA4B,UAAM,CACxC,GAAMC,CAAAA,IAAI,CAAG,GAAb,CACA,GAAMC,CAAAA,QAAQ,CAAG,CAAC,CAAlB,CACA,GAAMC,CAAAA,QAAQ,CAAG,CAAjB,CAEA,GAAMC,CAAAA,MAAM,CAAG,gBAACA,OAAD,CAKT,CACJ,GAAQC,CAAAA,YAAR,CAA+ED,OAA/E,CAAQC,YAAR,CAAiCC,UAAjC,CAA+EF,OAA/E,CAAsBG,SAAtB,CAA6CC,cAA7C,CAA+EJ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T,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,EAAIX,QAAtC,EARoG,sEAApG,CAAF,CAWAS,EAAE,CAAC,iGAAD,CAAoG,4JAC9FD,aAD8F,CAC9E,mEAA+BN,MAAM,CAAC,CAC1DC,YAAY,CAAE,CAD4C,CAE1DE,SAAS,CAAE,UAF+C,CAG1DC,cAAc,CAAE,CAH0C,CAI1DC,aAAa,CAAE,CAJ2C,CAAD,CAArC,CAD8E,CAQpGG,MAAM,CAACF,aAAa,CAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,EAAIV,QAAtC,EARoG,sEAApG,CAAF,CAWAQ,EAAE,CAAC,sEAAD,CAAyE,4JACnED,aADmE,CACnD,mEAA+BN,MAAM,CAAC,CAC1DC,YAAY,CAAE,CAD4C,CAE1DE,SAAS,CAAE,UAF+C,CAG1DC,cAAc,CAAE,CAH0C,CAI1DC,aAAa,CAAE,CAJ2C,CAAD,CAArC,CADmD,CAQzEG,MAAM,CAACF,aAAa,CAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,EAAIX,QAAtC,EARyE,sEAAzE,CAAF,CAUD,CA7EO,CAAR","sourcesContent":["import { computeNewIndexWhenDataChanges } from \"./computeNewIndexWhenDataChanges\";\n\ndescribe(\"should work as expected\", () => {\n const size = 375;\n const positive = -1;\n const negative = 1;\n\n const params = (params: {\n direction: \"positive\" | \"negative\"\n currentIndex: number\n previousLength: number\n currentLength: number\n }) => {\n const { currentIndex, direction: _direction, previousLength, currentLength } = params;\n const direction = _direction === \"negative\" ? negative : positive;\n return {\n direction,\n handlerOffset: size * currentIndex * direction,\n size,\n previousLength,\n currentLength,\n };\n };\n\n it(\"The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.\", async () => {\n const currentIndex = 1;\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(2 * positive);\n });\n\n it(\"The direction is negative, Changing length of data set from 4 to 3, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 2,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(1 * negative);\n });\n\n it(\"The direction is positive, Changing length of data set from 4 to 5, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 3,\n direction: \"positive\",\n previousLength: 4,\n currentLength: 5,\n }));\n\n expect(handlerOffset / size).toBe(3 * positive);\n });\n\n it(\"The direction is negative, Changing length of data set from 4 to 5, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 3,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 5,\n }));\n\n expect(handlerOffset / size).toBe(4 * negative);\n });\n\n it(\"Changing length of data set from 0 to 3, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 0,\n direction: \"positive\",\n previousLength: 0,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(0 * positive);\n });\n});\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.BaseLayout=void 0;var _defineProperty2=_interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));var _slicedToArray2=_interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=_interopRequireWildcard(require("react-native-reanimated"));var _useCheckMounted=require("../hooks/useCheckMounted");var _useOffsetX=require("../hooks/useOffsetX");var _LazyView=require("../LazyView");var _store=require("../store");var _this=this,_jsxFileName="/home/runner/work/react-native-reanimated-carousel/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,dataLength=_context$props.dataLength,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,dataLength:dataLength,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,dataLength:dataLength,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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (74:41)";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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (76:4)";_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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (92:4)";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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (93:4)";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:103,columnNumber:5}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:
|
|
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="/home/runner/work/react-native-reanimated-carousel/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,dataLength=_context$props.dataLength,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,dataLength:dataLength,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,dataLength:dataLength,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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (74:41)";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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (76:4)";_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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (92:4)";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="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/layouts/BaseLayout.tsx (93:4)";return _f;}(),[visibleRanges.value]);return _react.default.createElement(_reactNativeReanimated.default.View,{style:[{width:width||"100%",height:height||"100%",position:"absolute"},animatedStyle],testID:"__CAROUSEL_ITEM_"+index+"_"+(shouldUpdate?"READY":"NOT_READY")+"__",__self:_this,__source:{fileName:_jsxFileName,lineNumber:103,columnNumber:5}},_react.default.createElement(_LazyView.LazyView,{shouldUpdate:shouldUpdate,__self:_this,__source:{fileName:_jsxFileName,lineNumber:119,columnNumber:7}},children({animationValue:animationValue})));};exports.BaseLayout=BaseLayout;
|
|
2
2
|
//# sourceMappingURL=BaseLayout.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","mounted","handlerOffset","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","dataLength","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,oDAGA,uFASA,yDAEA,+CAEA,qCACA,+B,y5DAIO,GAAMA,CAAAA,UAQX,CAAG,QARQA,CAAAA,UAQR,CAACC,KAAD,CAAW,CACd,GAAMC,CAAAA,OAAO,CAAG,sCAAhB,CACA,GAAQC,CAAAA,aAAR,
|
|
1
|
+
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","mounted","handlerOffset","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","dataLength","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,oDAGA,uFASA,yDAEA,+CAEA,qCACA,+B,y5DAIO,GAAMA,CAAAA,UAQX,CAAG,QARQA,CAAAA,UAQR,CAACC,KAAD,CAAW,CACd,GAAMC,CAAAA,OAAO,CAAG,sCAAhB,CACA,GAAQC,CAAAA,aAAR,CACEF,KADF,CAAQE,aAAR,CAAuBC,KAAvB,CACEH,KADF,CAAuBG,KAAvB,CAA8BC,QAA9B,CACEJ,KADF,CAA8BI,QAA9B,CAAwCC,aAAxC,CACEL,KADF,CAAwCK,aAAxC,CAAuDC,cAAvD,CACEN,KADF,CAAuDM,cAAvD,CAGA,GAAMC,CAAAA,OAAO,CAAGC,eAAMC,UAAN,CAAiBC,UAAjB,CAAhB,CACA,mBAWIH,OAXJ,CACEP,KADF,CAEIW,IAFJ,gBAEIA,IAFJ,CAGIC,UAHJ,gBAGIA,UAHJ,CAIIC,KAJJ,gBAIIA,KAJJ,CAKIC,MALJ,gBAKIA,MALJ,CAMIC,QANJ,gBAMIA,QANJ,CAOIC,YAPJ,gBAOIA,YAPJ,CAQIC,IARJ,gBAQIA,IARJ,CASIC,UATJ,gBASIA,UATJ,CAYA,GAAMC,CAAAA,IAAI,CAAGJ,QAAQ,CAAGD,MAAH,CAAYD,KAAjC,CACA,oBAAwCL,eAAMY,QAAN,CAAe,KAAf,CAAxC,iEAAOC,YAAP,qBAAqBC,eAArB,qBACA,GAAIC,CAAAA,aAAoB,gBACtBrB,aAAa,CAAbA,aADsB,CAEtBC,KAAK,CAALA,KAFsB,CAGtBgB,IAAI,CAAJA,IAHsB,CAItBP,UAAU,CAAVA,UAJsB,CAKtBD,IAAI,CAAJA,IALsB,EAMlB,MAAOK,CAAAA,YAAP,GAAwB,UAAxB,CAAqCA,YAAY,EAAjD,CAAsD,EANpC,CAAxB,CASA,GAAIC,IAAI,GAAK,kBAAb,CAA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B,aAyFL,qTAEQ,CACJ,mCAAQ2B,UAAR,EACE3B,aAAa,CAACyB,KAAd,CAAoBI,aADtB,CAEE7B,aAAa,CAACyB,KAAd,CAAoBK,aAFtB,EAID,CAPH,sBAxFAE,8BAwFA,YAxFQL,UAwFR,eAxFuD3B,aAwFvD,sWAQE,CAACA,aAAa,CAACyB,KAAf,CARF,EAWA,MACE,8BAAC,8BAAD,CAAU,IAAV,EACE,KAAK,CAAE,CACL,CACEjB,KAAK,CAAEA,KAAK,EAAI,MADlB,CAEEC,MAAM,CAAEA,MAAM,EAAI,MAFpB,CAGEwB,QAAQ,CAAE,UAHZ,CADK,CAMLP,aANK,CADT,CAcE,MAAM,oBAAqB5B,KAArB,MAA8BkB,YAAY,CAAG,OAAH,CAAa,WAAvD,MAdR,8EAgBE,6BAAC,kBAAD,EAAU,YAAY,CAAEA,YAAxB,8EACGjB,QAAQ,CAAC,CAAEyB,cAAc,CAAdA,cAAF,CAAD,CADX,CAhBF,CADF,CAsBD,CAtGM,C","sourcesContent":["import React from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport type { AnimatedStyleProp } from \"react-native-reanimated\";\nimport Animated, {\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { ILayoutConfig } from \"./stack\";\n\nimport { useCheckMounted } from \"../hooks/useCheckMounted\";\nimport type { IOpts } from \"../hooks/useOffsetX\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { LazyView } from \"../LazyView\";\nimport { CTX } from \"../store\";\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number\n handlerOffset: Animated.SharedValue<number>\n visibleRanges: IVisibleRanges\n animationStyle: TAnimationStyle\n children: (ctx: {\n animationValue: Animated.SharedValue<number>\n }) => React.ReactElement\n}> = (props) => {\n const 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 dataLength,\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,\n index,\n size,\n dataLength,\n loop,\n ...(typeof customConfig === \"function\" ? customConfig() : {}),\n };\n\n if (mode === \"horizontal-stack\") {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n type: snapDirection === \"right\" ? \"negative\" : \"positive\",\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n () => 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 * We use this testID to know when the carousel item is ready to be tested in test.\n * e.g.\n * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.\n * */\n testID={`__CAROUSEL_ITEM_${index}_${shouldUpdate ? \"READY\" : \"NOT_READY\"}__`}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.test.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["index.test.ts"],"names":["computeNewIndexWhenDataChanges","describe","size","positive","negative","params","currentIndex","direction","_direction","previousLength","currentLength","handlerOffset","it","expect","toBe"],"mappings":"AAAA,SAASA,8BAAT,QAA+C,kCAA/C;AAEAC,QAAQ,CAAC,yBAAD,EAA4B,MAAM;AACxC,QAAMC,IAAI,GAAG,GAAb;AACA,QAAMC,QAAQ,GAAG,CAAC,CAAlB;AACA,QAAMC,QAAQ,GAAG,CAAjB;;AAEA,QAAMC,MAAM,GAAIA,MAAD,IAKT;AACJ,UAAM;AAAEC,MAAAA,YAAF;AAAgBC,MAAAA,SAAS,EAAEC,UAA3B;AAAuCC,MAAAA,cAAvC;AAAuDC,MAAAA;AAAvD,QAAyEL,MAA/E;AACA,UAAME,SAAS,GAAGC,UAAU,KAAK,UAAf,GAA4BJ,QAA5B,GAAuCD,QAAzD;AACA,WAAO;AACLI,MAAAA,SADK;AAELI,MAAAA,aAAa,EAAET,IAAI,GAAGI,YAAP,GAAsBC,SAFhC;AAGLL,MAAAA,IAHK;AAILO,MAAAA,cAJK;AAKLC,MAAAA;AALK,KAAP;AAOD,GAfD;;AAiBAE,EAAAA,EAAE,CAAC,qGAAD,EAAwG,YAAY;AACpH,UAAMN,YAAY,GAAG,CAArB;AACA,UAAMK,aAAa,GAAGX,8BAA8B,CAACK,MAAM,CAAC;AAC1DC,MAAAA,YAD0D;AAE1DC,MAAAA,SAAS,EAAE,UAF+C;AAG1DE,MAAAA,cAAc,EAAE,CAH0C;AAI1DC,MAAAA,aAAa,EAAE;AAJ2C,KAAD,CAAP,CAApD;AAOAG,IAAAA,MAAM,CAACF,aAAa,GAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,IAAIX,QAAtC;AACD,GAVC,CAAF;AAYAS,EAAAA,EAAE,CAAC,iGAAD,EAAoG,YAAY;AAChH,UAAMD,aAAa,GAAGX,8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C,MAAAA,aAAa,EAAE;AAJ2C,KAAD,CAAP,CAApD;AAOAG,IAAAA,MAAM,CAACF,aAAa,GAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,IAAIX,QAAtC;AACD,GATC,CAAF;AAUD,CA7EO,CAAR","sourcesContent":["import { computeNewIndexWhenDataChanges } from \"./computeNewIndexWhenDataChanges\";\n\ndescribe(\"should work as expected\", () => {\n const size = 375;\n const positive = -1;\n const negative = 1;\n\n const params = (params: {\n direction: \"positive\" | \"negative\"\n currentIndex: number\n previousLength: number\n currentLength: number\n }) => {\n const { currentIndex, direction: _direction, previousLength, currentLength } = params;\n const direction = _direction === \"negative\" ? negative : positive;\n return {\n direction,\n handlerOffset: size * currentIndex * direction,\n size,\n previousLength,\n currentLength,\n };\n };\n\n it(\"The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.\", async () => {\n const currentIndex = 1;\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(2 * positive);\n });\n\n it(\"The direction is negative, Changing length of data set from 4 to 3, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 2,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(1 * negative);\n });\n\n it(\"The direction is positive, Changing length of data set from 4 to 5, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 3,\n direction: \"positive\",\n previousLength: 4,\n currentLength: 5,\n }));\n\n expect(handlerOffset / size).toBe(3 * positive);\n });\n\n it(\"The direction is negative, Changing length of data set from 4 to 5, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 3,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 5,\n }));\n\n expect(handlerOffset / size).toBe(4 * negative);\n });\n\n it(\"Changing length of data set from 0 to 3, the index remains original.\", async () => {\n const handlerOffset = computeNewIndexWhenDataChanges(params({\n currentIndex: 0,\n direction: \"positive\",\n previousLength: 0,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(0 * positive);\n });\n});\n"]}
|
|
@@ -68,6 +68,13 @@ export const BaseLayout = props => {
|
|
|
68
68
|
height: height || "100%",
|
|
69
69
|
position: "absolute"
|
|
70
70
|
}, animatedStyle]
|
|
71
|
+
/**
|
|
72
|
+
* We use this testID to know when the carousel item is ready to be tested in test.
|
|
73
|
+
* e.g.
|
|
74
|
+
* The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.
|
|
75
|
+
* */
|
|
76
|
+
,
|
|
77
|
+
testID: `__CAROUSEL_ITEM_${index}_${shouldUpdate ? "READY" : "NOT_READY"}__`
|
|
71
78
|
}, /*#__PURE__*/React.createElement(LazyView, {
|
|
72
79
|
shouldUpdate: shouldUpdate
|
|
73
80
|
}, children({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["BaseLayout.tsx"],"names":["React","Animated","runOnJS","useAnimatedReaction","useAnimatedStyle","useDerivedValue","useCheckMounted","useOffsetX","LazyView","CTX","BaseLayout","props","mounted","handlerOffset","index","children","visibleRanges","animationStyle","context","useContext","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","shouldUpdate","setShouldUpdate","useState","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","current","position"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,OAAOC,QAAP,IACEC,OADF,EAEEC,mBAFF,EAGEC,gBAHF,EAIEC,eAJF,QAKO,yBALP;AASA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,SAASC,UAAT,QAA2B,qBAA3B;AAEA,SAASC,QAAT,QAAyB,aAAzB;AACA,SAASC,GAAT,QAAoB,UAApB;AAIA,OAAO,MAAMC,UAQX,GAAIC,KAAD,IAAW;AACd,QAAMC,OAAO,GAAGN,eAAe,EAA/B;AACA,QAAM;AAAEO,IAAAA,aAAF;AAAiBC,IAAAA,KAAjB;AAAwBC,IAAAA,QAAxB;AAAkCC,IAAAA,aAAlC;AAAiDC,IAAAA;AAAjD,
|
|
1
|
+
{"version":3,"sources":["BaseLayout.tsx"],"names":["React","Animated","runOnJS","useAnimatedReaction","useAnimatedStyle","useDerivedValue","useCheckMounted","useOffsetX","LazyView","CTX","BaseLayout","props","mounted","handlerOffset","index","children","visibleRanges","animationStyle","context","useContext","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","shouldUpdate","setShouldUpdate","useState","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","updateView","useCallback","negativeRange","positiveRange","current","position"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,OAAOC,QAAP,IACEC,OADF,EAEEC,mBAFF,EAGEC,gBAHF,EAIEC,eAJF,QAKO,yBALP;AASA,SAASC,eAAT,QAAgC,0BAAhC;AAEA,SAASC,UAAT,QAA2B,qBAA3B;AAEA,SAASC,QAAT,QAAyB,aAAzB;AACA,SAASC,GAAT,QAAoB,UAApB;AAIA,OAAO,MAAMC,UAQX,GAAIC,KAAD,IAAW;AACd,QAAMC,OAAO,GAAGN,eAAe,EAA/B;AACA,QAAM;AAAEO,IAAAA,aAAF;AAAiBC,IAAAA,KAAjB;AAAwBC,IAAAA,QAAxB;AAAkCC,IAAAA,aAAlC;AAAiDC,IAAAA;AAAjD,MACJN,KADF;AAGA,QAAMO,OAAO,GAAGlB,KAAK,CAACmB,UAAN,CAAiBV,GAAjB,CAAhB;AACA,QAAM;AACJE,IAAAA,KAAK,EAAE;AACLS,MAAAA,IADK;AAELC,MAAAA,UAFK;AAGLC,MAAAA,KAHK;AAILC,MAAAA,MAJK;AAKLC,MAAAA,QALK;AAMLC,MAAAA,YANK;AAOLC,MAAAA,IAPK;AAQLC,MAAAA;AARK;AAD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AAI6B,aAAa,CAAC,CAAD,CAAtB,IAA6B7B,KAAK,IAAI6B,aAAa,CAAC,CAAD,CAApD,IACU7B,KAAK,IAAI8B,aAAa,CAAC,CAAD,CAAtB,IAA6B9B,KAAK,IAAI8B,aAAa,CAAC,CAAD,CAF7C,CAD5B;AAKD,GAPgB,EAQjB,CAAC9B,KAAD,EAAQF,OAAR,CARiB,CAAnB;AAWAT,EAAAA,mBAAmB,CACjB,MAAMa,aAAa,CAACuB,KADH,EAEjB,MAAM;AACJrC,IAAAA,OAAO,CAACuC,UAAD,CAAP,CACEzB,aAAa,CAACuB,KAAd,CAAoBI,aADtB,EAEE3B,aAAa,CAACuB,KAAd,CAAoBK,aAFtB;AAID,GAPgB,EAQjB,CAAC5B,aAAa,CAACuB,KAAf,CARiB,CAAnB;AAWA,sBACE,oBAAC,QAAD,CAAU,IAAV;AACE,IAAA,KAAK,EAAE,CACL;AACEjB,MAAAA,KAAK,EAAEA,KAAK,IAAI,MADlB;AAEEC,MAAAA,MAAM,EAAEA,MAAM,IAAI,MAFpB;AAGEuB,MAAAA,QAAQ,EAAE;AAHZ,KADK,EAMLN,aANK;AAQP;AACN;AACA;AACA;AACA;AAbI;AAcE,IAAA,MAAM,EAAG,mBAAkB1B,KAAM,IAAGe,YAAY,GAAG,OAAH,GAAa,WAAY;AAd3E,kBAgBE,oBAAC,QAAD;AAAU,IAAA,YAAY,EAAEA;AAAxB,KACGd,QAAQ,CAAC;AAAEuB,IAAAA;AAAF,GAAD,CADX,CAhBF,CADF;AAsBD,CAtGM","sourcesContent":["import React from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport type { AnimatedStyleProp } from \"react-native-reanimated\";\nimport Animated, {\n runOnJS,\n useAnimatedReaction,\n useAnimatedStyle,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { ILayoutConfig } from \"./stack\";\n\nimport { useCheckMounted } from \"../hooks/useCheckMounted\";\nimport type { IOpts } from \"../hooks/useOffsetX\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { LazyView } from \"../LazyView\";\nimport { CTX } from \"../store\";\n\nexport type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;\n\nexport const BaseLayout: React.FC<{\n index: number\n handlerOffset: Animated.SharedValue<number>\n visibleRanges: IVisibleRanges\n animationStyle: TAnimationStyle\n children: (ctx: {\n animationValue: Animated.SharedValue<number>\n }) => React.ReactElement\n}> = (props) => {\n const 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 dataLength,\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,\n index,\n size,\n dataLength,\n loop,\n ...(typeof customConfig === \"function\" ? customConfig() : {}),\n };\n\n if (mode === \"horizontal-stack\") {\n const { snapDirection, showLength } = modeConfig as ILayoutConfig;\n\n offsetXConfig = {\n handlerOffset,\n index,\n size,\n dataLength,\n loop,\n type: snapDirection === \"right\" ? \"negative\" : \"positive\",\n viewCount: showLength,\n };\n }\n\n const x = useOffsetX(offsetXConfig, visibleRanges);\n const animationValue = useDerivedValue(() => x.value / size, [x, size]);\n const animatedStyle = useAnimatedStyle(\n () => 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 * We use this testID to know when the carousel item is ready to be tested in test.\n * e.g.\n * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.\n * */\n testID={`__CAROUSEL_ITEM_${index}_${shouldUpdate ? \"READY\" : \"NOT_READY\"}__`}\n >\n <LazyView shouldUpdate={shouldUpdate}>\n {children({ animationValue })}\n </LazyView>\n </Animated.View>\n );\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated-carousel",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.3.0",
|
|
4
4
|
"description": "Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"react-native": "src/index.tsx",
|
|
@@ -22,8 +22,8 @@
|
|
|
22
22
|
],
|
|
23
23
|
"scripts": {
|
|
24
24
|
"gif": "node scripts/makegif.js ./scripts/gif-works-directory",
|
|
25
|
-
"test": "
|
|
26
|
-
"test:dev": "
|
|
25
|
+
"test": "jest run src/**/*",
|
|
26
|
+
"test:dev": "jest dev src/**/*",
|
|
27
27
|
"typescript": "tsc --noEmit",
|
|
28
28
|
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
|
|
29
29
|
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --fix",
|
|
@@ -66,7 +66,7 @@
|
|
|
66
66
|
"@dohooo/eslint-config": "^0.0.7",
|
|
67
67
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
68
68
|
"@release-it/conventional-changelog": "^2.0.0",
|
|
69
|
-
"@types/jest": "^
|
|
69
|
+
"@types/jest": "^29.2.5",
|
|
70
70
|
"@types/react": "~17.0.2",
|
|
71
71
|
"@types/react-native": "^0.66.16",
|
|
72
72
|
"@types/react-native-snap-carousel": "^3.8.5",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"eslint-plugin-prettier": "^3.1.3",
|
|
81
81
|
"gifify": "^2.4.3",
|
|
82
82
|
"husky": "^4.2.5",
|
|
83
|
-
"jest": "^
|
|
83
|
+
"jest": "^29.3.1",
|
|
84
84
|
"pod-install": "^0.1.0",
|
|
85
85
|
"prettier": "^2.0.5",
|
|
86
86
|
"react": "16.13.1",
|
|
@@ -90,8 +90,7 @@
|
|
|
90
90
|
"react-native-reanimated": "2.8.0",
|
|
91
91
|
"release-it": "^14.2.2",
|
|
92
92
|
"sponsorkit": "^0.1.3",
|
|
93
|
-
"typescript": "^4.0.8"
|
|
94
|
-
"vitest": "^0.24.3"
|
|
93
|
+
"typescript": "^4.0.8"
|
|
95
94
|
},
|
|
96
95
|
"peerDependencies": {
|
|
97
96
|
"react": ">=16.8.0",
|
package/src/hooks/index.test.ts
CHANGED
|
@@ -30,7 +30,7 @@ export const BaseLayout: React.FC<{
|
|
|
30
30
|
}> = (props) => {
|
|
31
31
|
const mounted = useCheckMounted();
|
|
32
32
|
const { handlerOffset, index, children, visibleRanges, animationStyle }
|
|
33
|
-
|
|
33
|
+
= props;
|
|
34
34
|
|
|
35
35
|
const context = React.useContext(CTX);
|
|
36
36
|
const {
|
|
@@ -109,6 +109,12 @@ export const BaseLayout: React.FC<{
|
|
|
109
109
|
},
|
|
110
110
|
animatedStyle,
|
|
111
111
|
]}
|
|
112
|
+
/**
|
|
113
|
+
* We use this testID to know when the carousel item is ready to be tested in test.
|
|
114
|
+
* e.g.
|
|
115
|
+
* The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.
|
|
116
|
+
* */
|
|
117
|
+
testID={`__CAROUSEL_ITEM_${index}_${shouldUpdate ? "READY" : "NOT_READY"}__`}
|
|
112
118
|
>
|
|
113
119
|
<LazyView shouldUpdate={shouldUpdate}>
|
|
114
120
|
{children({ animationValue })}
|