react-native-reanimated-carousel 4.0.0-alpha.0 → 4.0.0-alpha.10
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 +22 -162
- package/lib/commonjs/components/BaseLayout.js +95 -0
- package/lib/commonjs/components/BaseLayout.js.map +1 -0
- package/lib/commonjs/components/Carousel.js +210 -0
- package/lib/commonjs/components/Carousel.js.map +1 -0
- package/lib/commonjs/components/ItemRenderer.js +80 -0
- package/lib/commonjs/components/ItemRenderer.js.map +1 -0
- package/lib/commonjs/components/LazyView.js +22 -0
- package/lib/commonjs/components/LazyView.js.map +1 -0
- package/lib/commonjs/components/ScrollViewGesture.js +315 -0
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
- package/lib/commonjs/components/rnr-demo.test.js +45 -0
- package/lib/commonjs/components/rnr-demo.test.js.map +1 -0
- package/lib/commonjs/constants/index.js +21 -1
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +56 -1
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +245 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCheckMounted.js +23 -1
- package/lib/commonjs/hooks/useCheckMounted.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +102 -1
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.test.js +38 -0
- package/lib/commonjs/hooks/useCommonVariables.test.js.map +1 -0
- package/lib/commonjs/hooks/useInitProps.js +78 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +39 -1
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +51 -1
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.test.js +53 -0
- package/lib/commonjs/hooks/useOffsetX.test.js.map +1 -0
- package/lib/commonjs/hooks/useOnProgressChange.js +38 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePanGestureProxy.js +84 -0
- package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
- package/lib/commonjs/hooks/usePanGestureProxy.test.js +397 -0
- package/lib/commonjs/hooks/usePanGestureProxy.test.js.map +1 -0
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +36 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useUpdateGestureConfig.js +20 -0
- package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/commonjs/hooks/useVisibleRanges.js +71 -1
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.test.js +162 -0
- package/lib/commonjs/hooks/useVisibleRanges.test.js.map +1 -0
- package/lib/commonjs/index.js +13 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/index.js +20 -1
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +27 -1
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +38 -1
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +215 -1
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js +14 -1
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/types.js +5 -1
- package/lib/commonjs/utils/compute-offset-if-data-changed.js +52 -0
- package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +1 -0
- package/lib/commonjs/utils/compute-offset-if-data-changed.test.js +30 -0
- package/lib/commonjs/utils/compute-offset-if-data-changed.test.js.map +1 -0
- package/lib/commonjs/utils/compute-offset-if-size-changed.js +18 -0
- package/lib/commonjs/utils/compute-offset-if-size-changed.js.map +1 -0
- package/lib/commonjs/utils/compute-offset-if-size-changed.test.js +72 -0
- package/lib/commonjs/utils/compute-offset-if-size-changed.test.js.map +1 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js +124 -0
- package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/commonjs/utils/deal-with-animation.js +21 -0
- package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
- package/lib/commonjs/utils/handleroffset-direction.js +16 -0
- package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
- package/lib/commonjs/utils/handleroffset-direction.test.js +46 -0
- package/lib/commonjs/utils/handleroffset-direction.test.js.map +1 -0
- package/lib/commonjs/utils/index.test.js +74 -0
- package/lib/commonjs/utils/index.test.js.map +1 -0
- package/lib/commonjs/utils/log.js +22 -1
- package/lib/commonjs/utils/log.js.map +1 -1
- package/lib/module/{layouts → components}/BaseLayout.js +6 -16
- package/lib/module/components/BaseLayout.js.map +1 -0
- package/lib/module/{Carousel.js → components/Carousel.js} +33 -52
- package/lib/module/components/Carousel.js.map +1 -0
- package/lib/module/components/ItemRenderer.js +62 -0
- package/lib/module/components/ItemRenderer.js.map +1 -0
- package/lib/module/{ScrollViewGesture.js → components/ScrollViewGesture.js} +59 -32
- package/lib/module/components/ScrollViewGesture.js.map +1 -0
- package/lib/module/components/rnr-demo.test.js +33 -0
- package/lib/module/components/rnr-demo.test.js.map +1 -0
- package/lib/module/hooks/useCarouselController.js +15 -14
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +39 -9
- package/lib/module/hooks/useCommonVariables.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.test.js +34 -0
- package/lib/module/hooks/useCommonVariables.test.js.map +1 -0
- package/lib/module/hooks/useInitProps.js +1 -3
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/hooks/useLayoutConfig.js.map +1 -1
- package/lib/module/hooks/useOffsetX.js +9 -6
- package/lib/module/hooks/useOffsetX.js.map +1 -1
- package/lib/module/hooks/useOffsetX.test.js +48 -0
- package/lib/module/hooks/useOffsetX.test.js.map +1 -0
- package/lib/module/hooks/useOnProgressChange.js +1 -1
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/hooks/usePanGestureProxy.js +71 -0
- package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
- package/lib/module/hooks/usePanGestureProxy.test.js +383 -0
- package/lib/module/hooks/usePanGestureProxy.test.js.map +1 -0
- package/lib/module/hooks/useUpdateGestureConfig.js +10 -0
- package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
- package/lib/module/hooks/useVisibleRanges.js +47 -19
- package/lib/module/hooks/useVisibleRanges.js.map +1 -1
- package/lib/module/hooks/useVisibleRanges.test.js +157 -0
- package/lib/module/hooks/useVisibleRanges.test.js.map +1 -0
- package/lib/module/index.js +1 -2
- package/lib/module/index.js.map +1 -1
- package/lib/module/{hooks/computeNewIndexWhenDataChanges.js → utils/compute-offset-if-data-changed.js} +2 -2
- package/lib/module/utils/compute-offset-if-data-changed.js.map +1 -0
- package/lib/module/utils/compute-offset-if-data-changed.test.js +27 -0
- package/lib/module/utils/compute-offset-if-data-changed.test.js.map +1 -0
- package/lib/module/utils/compute-offset-if-size-changed.js +11 -0
- package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -0
- package/lib/module/utils/compute-offset-if-size-changed.test.js +69 -0
- package/lib/module/utils/compute-offset-if-size-changed.test.js.map +1 -0
- package/lib/module/utils/{computedWithAutoFillData.js → computed-with-auto-fill-data.js} +1 -1
- package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
- package/lib/module/utils/{dealWithAnimation.js → deal-with-animation.js} +1 -1
- package/lib/module/utils/deal-with-animation.js.map +1 -0
- package/lib/module/utils/handleroffset-direction.js +9 -0
- package/lib/module/utils/handleroffset-direction.js.map +1 -0
- package/lib/module/utils/handleroffset-direction.test.js +41 -0
- package/lib/module/utils/handleroffset-direction.test.js.map +1 -0
- package/lib/module/{hooks → utils}/index.test.js +6 -6
- package/lib/module/utils/index.test.js.map +1 -0
- package/lib/typescript/{Carousel.d.ts → components/Carousel.d.ts} +1 -1
- package/lib/typescript/components/ItemRenderer.d.ts +22 -0
- package/lib/typescript/{ScrollViewGesture.d.ts → components/ScrollViewGesture.d.ts} +1 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +3 -2
- package/lib/typescript/hooks/useCommonVariables.test.d.ts +1 -0
- package/lib/typescript/hooks/useLayoutConfig.d.ts +1 -1
- package/lib/typescript/hooks/useOffsetX.test.d.ts +1 -0
- package/lib/typescript/hooks/usePanGestureProxy.d.ts +9 -0
- package/lib/typescript/hooks/usePanGestureProxy.test.d.ts +1 -0
- package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +5 -0
- package/lib/typescript/hooks/useVisibleRanges.d.ts +8 -4
- package/lib/typescript/hooks/useVisibleRanges.test.d.ts +1 -0
- package/lib/typescript/index.d.ts +3 -2
- package/lib/typescript/types.d.ts +113 -104
- package/lib/typescript/{hooks/computeNewIndexWhenDataChanges.d.ts → utils/compute-offset-if-data-changed.d.ts} +1 -1
- package/lib/typescript/utils/compute-offset-if-data-changed.test.d.ts +1 -0
- package/lib/typescript/utils/compute-offset-if-size-changed.d.ts +5 -0
- package/lib/typescript/utils/compute-offset-if-size-changed.test.d.ts +1 -0
- package/lib/typescript/utils/handleroffset-direction.d.ts +3 -0
- package/lib/typescript/utils/handleroffset-direction.test.d.ts +1 -0
- package/lib/typescript/utils/index.test.d.ts +1 -0
- package/package.json +32 -73
- package/src/{layouts → components}/BaseLayout.tsx +7 -35
- package/src/{Carousel.tsx → components/Carousel.tsx} +35 -69
- package/src/components/ItemRenderer.tsx +105 -0
- package/src/{ScrollViewGesture.tsx → components/ScrollViewGesture.tsx} +88 -48
- package/src/components/rnr-demo.test.tsx +43 -0
- package/src/hooks/useCarouselController.tsx +27 -24
- package/src/hooks/useCommonVariables.test.tsx +41 -0
- package/src/hooks/useCommonVariables.ts +36 -11
- package/src/hooks/useInitProps.ts +1 -3
- package/src/hooks/useLayoutConfig.ts +1 -1
- package/src/hooks/useOffsetX.test.ts +54 -0
- package/src/hooks/useOffsetX.ts +33 -31
- package/src/hooks/useOnProgressChange.ts +1 -1
- package/src/hooks/usePanGestureProxy.test.tsx +376 -0
- package/src/hooks/usePanGestureProxy.ts +110 -0
- package/src/hooks/useUpdateGestureConfig.ts +15 -0
- package/src/hooks/useVisibleRanges.test.tsx +179 -0
- package/src/hooks/useVisibleRanges.tsx +72 -24
- package/src/index.tsx +4 -2
- package/src/types.ts +132 -125
- package/src/utils/compute-offset-if-data-changed.test.ts +30 -0
- package/src/{hooks/computeNewIndexWhenDataChanges.ts → utils/compute-offset-if-data-changed.ts} +1 -1
- package/src/utils/compute-offset-if-size-changed.test.ts +78 -0
- package/src/utils/compute-offset-if-size-changed.ts +11 -0
- package/src/utils/handleroffset-direction.test.ts +52 -0
- package/src/utils/handleroffset-direction.ts +18 -0
- package/src/{hooks → utils}/index.test.ts +6 -6
- package/README.zh-CN.md +0 -202
- package/lib/commonjs/Carousel.js +0 -2
- package/lib/commonjs/Carousel.js.map +0 -1
- package/lib/commonjs/LazyView.js +0 -2
- package/lib/commonjs/LazyView.js.map +0 -1
- package/lib/commonjs/ScrollViewGesture.js +0 -2
- package/lib/commonjs/ScrollViewGesture.js.map +0 -1
- package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js +0 -2
- package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
- package/lib/commonjs/hooks/index.test.js +0 -2
- package/lib/commonjs/hooks/index.test.js.map +0 -1
- package/lib/commonjs/layouts/BaseLayout.js +0 -2
- package/lib/commonjs/layouts/BaseLayout.js.map +0 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +0 -2
- package/lib/commonjs/layouts/ParallaxLayout.js.map +0 -1
- package/lib/commonjs/utils/computedWithAutoFillData.js +0 -2
- package/lib/commonjs/utils/computedWithAutoFillData.js.map +0 -1
- package/lib/commonjs/utils/dealWithAnimation.js +0 -2
- package/lib/commonjs/utils/dealWithAnimation.js.map +0 -1
- package/lib/commonjs/utils/handlerOffsetDirection.js +0 -2
- package/lib/commonjs/utils/handlerOffsetDirection.js.map +0 -1
- package/lib/module/Carousel.js.map +0 -1
- package/lib/module/ScrollViewGesture.js.map +0 -1
- package/lib/module/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
- package/lib/module/hooks/index.test.js.map +0 -1
- package/lib/module/layouts/BaseLayout.js.map +0 -1
- package/lib/module/layouts/ParallaxLayout.js +0 -61
- package/lib/module/layouts/ParallaxLayout.js.map +0 -1
- package/lib/module/utils/computedWithAutoFillData.js.map +0 -1
- package/lib/module/utils/dealWithAnimation.js.map +0 -1
- package/lib/module/utils/handlerOffsetDirection.js +0 -9
- package/lib/module/utils/handlerOffsetDirection.js.map +0 -1
- package/lib/typescript/layouts/ParallaxLayout.d.ts +0 -13
- package/lib/typescript/utils/handlerOffsetDirection.d.ts +0 -2
- package/src/layouts/ParallaxLayout.tsx +0 -141
- package/src/utils/handlerOffsetDirection.ts +0 -15
- /package/lib/module/{LazyView.js → components/LazyView.js} +0 -0
- /package/lib/module/{LazyView.js.map → components/LazyView.js.map} +0 -0
- /package/lib/typescript/{layouts → components}/BaseLayout.d.ts +0 -0
- /package/lib/typescript/{LazyView.d.ts → components/LazyView.d.ts} +0 -0
- /package/lib/typescript/{hooks/index.test.d.ts → components/rnr-demo.test.d.ts} +0 -0
- /package/lib/typescript/utils/{computedWithAutoFillData.d.ts → computed-with-auto-fill-data.d.ts} +0 -0
- /package/lib/typescript/utils/{dealWithAnimation.d.ts → deal-with-animation.d.ts} +0 -0
- /package/src/{LazyView.tsx → components/LazyView.tsx} +0 -0
- /package/src/utils/{computedWithAutoFillData.ts → computed-with-auto-fill-data.ts} +0 -0
- /package/src/utils/{dealWithAnimation.ts → deal-with-animation.ts} +0 -0
|
@@ -1,2 +1,79 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useInitProps = useInitProps;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
|
|
11
|
+
|
|
12
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
|
+
|
|
14
|
+
function useInitProps(props) {
|
|
15
|
+
var _props$enableSnap;
|
|
16
|
+
|
|
17
|
+
const {
|
|
18
|
+
defaultIndex = 0,
|
|
19
|
+
data: rawData = [],
|
|
20
|
+
loop = true,
|
|
21
|
+
autoPlayInterval: _autoPlayInterval = 1000,
|
|
22
|
+
scrollAnimationDuration = 500,
|
|
23
|
+
style = {},
|
|
24
|
+
autoFillData = true,
|
|
25
|
+
// switchers
|
|
26
|
+
enabled = true,
|
|
27
|
+
pagingEnabled = true,
|
|
28
|
+
overscrollEnabled = true,
|
|
29
|
+
snapEnabled = (_props$enableSnap = props.enableSnap) !== null && _props$enableSnap !== void 0 ? _props$enableSnap : true,
|
|
30
|
+
width: _width,
|
|
31
|
+
height: _height
|
|
32
|
+
} = props;
|
|
33
|
+
const width = Math.round(_width || 0);
|
|
34
|
+
const height = Math.round(_height || 0);
|
|
35
|
+
const autoPlayInterval = Math.max(_autoPlayInterval, 0);
|
|
36
|
+
|
|
37
|
+
const data = _react.default.useMemo(() => {
|
|
38
|
+
return (0, _computedWithAutoFillData.computedFillDataWithAutoFillData)({
|
|
39
|
+
loop,
|
|
40
|
+
autoFillData,
|
|
41
|
+
data: rawData,
|
|
42
|
+
dataLength: rawData.length
|
|
43
|
+
});
|
|
44
|
+
}, [rawData, loop, autoFillData]);
|
|
45
|
+
|
|
46
|
+
const dataLength = data.length;
|
|
47
|
+
const rawDataLength = rawData.length;
|
|
48
|
+
|
|
49
|
+
if (props.mode === "vertical-stack" || props.mode === "horizontal-stack") {
|
|
50
|
+
var _props$modeConfig$sho, _props$modeConfig;
|
|
51
|
+
|
|
52
|
+
if (!props.modeConfig) props.modeConfig = {};
|
|
53
|
+
props.modeConfig.showLength = (_props$modeConfig$sho = (_props$modeConfig = props.modeConfig) === null || _props$modeConfig === void 0 ? void 0 : _props$modeConfig.showLength) !== null && _props$modeConfig$sho !== void 0 ? _props$modeConfig$sho : dataLength - 1;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return { ...props,
|
|
57
|
+
defaultIndex,
|
|
58
|
+
autoFillData,
|
|
59
|
+
// Fill data with autoFillData
|
|
60
|
+
data,
|
|
61
|
+
// Length of fill data
|
|
62
|
+
dataLength,
|
|
63
|
+
// Raw data that has not been processed
|
|
64
|
+
rawData,
|
|
65
|
+
// Length of raw data
|
|
66
|
+
rawDataLength,
|
|
67
|
+
loop,
|
|
68
|
+
enabled,
|
|
69
|
+
autoPlayInterval,
|
|
70
|
+
scrollAnimationDuration,
|
|
71
|
+
style,
|
|
72
|
+
pagingEnabled,
|
|
73
|
+
snapEnabled,
|
|
74
|
+
overscrollEnabled,
|
|
75
|
+
width,
|
|
76
|
+
height
|
|
77
|
+
};
|
|
78
|
+
}
|
|
2
79
|
//# sourceMappingURL=useInitProps.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useInitProps.ts"],"names":["useInitProps","props","defaultIndex","data","rawData","loop","autoPlayInterval","_autoPlayInterval","scrollAnimationDuration","style","
|
|
1
|
+
{"version":3,"sources":["useInitProps.ts"],"names":["useInitProps","props","defaultIndex","data","rawData","loop","autoPlayInterval","_autoPlayInterval","scrollAnimationDuration","style","autoFillData","enabled","pagingEnabled","overscrollEnabled","snapEnabled","enableSnap","width","_width","height","_height","Math","round","max","React","useMemo","dataLength","length","rawDataLength","mode","modeConfig","showLength"],"mappings":";;;;;;;AAAA;;AAGA;;;;AAuBO,SAASA,YAAT,CACLC,KADK,EAEwB;AAAA;;A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BAAtD,EAA0E;AAAA;;AACxE,QAAI,CAAC3B,KAAK,CAAC4B,UAAX,EACE5B,KAAK,CAAC4B,UAAN,GAAmB,EAAnB;AAEF5B,IAAAA,KAAK,CAAC4B,UAAN,CAAiBC,UAAjB,iDAA8B7B,KAAK,CAAC4B,UAApC,sDAA8B,kBAAkBC,UAAhD,yEAA8DL,UAAU,GAAG,CAA3E;AACD;;AAED,SAAO,EACL,GAAGxB,KADE;AAELC,IAAAA,YAFK;AAGLQ,IAAAA,YAHK;AAIL;AACAP,IAAAA,IALK;AAML;AACAsB,IAAAA,UAPK;AAQL;AACArB,IAAAA,OATK;AAUL;AACAuB,IAAAA,aAXK;AAYLtB,IAAAA,IAZK;AAaLM,IAAAA,OAbK;AAcLL,IAAAA,gBAdK;AAeLE,IAAAA,uBAfK;AAgBLC,IAAAA,KAhBK;AAiBLG,IAAAA,aAjBK;AAkBLE,IAAAA,WAlBK;AAmBLD,IAAAA,iBAnBK;AAoBLG,IAAAA,KApBK;AAqBLE,IAAAA;AArBK,GAAP;AAuBD","sourcesContent":["import React from \"react\";\n\nimport type { TCarouselProps } from \"../types\";\nimport { computedFillDataWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\ntype TGetRequiredProps<P extends keyof TCarouselProps> = Record<\nP,\nRequired<TCarouselProps>[P]\n>;\n\nexport type TInitializeCarouselProps<T> = TCarouselProps<T> &\nTGetRequiredProps<\n| \"defaultIndex\"\n| \"loop\"\n| \"width\"\n| \"height\"\n| \"scrollAnimationDuration\"\n| \"autoPlayInterval\"\n| \"autoFillData\"\n> & {\n // Raw data that has not been processed\n rawData: T[]\n dataLength: number\n rawDataLength: number\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 autoFillData = true,\n // switchers\n enabled = true,\n pagingEnabled = true,\n overscrollEnabled = true,\n snapEnabled = props.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 () => {\n return computedFillDataWithAutoFillData<T>({\n loop,\n autoFillData,\n data: rawData,\n dataLength: rawData.length,\n });\n },\n [rawData, loop, autoFillData],\n );\n\n const dataLength = data.length;\n const rawDataLength = rawData.length;\n\n if (props.mode === \"vertical-stack\" || props.mode === \"horizontal-stack\") {\n if (!props.modeConfig)\n props.modeConfig = {};\n\n props.modeConfig.showLength = props.modeConfig?.showLength ?? dataLength - 1;\n }\n\n return {\n ...props,\n defaultIndex,\n autoFillData,\n // Fill data with autoFillData\n data,\n // Length of fill data\n dataLength,\n // Raw data that has not been processed\n rawData,\n // Length of raw data\n rawDataLength,\n loop,\n enabled,\n autoPlayInterval,\n scrollAnimationDuration,\n style,\n pagingEnabled,\n snapEnabled,\n overscrollEnabled,\n width,\n height,\n };\n}\n"]}
|
|
@@ -1,2 +1,40 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
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
|
+
}
|
|
2
40
|
//# 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":";;;;;;;AAAA;;AAKA;;;;AAIO,SAASA,eAAT,CACLC,IADK,EAEY;AACjB,QAAM;AAAEC,IAAAA,IAAF;AAAQC,IAAAA;AAAR,MAAqBF,IAA3B;AAEA,SAAOG,eAAMC,OAAN,CAAc,MAAM;AACzB,UAAMC,UAAU,GAAG;AAAEJ,MAAAA,IAAF;AAAQC,MAAAA;AAAR,KAAnB;;AACA,YAAQF,IAAI,CAACM,IAAb;AACE,WAAK,UAAL;AACE,eAAOC,iBAAQC,QAAR,CAAiBH,UAAjB,EAA6BL,IAAI,CAACS,UAAlC,CAAP;;AACF,WAAK,kBAAL;AACE,eAAOF,iBAAQG,eAAR,CAAwBV,IAAI,CAACS,UAA7B,CAAP;;AACF,WAAK,gBAAL;AACE,eAAOF,iBAAQI,aAAR,CAAsBX,IAAI,CAACS,UAA3B,CAAP;;AACF;AACE,eAAOF,iBAAQK,MAAR,CAAeP,UAAf,CAAP;AARJ;AAUD,GAZM,EAYJ,CAACL,IAAI,CAACM,IAAN,EAAYN,IAAI,CAACS,UAAjB,EAA6BR,IAA7B,EAAmCC,QAAnC,CAZI,CAAP;AAaD","sourcesContent":["import React from \"react\";\n\nimport type { TInitializeCarouselProps } from \"./useInitProps\";\n\nimport type { TAnimationStyle } from \"../components/BaseLayout\";\nimport { Layouts } from \"../layouts\";\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,2 +1,52 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
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
|
+
handlerOffset,
|
|
13
|
+
index,
|
|
14
|
+
size,
|
|
15
|
+
loop,
|
|
16
|
+
dataLength,
|
|
17
|
+
type = "positive",
|
|
18
|
+
viewCount: _viewCount
|
|
19
|
+
} = opts;
|
|
20
|
+
const ITEM_LENGTH = dataLength;
|
|
21
|
+
const VALID_LENGTH = ITEM_LENGTH - 1;
|
|
22
|
+
const TOTAL_WIDTH = size * ITEM_LENGTH;
|
|
23
|
+
const HALF_WIDTH = 0.5 * size;
|
|
24
|
+
const viewCount = _viewCount !== null && _viewCount !== void 0 ? _viewCount : Math.round((ITEM_LENGTH - 1) / 2);
|
|
25
|
+
const positiveCount = type === "positive" ? viewCount : VALID_LENGTH - viewCount;
|
|
26
|
+
let startPos = size * index;
|
|
27
|
+
if (index > positiveCount) startPos = (index - ITEM_LENGTH) * size;
|
|
28
|
+
const MAX = positiveCount * size;
|
|
29
|
+
const MIN = -((VALID_LENGTH - positiveCount) * size);
|
|
30
|
+
const x = (0, _reactNativeReanimated.useDerivedValue)(() => {
|
|
31
|
+
const {
|
|
32
|
+
negativeRange,
|
|
33
|
+
positiveRange
|
|
34
|
+
} = visibleRanges.value;
|
|
35
|
+
|
|
36
|
+
if (index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1]) {
|
|
37
|
+
if (loop) {
|
|
38
|
+
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];
|
|
39
|
+
const outputRange = [startPos, MAX + HALF_WIDTH - Number.MIN_VALUE, MIN - HALF_WIDTH, startPos, MAX + HALF_WIDTH, MIN - HALF_WIDTH + Number.MIN_VALUE, startPos];
|
|
40
|
+
return (0, _reactNativeReanimated.interpolate)(handlerOffset.value, inputRange, outputRange, _reactNativeReanimated.Extrapolate.CLAMP);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return handlerOffset.value + size * index;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
return Number.MAX_SAFE_INTEGER;
|
|
47
|
+
}, [loop, dataLength, viewCount, type, size, visibleRanges]);
|
|
48
|
+
return x;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.useOffsetX = useOffsetX;
|
|
2
52
|
//# sourceMappingURL=useOffsetX.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOffsetX.ts"],"names":["useOffsetX","opts","visibleRanges","handlerOffset","index","size","loop","dataLength","type","
|
|
1
|
+
{"version":3,"sources":["useOffsetX.ts"],"names":["useOffsetX","opts","visibleRanges","handlerOffset","index","size","loop","dataLength","type","viewCount","_viewCount","ITEM_LENGTH","VALID_LENGTH","TOTAL_WIDTH","HALF_WIDTH","Math","round","positiveCount","startPos","MAX","MIN","x","negativeRange","positiveRange","value","inputRange","Number","MIN_VALUE","outputRange","Extrapolate","CLAMP","MAX_SAFE_INTEGER"],"mappings":";;;;;;;AACA;;AAkBO,MAAMA,UAAU,GAAG,CAACC,IAAD,EAAcC,aAAd,KAAgD;AACxE,QAAM;AACJC,IAAAA,aADI;AAEJC,IAAAA,KAFI;AAGJC,IAAAA,IAHI;AAIJC,IAAAA,IAJI;AAKJC,IAAAA,UALI;AAMJC,IAAAA,IAAI,GAAG,UANH;AAOJC,IAAAA,SAAS,EAAEC;AAPP,MAQFT,IARJ;AAUA,QAAMU,WAAW,GAAGJ,UAApB;AACA,QAAMK,YAAY,GAAGD,WAAW,GAAG,CAAnC;AACA,QAAME,WAAW,GAAGR,IAAI,GAAGM,WAA3B;AACA,QAAMG,UAAU,GAAG,MAAMT,IAAzB;AAEA,QAAMI,SAAS,GAAGC,UAAH,aAAGA,UAAH,cAAGA,UAAH,GAAiBK,IAAI,CAACC,KAAL,CAAW,CAACL,WAAW,GAAG,CAAf,IAAoB,CAA/B,CAAhC;AACA,QAAMM,aAAa,GACfT,IAAI,KAAK,UAAT,GAAsBC,SAAtB,GAAkCG,YAAY,GAAGH,SADrD;AAGA,MAAIS,QAAQ,GAAGb,IAAI,GAAGD,KAAtB;AACA,MAAIA,KAAK,GAAGa,aAAZ,EACEC,QAAQ,GAAG,CAACd,KAAK,GAAGO,WAAT,IAAwBN,IAAnC;AAEF,QAAMc,GAAG,GAAGF,aAAa,GAAG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,EAAmBE,SAAnB,EAA8BD,IAA9B,EAAoCH,IAApC,EAA0CH,aAA1C,CAxCO,CAAV;AA0CA,SAAOmB,CAAP;AACD,CAtEM","sourcesContent":["import type Animated from \"react-native-reanimated\";\nimport {\n Extrapolate,\n interpolate,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { IVisibleRanges } from \"./useVisibleRanges\";\n\nexport interface IOpts {\n index: number\n size: number\n handlerOffset: Animated.SharedValue<number>\n dataLength: number\n type?: \"positive\" | \"negative\"\n viewCount?: number\n loop?: boolean\n}\n\nexport const useOffsetX = (opts: IOpts, visibleRanges: IVisibleRanges) => {\n const {\n handlerOffset,\n index,\n size,\n loop,\n dataLength,\n type = \"positive\",\n viewCount: _viewCount,\n } = opts;\n\n const ITEM_LENGTH = dataLength;\n const VALID_LENGTH = ITEM_LENGTH - 1;\n const TOTAL_WIDTH = size * ITEM_LENGTH;\n const HALF_WIDTH = 0.5 * size;\n\n const viewCount = _viewCount ?? Math.round((ITEM_LENGTH - 1) / 2);\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 const MAX = positiveCount * size;\n const MIN = -((VALID_LENGTH - positiveCount) * size);\n\n const x = useDerivedValue(() => {\n const { negativeRange, positiveRange } = visibleRanges.value;\n\n if (\n (index >= negativeRange[0] && index <= negativeRange[1])\n || (index >= positiveRange[0] && index <= positiveRange[1])\n ) {\n if (loop) {\n const inputRange = [\n -TOTAL_WIDTH,\n MIN - HALF_WIDTH - startPos - Number.MIN_VALUE,\n MIN - HALF_WIDTH - startPos,\n 0,\n MAX + HALF_WIDTH - startPos,\n MAX + HALF_WIDTH - startPos + Number.MIN_VALUE,\n TOTAL_WIDTH,\n ];\n\n const outputRange = [\n startPos,\n MAX + HALF_WIDTH - Number.MIN_VALUE,\n MIN - HALF_WIDTH,\n startPos,\n MAX + HALF_WIDTH,\n MIN - HALF_WIDTH + Number.MIN_VALUE,\n startPos,\n ];\n\n return interpolate(\n handlerOffset.value,\n inputRange,\n outputRange,\n Extrapolate.CLAMP,\n );\n }\n\n return handlerOffset.value + size * index;\n }\n\n return Number.MAX_SAFE_INTEGER;\n }, [loop, dataLength, viewCount, type, size, visibleRanges]);\n\n return x;\n};\n"]}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
4
|
+
|
|
5
|
+
var _reactHooks = require("@testing-library/react-hooks");
|
|
6
|
+
|
|
7
|
+
var _useOffsetX = require("./useOffsetX");
|
|
8
|
+
|
|
9
|
+
describe("useSharedValue", () => {
|
|
10
|
+
it("should return the correct values", async () => {
|
|
11
|
+
const hook = (0, _reactHooks.renderHook)(() => {
|
|
12
|
+
const range = (0, _reactNativeReanimated.useSharedValue)({
|
|
13
|
+
negativeRange: [7, 9],
|
|
14
|
+
positiveRange: [0, 3]
|
|
15
|
+
});
|
|
16
|
+
const inputs = Array.from({
|
|
17
|
+
length: 10
|
|
18
|
+
}).map((_, index) => ({
|
|
19
|
+
config: {
|
|
20
|
+
dataLength: 10,
|
|
21
|
+
handlerOffset: (0, _reactNativeReanimated.useSharedValue)(-0),
|
|
22
|
+
index,
|
|
23
|
+
loop: false,
|
|
24
|
+
size: 393
|
|
25
|
+
},
|
|
26
|
+
range
|
|
27
|
+
}));
|
|
28
|
+
return inputs.map(input => {
|
|
29
|
+
const {
|
|
30
|
+
config,
|
|
31
|
+
range
|
|
32
|
+
} = input;
|
|
33
|
+
return (0, _useOffsetX.useOffsetX)(config, range);
|
|
34
|
+
});
|
|
35
|
+
});
|
|
36
|
+
const expected = hook.result.current.map(v => v.value).slice();
|
|
37
|
+
expect(expected).toMatchInlineSnapshot(`
|
|
38
|
+
[
|
|
39
|
+
0,
|
|
40
|
+
393,
|
|
41
|
+
786,
|
|
42
|
+
1179,
|
|
43
|
+
9007199254740991,
|
|
44
|
+
9007199254740991,
|
|
45
|
+
9007199254740991,
|
|
46
|
+
2751,
|
|
47
|
+
3144,
|
|
48
|
+
3537,
|
|
49
|
+
]
|
|
50
|
+
`);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
//# sourceMappingURL=useOffsetX.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useOffsetX.test.ts"],"names":["describe","it","hook","range","negativeRange","positiveRange","inputs","Array","from","length","map","_","index","config","dataLength","handlerOffset","loop","size","input","expected","result","current","v","value","slice","expect","toMatchInlineSnapshot"],"mappings":";;AAAA;;AAEA;;AAGA;;AAGAA,QAAQ,CAAC,gBAAD,EAAmB,MAAM;AAC/BC,EAAAA,EAAE,CAAC,kCAAD,EAAqC,YAAY;AACjD,UAAMC,IAAI,GAAG,4BAAW,MAAM;AAC5B,YAAMC,KAAK,GAAG,2CAAe;AAC3BC,QAAAA,aAAa,EAAE,CAAC,CAAD,EAAI,CAAJ,CADY;AAE3BC,QAAAA,aAAa,EAAE,CAAC,CAAD,EAAI,CAAJ;AAFY,OAAf,CAAd;AAIA,YAAMC,MAGJ,GAAGC,KAAK,CAACC,IAAN,CAAW;AAAEC,QAAAA,MAAM,EAAE;AAAV,OAAX,EAA2BC,GAA3B,CAA+B,CAACC,CAAD,EAAIC,KAAJ,MAAe;AACjDC,QAAAA,MAAM,EAAE;AACNC,UAAAA,UAAU,EAAE,EADN;AAENC,UAAAA,aAAa,EAAE,2CAAe,CAAC,CAAhB,CAFT;AAGNH,UAAAA,KAHM;AAINI,UAAAA,IAAI,EAAE,KAJA;AAKNC,UAAAA,IAAI,EAAE;AALA,SADyC;AAQjDd,QAAAA;AARiD,OAAf,CAA/B,CAHL;AAcA,aAAOG,MAAM,CAACI,GAAP,CAAYQ,KAAD,IAAW;AAC3B,cAAM;AAAEL,UAAAA,MAAF;AAAUV,UAAAA;AAAV,YAAoBe,KAA1B;AAEA,eAAO,4BAAWL,MAAX,EAAmBV,KAAnB,CAAP;AACD,OAJM,CAAP;AAKD,KAxBY,CAAb;AA0BA,UAAMgB,QAAQ,GAAGjB,IAAI,CAACkB,MAAL,CAAYC,OAAZ,CAAoBX,GAApB,CAAwBY,CAAC,IAAIA,CAAC,CAACC,KAA/B,EAAsCC,KAAtC,EAAjB;AAEAC,IAAAA,MAAM,CAACN,QAAD,CAAN,CAAiBO,qBAAjB,CAAwC;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAbI;AAcD,GA3CC,CAAF;AA4CD,CA7CO,CAAR","sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\n\nimport { renderHook } from \"@testing-library/react-hooks\";\n\nimport type { IOpts } from \"./useOffsetX\";\nimport { useOffsetX } from \"./useOffsetX\";\nimport type { IVisibleRanges } from \"./useVisibleRanges\";\n\ndescribe(\"useSharedValue\", () => {\n it(\"should return the correct values\", async () => {\n const hook = renderHook(() => {\n const range = useSharedValue({\n negativeRange: [7, 9],\n positiveRange: [0, 3],\n }) as IVisibleRanges;\n const inputs: Array<{\n config: IOpts\n range: IVisibleRanges\n }> = Array.from({ length: 10 }).map((_, index) => ({\n config: {\n dataLength: 10,\n handlerOffset: useSharedValue(-0),\n index,\n loop: false,\n size: 393,\n },\n range,\n }));\n\n return inputs.map((input) => {\n const { config, range } = input;\n\n return useOffsetX(config, range);\n });\n });\n\n const expected = hook.result.current.map(v => v.value).slice();\n\n expect(expected).toMatchInlineSnapshot(`\n [\n 0,\n 393,\n 786,\n 1179,\n 9007199254740991,\n 9007199254740991,\n 9007199254740991,\n 2751,\n 3144,\n 3537,\n ]\n `);\n });\n});\n"]}
|
|
@@ -1,2 +1,39 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
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 _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
|
|
11
|
+
|
|
12
|
+
function useOnProgressChange(opts) {
|
|
13
|
+
const {
|
|
14
|
+
autoFillData,
|
|
15
|
+
loop,
|
|
16
|
+
offsetX,
|
|
17
|
+
size,
|
|
18
|
+
rawDataLength,
|
|
19
|
+
onProgressChange
|
|
20
|
+
} = opts;
|
|
21
|
+
(0, _reactNativeReanimated.useAnimatedReaction)(() => offsetX.value, _value => {
|
|
22
|
+
let value = (0, _computedWithAutoFillData.computedOffsetXValueWithAutoFillData)({
|
|
23
|
+
value: _value,
|
|
24
|
+
rawDataLength,
|
|
25
|
+
size,
|
|
26
|
+
autoFillData,
|
|
27
|
+
loop
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
if (!loop) {
|
|
31
|
+
value = Math.max(-((rawDataLength - 1) * size), Math.min(value, 0));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let absoluteProgress = Math.abs(value / size);
|
|
35
|
+
if (value > 0) absoluteProgress = rawDataLength - absoluteProgress;
|
|
36
|
+
if (onProgressChange) (0, _reactNativeReanimated.runOnJS)(onProgressChange)(value, absoluteProgress);
|
|
37
|
+
}, [loop, autoFillData, rawDataLength, onProgressChange]);
|
|
38
|
+
}
|
|
2
39
|
//# sourceMappingURL=useOnProgressChange.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useOnProgressChange.ts"],"names":["useOnProgressChange","opts","autoFillData","loop","offsetX","size","rawDataLength","onProgressChange","value","_value","Math","max","min","absoluteProgress","abs"
|
|
1
|
+
{"version":3,"sources":["useOnProgressChange.ts"],"names":["useOnProgressChange","opts","autoFillData","loop","offsetX","size","rawDataLength","onProgressChange","value","_value","Math","max","min","absoluteProgress","abs"],"mappings":";;;;;;;AACA;;AAMA;;AAEO,SAASA,mBAAT,CACLC,IADK,EAQL;AACA,QAAM;AAAEC,IAAAA,YAAF;AAAgBC,IAAAA,IAAhB;AAAsBC,IAAAA,OAAtB;AAA+BC,IAAAA,IAA/B;AAAqCC,IAAAA,aAArC;AAAoDC,IAAAA;AAApD,MACEN,IADR;AAGA,kDACE,MAAMG,OAAO,CAACI,KADhB,EAEGC,MAAD,IAAY;AACV,QAAID,KAAK,GAAG,oEAAqC;AAC/CA,MAAAA,KAAK,EAAEC,MADwC;AAE/CH,MAAAA,aAF+C;AAG/CD,MAAAA,IAH+C;AAI/CH,MAAAA,YAJ+C;AAK/CC,MAAAA;AAL+C,KAArC,CAAZ;;AAQA,QAAI,CAACA,IAAL,EAAW;AACTK,MAAAA,KAAK,GAAGE,IAAI,CAACC,GAAL,CACN,EAAE,CAACL,aAAa,GAAG,CAAjB,IAAsBD,IAAxB,CADM,EAENK,IAAI,CAACE,GAAL,CAASJ,KAAT,EAAgB,CAAhB,CAFM,CAAR;AAID;;AAED,QAAIK,gBAAgB,GAAGH,IAAI,CAACI,GAAL,CAASN,KAAK,GAAGH,IAAjB,CAAvB;AAEA,QAAIG,KAAK,GAAG,CAAZ,EACEK,gBAAgB,GAAGP,aAAa,GAAGO,gBAAnC;AAEF,QAAIN,gBAAJ,EACE,oCAAQA,gBAAR,EAA0BC,KAA1B,EAAiCK,gBAAjC;AACH,GAzBH,EA0BE,CAACV,IAAD,EAAOD,YAAP,EAAqBI,aAArB,EAAoCC,gBAApC,CA1BF;AA4BD","sourcesContent":["import type Animated from \"react-native-reanimated\";\nimport {\n runOnJS,\n useAnimatedReaction,\n} from \"react-native-reanimated\";\n\nimport type { TCarouselProps } from \"../types\";\nimport { computedOffsetXValueWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\nexport function useOnProgressChange(\n opts: {\n size: number\n autoFillData: boolean\n loop: boolean\n offsetX: Animated.SharedValue<number>\n rawDataLength: number\n } & Pick<TCarouselProps, \"onProgressChange\">,\n) {\n const { autoFillData, loop, offsetX, size, rawDataLength, onProgressChange }\n = opts;\n\n useAnimatedReaction(\n () => offsetX.value,\n (_value) => {\n let value = computedOffsetXValueWithAutoFillData({\n value: _value,\n rawDataLength,\n size,\n autoFillData,\n loop,\n });\n\n if (!loop) {\n value = Math.max(\n -((rawDataLength - 1) * size),\n Math.min(value, 0),\n );\n }\n\n let absoluteProgress = Math.abs(value / size);\n\n if (value > 0)\n absoluteProgress = rawDataLength - absoluteProgress;\n\n if (onProgressChange)\n runOnJS(onProgressChange)(value, absoluteProgress);\n },\n [loop, autoFillData, rawDataLength, onProgressChange],\n );\n}\n"]}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.usePanGestureProxy = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = require("react");
|
|
9
|
+
|
|
10
|
+
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
11
|
+
|
|
12
|
+
var _useUpdateGestureConfig = require("./useUpdateGestureConfig");
|
|
13
|
+
|
|
14
|
+
const usePanGestureProxy = customization => {
|
|
15
|
+
const {
|
|
16
|
+
onConfigurePanGesture,
|
|
17
|
+
onGestureStart,
|
|
18
|
+
onGestureUpdate,
|
|
19
|
+
onGestureEnd,
|
|
20
|
+
options = {}
|
|
21
|
+
} = customization;
|
|
22
|
+
const gesture = (0, _react.useMemo)(() => {
|
|
23
|
+
const gesture = _reactNativeGestureHandler.Gesture.Pan(); // Save the original gesture callbacks
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
const originalGestures = {
|
|
27
|
+
onStart: gesture.onStart,
|
|
28
|
+
onUpdate: gesture.onUpdate,
|
|
29
|
+
onEnd: gesture.onEnd
|
|
30
|
+
}; // Save the user defined gesture callbacks
|
|
31
|
+
|
|
32
|
+
const userDefinedConflictGestures = {
|
|
33
|
+
onStart: undefined,
|
|
34
|
+
onUpdate: undefined,
|
|
35
|
+
onEnd: undefined
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const fakeOnStart = cb => {
|
|
39
|
+
// Using fakeOnStart to save the user defined callback
|
|
40
|
+
userDefinedConflictGestures.onStart = cb;
|
|
41
|
+
return gesture;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const fakeOnUpdate = cb => {
|
|
45
|
+
// Using fakeOnUpdate to save the user defined callback
|
|
46
|
+
userDefinedConflictGestures.onUpdate = cb;
|
|
47
|
+
return gesture;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const fakeOnEnd = cb => {
|
|
51
|
+
// Using fakeOnEnd to save the user defined callback
|
|
52
|
+
userDefinedConflictGestures.onEnd = cb;
|
|
53
|
+
return gesture;
|
|
54
|
+
}; // Setup the fake callbacks
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
gesture.onStart = fakeOnStart;
|
|
58
|
+
gesture.onUpdate = fakeOnUpdate;
|
|
59
|
+
gesture.onEnd = fakeOnEnd;
|
|
60
|
+
if (onConfigurePanGesture) // Get the gesture with the user defined configuration
|
|
61
|
+
onConfigurePanGesture(gesture); // Restore the original callbacks
|
|
62
|
+
|
|
63
|
+
gesture.onStart = originalGestures.onStart;
|
|
64
|
+
gesture.onUpdate = originalGestures.onUpdate;
|
|
65
|
+
gesture.onEnd = originalGestures.onEnd; // Setup the original callbacks with the user defined callbacks
|
|
66
|
+
|
|
67
|
+
gesture.onStart(e => {
|
|
68
|
+
onGestureStart(e);
|
|
69
|
+
if (userDefinedConflictGestures.onStart) userDefinedConflictGestures.onStart(e);
|
|
70
|
+
}).onUpdate(e => {
|
|
71
|
+
onGestureUpdate(e);
|
|
72
|
+
if (userDefinedConflictGestures.onUpdate) userDefinedConflictGestures.onUpdate(e);
|
|
73
|
+
}).onEnd((e, success) => {
|
|
74
|
+
onGestureEnd(e, success);
|
|
75
|
+
if (userDefinedConflictGestures.onEnd) userDefinedConflictGestures.onEnd(e, success);
|
|
76
|
+
});
|
|
77
|
+
return gesture;
|
|
78
|
+
}, [onGestureStart, onGestureUpdate, onGestureEnd, onConfigurePanGesture]);
|
|
79
|
+
(0, _useUpdateGestureConfig.useUpdateGestureConfig)(gesture, options);
|
|
80
|
+
return gesture;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
exports.usePanGestureProxy = usePanGestureProxy;
|
|
84
|
+
//# sourceMappingURL=usePanGestureProxy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["usePanGestureProxy.ts"],"names":["usePanGestureProxy","customization","onConfigurePanGesture","onGestureStart","onGestureUpdate","onGestureEnd","options","gesture","Gesture","Pan","originalGestures","onStart","onUpdate","onEnd","userDefinedConflictGestures","undefined","fakeOnStart","cb","fakeOnUpdate","fakeOnEnd","e","success"],"mappings":";;;;;;;AAAA;;AAEA;;AAGA;;AAEO,MAAMA,kBAAkB,GAC7BC,aADgC,IAQ7B;AACH,QAAM;AACJC,IAAAA,qBADI;AAEJC,IAAAA,cAFI;AAGJC,IAAAA,eAHI;AAIJC,IAAAA,YAJI;AAKJC,IAAAA,OAAO,GAAG;AALN,MAMFL,aANJ;AAQA,QAAMM,OAAO,GAAG,oBAAQ,MAAM;AAC5B,UAAMA,OAAO,GAAGC,mCAAQC,GAAR,EAAhB,CAD4B,CAG5B;;;AACA,UAAMC,gBAAgB,GAAG;AACvBC,MAAAA,OAAO,EAAEJ,OAAO,CAACI,OADM;AAEvBC,MAAAA,QAAQ,EAAEL,OAAO,CAACK,QAFK;AAGvBC,MAAAA,KAAK,EAAEN,OAAO,CAACM;AAHQ,KAAzB,CAJ4B,CAU5B;;AACA,UAAMC,2BAIL,GAAG;AACFH,MAAAA,OAAO,EAAEI,SADP;AAEFH,MAAAA,QAAQ,EAAEG,SAFR;AAGFF,MAAAA,KAAK,EAAEE;AAHL,KAJJ;;AAUA,UAAMC,WAAmC,GAAIC,EAAD,IAAQ;AAClD;AACAH,MAAAA,2BAA2B,CAACH,OAA5B,GAAsCM,EAAtC;AACA,aAAOV,OAAP;AACD,KAJD;;AAM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C;AACH,KAlBH;AAoBA,WAAOd,OAAP;AACD,GA3Ee,EA2Eb,CACDJ,cADC,EAEDC,eAFC,EAGDC,YAHC,EAIDH,qBAJC,CA3Ea,CAAhB;AAkFA,sDAAuBK,OAAvB,EAAgCD,OAAhC;AAEA,SAAOC,OAAP;AACD,CAtGM","sourcesContent":["import { useMemo } from \"react\";\nimport type { GestureStateChangeEvent, GestureUpdateEvent, PanGesture, PanGestureHandlerEventPayload } from \"react-native-gesture-handler\";\nimport { Gesture } from \"react-native-gesture-handler\";\n\nimport type { GestureConfig } from \"./useUpdateGestureConfig\";\nimport { useUpdateGestureConfig } from \"./useUpdateGestureConfig\";\n\nexport const usePanGestureProxy = (\n customization: {\n onConfigurePanGesture?: (gesture: PanGesture) => void\n onGestureStart: (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => void\n onGestureUpdate: (event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => void\n onGestureEnd: (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>, success: boolean) => void\n options?: GestureConfig\n },\n) => {\n const {\n onConfigurePanGesture,\n onGestureStart,\n onGestureUpdate,\n onGestureEnd,\n options = {},\n } = customization;\n\n const gesture = useMemo(() => {\n const gesture = Gesture.Pan();\n\n // Save the original gesture callbacks\n const originalGestures = {\n onStart: gesture.onStart,\n onUpdate: gesture.onUpdate,\n onEnd: gesture.onEnd,\n };\n\n // Save the user defined gesture callbacks\n const userDefinedConflictGestures: {\n onStart?: Parameters<(typeof gesture)[\"onStart\"]>[0]\n onUpdate?: Parameters<(typeof gesture)[\"onUpdate\"]>[0]\n onEnd?: Parameters<(typeof gesture)[\"onEnd\"]>[0]\n } = {\n onStart: undefined,\n onUpdate: undefined,\n onEnd: undefined,\n };\n\n const fakeOnStart: typeof gesture.onStart = (cb) => {\n // Using fakeOnStart to save the user defined callback\n userDefinedConflictGestures.onStart = cb;\n return gesture;\n };\n\n const fakeOnUpdate: typeof gesture.onUpdate = (cb) => {\n // Using fakeOnUpdate to save the user defined callback\n userDefinedConflictGestures.onUpdate = cb;\n return gesture;\n };\n\n const fakeOnEnd: typeof gesture.onEnd = (cb) => {\n // Using fakeOnEnd to save the user defined callback\n userDefinedConflictGestures.onEnd = cb;\n return gesture;\n };\n\n // Setup the fake callbacks\n gesture.onStart = fakeOnStart;\n gesture.onUpdate = fakeOnUpdate;\n gesture.onEnd = fakeOnEnd;\n\n if (onConfigurePanGesture)\n // Get the gesture with the user defined configuration\n onConfigurePanGesture(gesture);\n\n // Restore the original callbacks\n gesture.onStart = originalGestures.onStart;\n gesture.onUpdate = originalGestures.onUpdate;\n gesture.onEnd = originalGestures.onEnd;\n\n // Setup the original callbacks with the user defined callbacks\n gesture\n .onStart((e) => {\n onGestureStart(e);\n\n if (userDefinedConflictGestures.onStart)\n userDefinedConflictGestures.onStart(e);\n })\n .onUpdate((e) => {\n onGestureUpdate(e);\n\n if (userDefinedConflictGestures.onUpdate)\n userDefinedConflictGestures.onUpdate(e);\n })\n .onEnd((e, success) => {\n onGestureEnd(e, success);\n\n if (userDefinedConflictGestures.onEnd)\n userDefinedConflictGestures.onEnd(e, success);\n });\n\n return gesture;\n }, [\n onGestureStart,\n onGestureUpdate,\n onGestureEnd,\n onConfigurePanGesture,\n ]);\n\n useUpdateGestureConfig(gesture, options);\n\n return gesture;\n};\n"]}
|