react-native-reanimated-carousel
Version:
Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.
2 lines • 5.73 kB
JavaScript
var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.useCommonVariables=useCommonVariables;var _react=_interopRequireDefault(require("react"));var _reactNativeReanimated=require("react-native-reanimated");var _computeNewIndexWhenDataChanges=require("./computeNewIndexWhenDataChanges");var _handlerOffsetDirection=require("../utils/handlerOffsetDirection");var _worklet_10652703225927_init_data={code:"function anonymous() {\n const {\n prevDataLength,\n dataLength,\n loop\n } = this._closure;\n const previousLength = prevDataLength.value;\n const currentLength = dataLength;\n const isLengthChanged = previousLength !== currentLength;\n const shouldComputed = isLengthChanged && loop;\n if (shouldComputed) prevDataLength.value = dataLength;\n return {\n shouldComputed: shouldComputed,\n previousLength: previousLength,\n currentLength: currentLength\n };\n}",location:"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useCommonVariables.ts",sourceMap:"{\"version\":3,\"names\":[\"anonymous\",\"prevDataLength\",\"dataLength\",\"loop\",\"_closure\",\"previousLength\",\"value\",\"currentLength\",\"isLengthChanged\",\"shouldComputed\"],\"sources\":[\"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useCommonVariables.ts\"],\"mappings\":\"AAsCsB,SAAAA,SAAMA,CAAA;EAAA;IAAAC,cAAA;IAAAC,UAAA;IAAAC;EAAA,SAAAC,QAAA;EACxB,MAAMC,cAAc,GAAGJ,cAAc,CAACK,KAAK;EAC3C,MAAMC,aAAa,GAAGL,UAAU;EAChC,MAAMM,eAAe,GAAGH,cAAc,KAAKE,aAAa;EACxD,MAAME,cAAc,GAAGD,eAAe,IAAIL,IAAI;EAE9C,IAAIM,cAAc,EAChBR,cAAc,CAACK,KAAK,GAAGJ,UAAU;EAEnC,OAAO;IACLO,cAAc,EAAdA,cAAc;IACdJ,cAAc,EAAdA,cAAc;IACdE,aAAA,EAAAA;EACF,CAAC;AACH\"}"};var _worklet_17314307749108_init_data={code:"function anonymous({\n shouldComputed: shouldComputed,\n previousLength: previousLength,\n currentLength: currentLength\n}) {\n const {\n handlerOffsetDirection,\n handlerOffset,\n computeNewIndexWhenDataChanges,\n size\n } = this._closure;\n if (shouldComputed) {\n const direction = handlerOffsetDirection(handlerOffset);\n handlerOffset.value = computeNewIndexWhenDataChanges({\n direction: direction,\n previousLength: previousLength,\n currentLength: currentLength,\n size: size,\n handlerOffset: handlerOffset.value\n });\n }\n}",location:"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useCommonVariables.ts",sourceMap:"{\"version\":3,\"names\":[\"anonymous\",\"shouldComputed\",\"previousLength\",\"currentLength\",\"handlerOffsetDirection\",\"handlerOffset\",\"computeNewIndexWhenDataChanges\",\"size\",\"_closure\",\"direction\",\"value\"],\"sources\":[\"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useCommonVariables.ts\"],\"mappings\":\"AAoDK,SAACA,UAAA;EAAEC,cAAc,EAAdA,cAAc;EAAEC,cAAc,EAAdA,cAAc;EAAEC,aAAA,EAAAA;AAAc,CAAC,EAAK;EAAA;IAAAC,sBAAA;IAAAC,aAAA;IAAAC,8BAAA;IAAAC;EAAA,SAAAC,QAAA;EACxD,IAAIP,cAAc,EAAE;IAElB,MAAMQ,SAAS,GAAGL,sBAAsB,CAACC,aAAa,CAAC;IAEvDA,aAAa,CAACK,KAAK,GAAGJ,8BAA8B,CAAC;MACnDG,SAAS,EAATA,SAAS;MACTP,cAAc,EAAdA,cAAc;MACdC,aAAa,EAAbA,aAAa;MACbI,IAAI,EAAJA,IAAI;MACJF,aAAa,EAAEA,aAAa,CAACK;IAC/B,CAAC,CAAC;EACJ;AACF\"}"};function useCommonVariables(props){var vertical=props.vertical,height=props.height,width=props.width,dataLength=props.dataLength,defaultIndex=props.defaultIndex,defaultScrollOffsetValue=props.defaultScrollOffsetValue,loop=props.loop;var size=vertical?height:width;var validLength=dataLength-1;var defaultHandlerOffsetValue=-Math.abs(defaultIndex*size);var _handlerOffset=(0,_reactNativeReanimated.useSharedValue)(defaultHandlerOffsetValue);var handlerOffset=defaultScrollOffsetValue!=null?defaultScrollOffsetValue:_handlerOffset;var prevDataLength=(0,_reactNativeReanimated.useSharedValue)(dataLength);_react.default.useEffect(function(){handlerOffset.value=defaultHandlerOffsetValue;},[vertical,handlerOffset,defaultHandlerOffsetValue]);(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _e=[new global.Error(),-4,-27];var _f=function _f(){var previousLength=prevDataLength.value;var currentLength=dataLength;var isLengthChanged=previousLength!==currentLength;var shouldComputed=isLengthChanged&&loop;if(shouldComputed)prevDataLength.value=dataLength;return{shouldComputed:shouldComputed,previousLength:previousLength,currentLength:currentLength};};_f._closure={prevDataLength:prevDataLength,dataLength:dataLength,loop:loop};_f.__initData=_worklet_10652703225927_init_data;_f.__workletHash=10652703225927;_f.__stackDetails=_e;_f.__version="3.3.0";return _f;}(),function(){var _e=[new global.Error(),-5,-27];var _f=function _f(_ref){var shouldComputed=_ref.shouldComputed,previousLength=_ref.previousLength,currentLength=_ref.currentLength;if(shouldComputed){var direction=(0,_handlerOffsetDirection.handlerOffsetDirection)(handlerOffset);handlerOffset.value=(0,_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges)({direction:direction,previousLength:previousLength,currentLength:currentLength,size:size,handlerOffset:handlerOffset.value});}};_f._closure={handlerOffsetDirection:_handlerOffsetDirection.handlerOffsetDirection,handlerOffset:handlerOffset,computeNewIndexWhenDataChanges:_computeNewIndexWhenDataChanges.computeNewIndexWhenDataChanges,size:size};_f.__initData=_worklet_17314307749108_init_data;_f.__workletHash=17314307749108;_f.__stackDetails=_e;_f.__version="3.3.0";return _f;}(),[dataLength,loop]);return{size:size,validLength:validLength,handlerOffset:handlerOffset};}
//# sourceMappingURL=useCommonVariables.js.map