UNPKG

react-native-reanimated-carousel

Version:

Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.

2 lines 3.98 kB
Object.defineProperty(exports,"__esModule",{value:true});exports.useVisibleRanges=useVisibleRanges;var _reactNativeReanimated=require("react-native-reanimated");var _worklet_1686155145629_init_data={code:"function anonymous() {\n const {\n windowSize,\n translation,\n viewSize,\n total\n } = this._closure;\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 = [(curIndex - negativeCount + total) % total, (curIndex - 1 + total) % total];\n const positiveRange = [(curIndex + total) % total, (curIndex + positiveCount + total) % total];\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 {\n negativeRange: negativeRange,\n positiveRange: positiveRange\n };\n}",location:"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useVisibleRanges.tsx",sourceMap:"{\"version\":3,\"names\":[\"anonymous\",\"windowSize\",\"translation\",\"viewSize\",\"total\",\"_closure\",\"positiveCount\",\"Math\",\"round\",\"negativeCount\",\"curIndex\",\"value\",\"negativeRange\",\"positiveRange\"],\"sources\":[\"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/hooks/useVisibleRanges.tsx\"],\"mappings\":\"AAuBiC,SAAAA,SAAMA,CAAA;EAAA;IAAAC,UAAA;IAAAC,WAAA;IAAAC,QAAA;IAAAC;EAAA,SAAAC,QAAA;EACnC,MAAMC,aAAa,GAAGC,IAAI,CAACC,KAAK,CAACP,UAAU,GAAG,CAAC,CAAC;EAChD,MAAMQ,aAAa,GAAGR,UAAU,GAAGK,aAAa;EAChD,IAAII,QAAQ,GAAGH,IAAI,CAACC,KAAK,CAAC,CAACN,WAAW,CAACS,KAAK,GAAGR,QAAQ,CAAC;EACxDO,QAAQ,GAAGA,QAAQ,GAAG,CAAC,GAAIA,QAAQ,GAAGN,KAAK,GAAIA,KAAK,GAAGM,QAAQ;EAC/D,MAAME,aAAa,GAAG,CACpB,CAACF,QAAQ,GAAGD,aAAa,GAAGL,KAAK,IAAIA,KAAK,EAC1C,CAACM,QAAQ,GAAG,CAAC,GAAGN,KAAK,IAAIA,KAAK,CAC/B;EACD,MAAMS,aAAa,GAAG,CACpB,CAACH,QAAQ,GAAGN,KAAK,IAAIA,KAAK,EAC1B,CAACM,QAAQ,GAAGJ,aAAa,GAAGF,KAAK,IAAIA,KAAK,CAC3C;EACD,IAAIQ,aAAa,CAAC,CAAC,CAAC,GAAGR,KAAK,IAAIQ,aAAa,CAAC,CAAC,CAAC,GAAGA,aAAa,CAAC,CAAC,CAAC,EAAE;IACnEA,aAAa,CAAC,CAAC,CAAC,GAAGR,KAAK,GAAG,CAAC;IAC5BS,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;EACtB;EACA,IAAIA,aAAa,CAAC,CAAC,CAAC,GAAGA,aAAa,CAAC,CAAC,CAAC,EAAE;IACvCD,aAAa,CAAC,CAAC,CAAC,GAAGR,KAAK,GAAG,CAAC;IAC5BS,aAAa,CAAC,CAAC,CAAC,GAAG,CAAC;EACtB;EACA,OAAO;IAAED,aAAa,EAAbA,aAAa;IAAEC,aAAA,EAAAA;EAAc,CAAC;AACzC\"}"};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 _e=[new global.Error(),-5,-27];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.__initData=_worklet_1686155145629_init_data;_f.__workletHash=1686155145629;_f.__stackDetails=_e;_f.__version="3.3.0";return _f;}(),[total,windowSize,translation]);return ranges;} //# sourceMappingURL=useVisibleRanges.js.map