react-native-reanimated-carousel 4.0.0-alpha.1 → 4.0.0-alpha.11
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 +2 -3
- package/lib/commonjs/{layouts → components}/BaseLayout.js +5 -21
- package/lib/commonjs/components/BaseLayout.js.map +1 -0
- package/lib/commonjs/components/Carousel.js +28 -48
- package/lib/commonjs/components/Carousel.js.map +1 -1
- package/lib/commonjs/components/ItemRenderer.js +80 -0
- package/lib/commonjs/components/ItemRenderer.js.map +1 -0
- package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +81 -0
- package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +1 -0
- package/lib/commonjs/components/Pagination/Basic/index.js +57 -0
- package/lib/commonjs/components/Pagination/Basic/index.js.map +1 -0
- package/lib/commonjs/components/Pagination/index.js +14 -0
- package/lib/commonjs/components/Pagination/index.js.map +1 -0
- package/lib/commonjs/components/ScrollViewGesture.js +51 -33
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/components/rnr-demo.test.js +45 -0
- package/lib/commonjs/components/rnr-demo.test.js.map +1 -0
- package/lib/commonjs/hooks/useCarouselController.js +12 -11
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +38 -12
- 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/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +9 -6
- 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 +4 -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/useUpdateGestureConfig.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js +48 -19
- 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 +8 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/{computeNewIndexWhenDataChanges.js → compute-offset-if-data-changed.js} +3 -3
- 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/handleroffset-direction.js +5 -5
- package/lib/commonjs/utils/handleroffset-direction.js.map +1 -1
- 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 +6 -6
- package/lib/commonjs/utils/index.test.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/components/Carousel.js +27 -44
- package/lib/module/components/Carousel.js.map +1 -1
- package/lib/module/components/ItemRenderer.js +62 -0
- package/lib/module/components/ItemRenderer.js.map +1 -0
- package/lib/module/components/Pagination/Basic/PaginationItem.js +63 -0
- package/lib/module/components/Pagination/Basic/PaginationItem.js.map +1 -0
- package/lib/module/components/Pagination/Basic/index.js +42 -0
- package/lib/module/components/Pagination/Basic/index.js.map +1 -0
- package/lib/module/components/Pagination/index.js +5 -0
- package/lib/module/components/Pagination/index.js.map +1 -0
- package/lib/module/components/ScrollViewGesture.js +53 -34
- package/lib/module/components/ScrollViewGesture.js.map +1 -1
- 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 +12 -11
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCommonVariables.js +38 -8
- 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/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 +4 -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.map +1 -1
- 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 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/{computeNewIndexWhenDataChanges.js → 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/handleroffset-direction.js +5 -5
- package/lib/module/utils/handleroffset-direction.js.map +1 -1
- package/lib/module/utils/handleroffset-direction.test.js +41 -0
- package/lib/module/utils/handleroffset-direction.test.js.map +1 -0
- package/lib/module/utils/index.test.js +6 -6
- package/lib/module/utils/index.test.js.map +1 -1
- package/lib/typescript/components/ItemRenderer.d.ts +22 -0
- package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +17 -0
- package/lib/typescript/components/Pagination/Basic/index.d.ts +16 -0
- package/lib/typescript/components/Pagination/index.d.ts +3 -0
- package/lib/typescript/components/ScrollViewGesture.d.ts +1 -1
- package/lib/typescript/components/rnr-demo.test.d.ts +1 -0
- 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 +3 -2
- 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 +2 -0
- package/lib/typescript/types.d.ts +27 -16
- package/lib/typescript/utils/{computeNewIndexWhenDataChanges.d.ts → 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 +2 -1
- package/lib/typescript/utils/handleroffset-direction.test.d.ts +1 -0
- package/package.json +18 -60
- package/src/{layouts → components}/BaseLayout.tsx +7 -35
- package/src/components/Carousel.tsx +33 -71
- package/src/components/ItemRenderer.tsx +105 -0
- package/src/components/Pagination/Basic/PaginationItem.tsx +111 -0
- package/src/components/Pagination/Basic/index.tsx +81 -0
- package/src/components/Pagination/index.tsx +5 -0
- package/src/components/ScrollViewGesture.tsx +74 -49
- package/src/components/rnr-demo.test.tsx +43 -0
- package/src/hooks/useCarouselController.tsx +24 -21
- package/src/hooks/useCommonVariables.test.tsx +41 -0
- package/src/hooks/useCommonVariables.ts +35 -10
- 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 +7 -2
- package/src/hooks/usePanGestureProxy.test.tsx +376 -0
- package/src/hooks/usePanGestureProxy.ts +110 -0
- package/src/hooks/useUpdateGestureConfig.ts +4 -2
- package/src/hooks/useVisibleRanges.test.tsx +179 -0
- package/src/hooks/useVisibleRanges.tsx +72 -24
- package/src/index.tsx +3 -0
- package/src/types.ts +28 -17
- package/src/utils/compute-offset-if-data-changed.test.ts +30 -0
- package/src/utils/{computeNewIndexWhenDataChanges.ts → 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 +12 -9
- package/src/utils/index.test.ts +6 -6
- package/lib/commonjs/layouts/BaseLayout.js.map +0 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +0 -84
- package/lib/commonjs/layouts/ParallaxLayout.js.map +0 -1
- package/lib/commonjs/utils/computeNewIndexWhenDataChanges.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/computeNewIndexWhenDataChanges.js.map +0 -1
- package/lib/typescript/layouts/ParallaxLayout.d.ts +0 -13
- package/src/layouts/ParallaxLayout.tsx +0 -141
- /package/lib/typescript/{layouts → components}/BaseLayout.d.ts +0 -0
package/README.md
CHANGED
|
@@ -32,9 +32,8 @@ Check out [the documentation website](https://reanimated-carousel.dev).
|
|
|
32
32
|
| <a href="./example/app/src/pages/parallax/index.tsx">parallax-vertical</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-left</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-right</a> |
|
|
33
33
|
| <img src="assets/stack-vertical-left.gif"/> | <img src="assets/stack-vertical-right.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
|
|
34
34
|
| <a href="./example/app/src/pages/stack/index.tsx">stack-vertical-left</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-vertical-right</a> | <a href="./example/app/src/pages/stack/index.tsx">stack-horizontal-right</a> |
|
|
35
|
-
| <img src="assets/left-align.gif"/> |
|
|
36
|
-
| <a href="./example/app/src/pages/left-align/index.tsx">left-align</a> |
|
|
37
|
-
|
|
35
|
+
| <img src="assets/left-align.gif"/> | | <img src="assets/right-align.gif" > |
|
|
36
|
+
| <a href="./example/app/src/pages/left-align/index.tsx">left-align</a> | | <a href="./example/app/src/pages/right-align/index.tsx">right-align</a> |
|
|
38
37
|
|
|
39
38
|
> You can make cool animations with custom animation API [[Details]](https://reanimated-carousel.dev/custom-animations)
|
|
40
39
|
|
|
@@ -9,10 +9,6 @@ var _react = _interopRequireDefault(require("react"));
|
|
|
9
9
|
|
|
10
10
|
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
11
11
|
|
|
12
|
-
var _LazyView = require("../components/LazyView");
|
|
13
|
-
|
|
14
|
-
var _useCheckMounted = require("../hooks/useCheckMounted");
|
|
15
|
-
|
|
16
12
|
var _useOffsetX = require("../hooks/useOffsetX");
|
|
17
13
|
|
|
18
14
|
var _store = require("../store");
|
|
@@ -24,7 +20,6 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
24
20
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
25
21
|
|
|
26
22
|
const BaseLayout = props => {
|
|
27
|
-
const mounted = (0, _useCheckMounted.useCheckMounted)();
|
|
28
23
|
const {
|
|
29
24
|
handlerOffset,
|
|
30
25
|
index,
|
|
@@ -48,9 +43,6 @@ const BaseLayout = props => {
|
|
|
48
43
|
}
|
|
49
44
|
} = context;
|
|
50
45
|
const size = vertical ? height : width;
|
|
51
|
-
|
|
52
|
-
const [shouldUpdate, setShouldUpdate] = _react.default.useState(false);
|
|
53
|
-
|
|
54
46
|
let offsetXConfig = {
|
|
55
47
|
handlerOffset,
|
|
56
48
|
index,
|
|
@@ -78,15 +70,9 @@ const BaseLayout = props => {
|
|
|
78
70
|
|
|
79
71
|
const x = (0, _useOffsetX.useOffsetX)(offsetXConfig, visibleRanges);
|
|
80
72
|
const animationValue = (0, _reactNativeReanimated.useDerivedValue)(() => x.value / size, [x, size]);
|
|
81
|
-
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() =>
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
mounted.current && setShouldUpdate(index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1]);
|
|
85
|
-
}, [index, mounted]);
|
|
86
|
-
|
|
87
|
-
(0, _reactNativeReanimated.useAnimatedReaction)(() => visibleRanges.value, () => {
|
|
88
|
-
(0, _reactNativeReanimated.runOnJS)(updateView)(visibleRanges.value.negativeRange, visibleRanges.value.positiveRange);
|
|
89
|
-
}, [visibleRanges.value]);
|
|
73
|
+
const animatedStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
74
|
+
return animationStyle(x.value / size);
|
|
75
|
+
}, [animationStyle]);
|
|
90
76
|
return /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
91
77
|
style: [{
|
|
92
78
|
width: width || "100%",
|
|
@@ -99,12 +85,10 @@ const BaseLayout = props => {
|
|
|
99
85
|
* The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.
|
|
100
86
|
* */
|
|
101
87
|
,
|
|
102
|
-
testID: `__CAROUSEL_ITEM_${index}
|
|
103
|
-
}, /*#__PURE__*/_react.default.createElement(_LazyView.LazyView, {
|
|
104
|
-
shouldUpdate: shouldUpdate
|
|
88
|
+
testID: `__CAROUSEL_ITEM_${index}__`
|
|
105
89
|
}, children({
|
|
106
90
|
animationValue
|
|
107
|
-
}))
|
|
91
|
+
}));
|
|
108
92
|
};
|
|
109
93
|
|
|
110
94
|
exports.BaseLayout = BaseLayout;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["BaseLayout.tsx"],"names":["BaseLayout","props","handlerOffset","index","children","visibleRanges","animationStyle","context","React","useContext","CTX","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","position"],"mappings":";;;;;;;AAAA;;AAGA;;AAMA;;AAGA;;;;;;;;AAIO,MAAMA,UAQX,GAAIC,KAAD,IAAW;AACd,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,KAAjB;AAAwBC,IAAAA,QAAxB;AAAkCC,IAAAA,aAAlC;AAAiDC,IAAAA;AAAjD,MACFL,KADJ;;AAGA,QAAMM,OAAO,GAAGC,eAAMC,UAAN,CAAiBC,UAAjB,CAAhB;;AACA,QAAM;AACJT,IAAAA,KAAK,EAAE;AACLU,MAAAA,IADK;AAELC,MAAAA,UAFK;AAGLC,MAAAA,KAHK;AAILC,MAAAA,MAJK;AAKLC,MAAAA,Q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MAAAA,QAAQ,EAAE;AAHZ,KADK,EAMLD,aANK;AAQP;AACN;AACA;AACA;AACA;AAbI;AAcE,IAAA,MAAM,EAAG,mBAAkBzB,KAAM;AAdnC,KAgBGC,QAAQ,CAAC;AAAEsB,IAAAA;AAAF,GAAD,CAhBX,CADF;AAoBD,CA/EM","sourcesContent":["import React from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport type { AnimatedStyleProp } from \"react-native-reanimated\";\nimport Animated, {\n useAnimatedStyle,\n useDerivedValue,\n} from \"react-native-reanimated\";\n\nimport type { IOpts } from \"../hooks/useOffsetX\";\nimport { useOffsetX } from \"../hooks/useOffsetX\";\nimport type { IVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport type { ILayoutConfig } from \"../layouts/stack\";\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 { 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\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 () => {\n return animationStyle(x.value / size);\n },\n [animationStyle],\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}__`}\n >\n {children({ animationValue })}\n </Animated.View>\n );\n};\n"]}
|
|
@@ -13,6 +13,8 @@ var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
|
13
13
|
|
|
14
14
|
var _reactNativeReanimated = require("react-native-reanimated");
|
|
15
15
|
|
|
16
|
+
var _ItemRenderer = require("./ItemRenderer");
|
|
17
|
+
|
|
16
18
|
var _ScrollViewGesture = require("./ScrollViewGesture");
|
|
17
19
|
|
|
18
20
|
var _useAutoPlay = require("../hooks/useAutoPlay");
|
|
@@ -29,10 +31,6 @@ var _useOnProgressChange = require("../hooks/useOnProgressChange");
|
|
|
29
31
|
|
|
30
32
|
var _usePropsErrorBoundary = require("../hooks/usePropsErrorBoundary");
|
|
31
33
|
|
|
32
|
-
var _useVisibleRanges = require("../hooks/useVisibleRanges");
|
|
33
|
-
|
|
34
|
-
var _BaseLayout = require("../layouts/BaseLayout");
|
|
35
|
-
|
|
36
34
|
var _store = require("../store");
|
|
37
35
|
|
|
38
36
|
var _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
|
|
@@ -49,8 +47,6 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
49
47
|
data,
|
|
50
48
|
// Length of fill data
|
|
51
49
|
dataLength,
|
|
52
|
-
// Raw data that has not been processed
|
|
53
|
-
rawData,
|
|
54
50
|
// Length of raw data
|
|
55
51
|
rawDataLength,
|
|
56
52
|
mode,
|
|
@@ -64,10 +60,11 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
64
60
|
autoPlayInterval,
|
|
65
61
|
scrollAnimationDuration,
|
|
66
62
|
withAnimation,
|
|
63
|
+
fixedDirection,
|
|
67
64
|
renderItem,
|
|
68
65
|
onScrollEnd,
|
|
69
66
|
onSnapToItem,
|
|
70
|
-
|
|
67
|
+
onScrollStart,
|
|
71
68
|
onProgressChange,
|
|
72
69
|
customAnimation,
|
|
73
70
|
defaultIndex
|
|
@@ -86,7 +83,7 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
86
83
|
(0, _usePropsErrorBoundary.usePropsErrorBoundary)({ ...props,
|
|
87
84
|
dataLength
|
|
88
85
|
});
|
|
89
|
-
(0, _useOnProgressChange.useOnProgressChange)({
|
|
86
|
+
const progressValue = (0, _useOnProgressChange.useOnProgressChange)({
|
|
90
87
|
autoFillData,
|
|
91
88
|
loop,
|
|
92
89
|
size,
|
|
@@ -102,9 +99,10 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
102
99
|
handlerOffset,
|
|
103
100
|
withAnimation,
|
|
104
101
|
defaultIndex,
|
|
102
|
+
fixedDirection,
|
|
103
|
+
duration: scrollAnimationDuration,
|
|
105
104
|
onScrollEnd: () => (0, _reactNativeReanimated.runOnJS)(_onScrollEnd)(),
|
|
106
|
-
|
|
107
|
-
duration: scrollAnimationDuration
|
|
105
|
+
onScrollStart: () => !!onScrollStart && (0, _reactNativeReanimated.runOnJS)(onScrollStart)()
|
|
108
106
|
});
|
|
109
107
|
const {
|
|
110
108
|
next,
|
|
@@ -136,10 +134,10 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
136
134
|
if (onScrollEnd) onScrollEnd(realIndex);
|
|
137
135
|
}, [loop, autoFillData, rawDataLength, getSharedIndex, onSnapToItem, onScrollEnd]);
|
|
138
136
|
|
|
139
|
-
const
|
|
137
|
+
const scrollViewGestureOnScrollStart = _react.default.useCallback(() => {
|
|
140
138
|
pauseAutoPlay();
|
|
141
|
-
|
|
142
|
-
}, [
|
|
139
|
+
onScrollStart === null || onScrollStart === void 0 ? void 0 : onScrollStart();
|
|
140
|
+
}, [onScrollStart, pauseAutoPlay]);
|
|
143
141
|
|
|
144
142
|
const scrollViewGestureOnScrollEnd = _react.default.useCallback(() => {
|
|
145
143
|
startAutoPlay();
|
|
@@ -155,44 +153,13 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
155
153
|
next,
|
|
156
154
|
prev,
|
|
157
155
|
getCurrentIndex,
|
|
158
|
-
scrollTo
|
|
156
|
+
scrollTo,
|
|
157
|
+
progressValue
|
|
159
158
|
}), [getCurrentIndex, next, prev, scrollTo]);
|
|
160
159
|
|
|
161
|
-
const visibleRanges = (0, _useVisibleRanges.useVisibleRanges)({
|
|
162
|
-
total: dataLength,
|
|
163
|
-
viewSize: size,
|
|
164
|
-
translation: handlerOffset,
|
|
165
|
-
windowSize
|
|
166
|
-
});
|
|
167
160
|
const layoutConfig = (0, _useLayoutConfig.useLayoutConfig)({ ...props,
|
|
168
161
|
size
|
|
169
162
|
});
|
|
170
|
-
|
|
171
|
-
const renderLayout = _react.default.useCallback((item, i) => {
|
|
172
|
-
const realIndex = (0, _computedWithAutoFillData.computedRealIndexWithAutoFillData)({
|
|
173
|
-
index: i,
|
|
174
|
-
dataLength: rawDataLength,
|
|
175
|
-
loop,
|
|
176
|
-
autoFillData
|
|
177
|
-
});
|
|
178
|
-
return /*#__PURE__*/_react.default.createElement(_BaseLayout.BaseLayout, {
|
|
179
|
-
key: i,
|
|
180
|
-
index: i,
|
|
181
|
-
handlerOffset: offsetX,
|
|
182
|
-
visibleRanges: visibleRanges,
|
|
183
|
-
animationStyle: customAnimation || layoutConfig
|
|
184
|
-
}, _ref => {
|
|
185
|
-
let {
|
|
186
|
-
animationValue
|
|
187
|
-
} = _ref;
|
|
188
|
-
return renderItem({
|
|
189
|
-
item,
|
|
190
|
-
index: realIndex,
|
|
191
|
-
animationValue
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
}, [loop, rawData, offsetX, visibleRanges, autoFillData, renderItem, layoutConfig, customAnimation]);
|
|
195
|
-
|
|
196
163
|
return /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.GestureHandlerRootView, null, /*#__PURE__*/_react.default.createElement(_store.CTX.Provider, {
|
|
197
164
|
value: {
|
|
198
165
|
props,
|
|
@@ -207,11 +174,24 @@ const Carousel = /*#__PURE__*/_react.default.forwardRef((_props, ref) => {
|
|
|
207
174
|
height: height || "100%"
|
|
208
175
|
}, style, vertical ? styles.itemsVertical : styles.itemsHorizontal],
|
|
209
176
|
testID: testID,
|
|
210
|
-
|
|
177
|
+
onScrollStart: scrollViewGestureOnScrollStart,
|
|
211
178
|
onScrollEnd: scrollViewGestureOnScrollEnd,
|
|
212
179
|
onTouchBegin: scrollViewGestureOnTouchBegin,
|
|
213
180
|
onTouchEnd: scrollViewGestureOnTouchEnd
|
|
214
|
-
},
|
|
181
|
+
}, /*#__PURE__*/_react.default.createElement(_ItemRenderer.ItemRenderer, {
|
|
182
|
+
data: data,
|
|
183
|
+
dataLength: dataLength,
|
|
184
|
+
rawDataLength: rawDataLength,
|
|
185
|
+
loop: loop,
|
|
186
|
+
size: size,
|
|
187
|
+
windowSize: windowSize,
|
|
188
|
+
autoFillData: autoFillData,
|
|
189
|
+
offsetX: offsetX,
|
|
190
|
+
handlerOffset: handlerOffset,
|
|
191
|
+
layoutConfig: layoutConfig,
|
|
192
|
+
renderItem: renderItem,
|
|
193
|
+
customAnimation: customAnimation
|
|
194
|
+
}))));
|
|
215
195
|
});
|
|
216
196
|
|
|
217
197
|
var _default = Carousel;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","testID","loop","autoFillData","data","dataLength","rawData","rawDataLength","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffset","offsetX","totalSize","x","value","isNaN","carouselController","_onScrollEnd","duration","next","prev","scrollTo","getSharedIndex","getCurrentIndex","start","startAutoPlay","pause","pauseAutoPlay","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","i","animationValue","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;AACA;;AAEA;;AAEA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AAEA;;;;AAEA,MAAMA,QAAQ,gBAAGC,eAAMC,UAAN,CACf,CAACC,MAAD,EAASC,GAAT,KAAiB;AACf,QAAMC,KAAK,GAAG,gCAAaF,MAAb,CAAd;AAEA,QAAM;AACJG,IAAAA,MADI;AAEJC,IAAAA,IAFI;AAGJC,IAAAA,YAHI;AAIJ;AACAC,IAAAA,IALI;AAMJ;AACAC,IAAAA,UAPI;AAQJ;AACAC,IAAAA,OATI;AAUJ;AACAC,IAAAA,aAXI;AAYJC,IAAAA,IAZI;AAaJC,IAAAA,KAbI;AAcJC,IAAAA,KAdI;AAeJC,IAAAA,MAfI;AAgBJC,IAAAA,QAhBI;AAiBJC,IAAAA,QAjBI;AAkBJC,IAAAA,UAlBI;AAmBJC,IAAAA,eAnBI;AAoBJC,IAAAA,gBApBI;AAqBJC,IAAAA,uBArBI;AAsBJC,IAAAA,aAtBI;AAuBJC,IAAAA,UAvBI;AAwBJC,IAAAA,WAxBI;AAyBJC,IAAAA,YAzBI;AA0BJC,IAAAA,aA1BI;AA2BJC,IAAAA,gBA3BI;AA4BJC,IAAAA,eA5BI;AA6BJC,IAAAA;AA7BI,MA8BFzB,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F,EAOE0C,YAPF,EAQErC,eARF,CA3BmB,CAArB;;AAuCA,sBACE,6BAAC,iDAAD,qBACE,6BAAC,UAAD,CAAK,QAAL;AAAc,IAAA,KAAK,EAAE;AAAExB,MAAAA,KAAF;AAASkE,MAAAA,MAAM,EAAExC;AAAjB;AAArB,kBACE,6BAAC,oCAAD;AACE,IAAA,GAAG,EAAElB,IADP;AAEE,IAAA,IAAI,EAAEmB,IAFR;AAGE,IAAA,WAAW,EAAEC,aAHf;AAIE,IAAA,KAAK,EAAE,CACLuC,MAAM,CAACC,SADF,EAEL;AACE1D,MAAAA,KAAK,EAAEA,KAAK,IAAI,MADlB;AAEEC,MAAAA,MAAM,EAAEA,MAAM,IAAI;AAFpB,KAFK,EAMLF,KANK,EAOLG,QAAQ,GACJuD,MAAM,CAACE,aADH,GAEJF,MAAM,CAACG,eATN,CAJT;AAeE,IAAA,MAAM,EAAErE,MAfV;AAgBE,IAAA,aAAa,EAAEmD,8BAhBjB;AAiBE,IAAA,WAAW,EAAEC,4BAjBf;AAkBE,IAAA,YAAY,EAAEC,6BAlBhB;AAmBE,IAAA,UAAU,EAAEC;AAnBd,KAqBGnD,IAAI,CAACmE,GAAL,CAAST,YAAT,CArBH,CADF,CADF,CADF;AA6BD,CApNc,CAAjB;;eAuNenE,Q;;;AAIf,MAAMwE,MAAM,GAAGK,wBAAWC,MAAX,CAAkB;AAC/BL,EAAAA,SAAS,EAAE;AACTM,IAAAA,QAAQ,EAAE;AADD,GADoB;AAI/BJ,EAAAA,eAAe,EAAE;AACfK,IAAAA,aAAa,EAAE;AADA,GAJc;AAO/BN,EAAAA,aAAa,EAAE;AACbM,IAAAA,aAAa,EAAE;AADF;AAPgB,CAAlB,CAAf","sourcesContent":["import React from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport { GestureHandlerRootView } from \"react-native-gesture-handler\";\nimport { runOnJS, useDerivedValue } from \"react-native-reanimated\";\n\nimport { ScrollViewGesture } from \"./ScrollViewGesture\";\n\nimport { useAutoPlay } from \"../hooks/useAutoPlay\";\nimport { useCarouselController } from \"../hooks/useCarouselController\";\nimport { useCommonVariables } from \"../hooks/useCommonVariables\";\nimport { useInitProps } from \"../hooks/useInitProps\";\nimport { useLayoutConfig } from \"../hooks/useLayoutConfig\";\nimport { useOnProgressChange } from \"../hooks/useOnProgressChange\";\nimport { usePropsErrorBoundary } from \"../hooks/usePropsErrorBoundary\";\nimport { useVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { BaseLayout } from \"../layouts/BaseLayout\";\nimport { CTX } from \"../store\";\nimport type { ICarouselInstance, TCarouselProps } from \"../types\";\nimport { computedRealIndexWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n loop,\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 mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffset } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n\n if (!loop)\n return handlerOffset.value;\n\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary({ ...props, dataLength });\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawDataLength,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n dataLength,\n autoFillData,\n handlerOffset,\n withAnimation,\n defaultIndex,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n duration: scrollAnimationDuration,\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex }\n = carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem)\n onSnapToItem(realIndex);\n\n if (onScrollEnd)\n onScrollEnd(realIndex);\n }, [\n loop,\n autoFillData,\n rawDataLength,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pauseAutoPlay();\n onScrollBegin?.();\n }, [onScrollBegin, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n }),\n [getCurrentIndex, next, prev, scrollTo],\n );\n\n const visibleRanges = useVisibleRanges({\n total: dataLength,\n viewSize: size,\n translation: handlerOffset,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index: i,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffset={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n loop,\n rawData,\n offsetX,\n visibleRanges,\n autoFillData,\n renderItem,\n layoutConfig,\n customAnimation,\n ],\n );\n\n return (\n <GestureHandlerRootView>\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffset}\n style={[\n styles.container,\n {\n width: width || \"100%\",\n height: height || \"100%\",\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n {data.map(renderLayout)}\n </ScrollViewGesture>\n </CTX.Provider>\n </GestureHandlerRootView>\n );\n },\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: \"hidden\",\n },\n itemsHorizontal: {\n flexDirection: \"row\",\n },\n itemsVertical: {\n flexDirection: \"column\",\n },\n});\n"]}
|
|
1
|
+
{"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","testID","loop","autoFillData","data","dataLength","rawDataLength","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","fixedDirection","renderItem","onScrollEnd","onSnapToItem","onScrollStart","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffset","offsetX","totalSize","x","value","isNaN","progressValue","carouselController","duration","_onScrollEnd","next","prev","scrollTo","getSharedIndex","getCurrentIndex","start","startAutoPlay","pause","pauseAutoPlay","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollStart","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","layoutConfig","common","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SAAS,EAAE;AACTK,IAAAA,QAAQ,EAAE;AADD,GADoB;AAI/BH,EAAAA,eAAe,EAAE;AACfI,IAAAA,aAAa,EAAE;AADA,GAJc;AAO/BL,EAAAA,aAAa,EAAE;AACbK,IAAAA,aAAa,EAAE;AADF;AAPgB,CAAlB,CAAf","sourcesContent":["import React from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport { GestureHandlerRootView } from \"react-native-gesture-handler\";\nimport { runOnJS, useDerivedValue } from \"react-native-reanimated\";\n\nimport { ItemRenderer } from \"./ItemRenderer\";\nimport { ScrollViewGesture } from \"./ScrollViewGesture\";\n\nimport { useAutoPlay } from \"../hooks/useAutoPlay\";\nimport { useCarouselController } from \"../hooks/useCarouselController\";\nimport { useCommonVariables } from \"../hooks/useCommonVariables\";\nimport { useInitProps } from \"../hooks/useInitProps\";\nimport { useLayoutConfig } from \"../hooks/useLayoutConfig\";\nimport { useOnProgressChange } from \"../hooks/useOnProgressChange\";\nimport { usePropsErrorBoundary } from \"../hooks/usePropsErrorBoundary\";\nimport { CTX } from \"../store\";\nimport type { ICarouselInstance, TCarouselProps } from \"../types\";\nimport { computedRealIndexWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n loop,\n autoFillData,\n // Fill data with autoFillData\n data,\n // Length of fill data\n dataLength,\n // Length of raw data\n rawDataLength,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n fixedDirection,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollStart,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffset } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n\n if (!loop) return handlerOffset.value;\n\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary({ ...props, dataLength });\n const progressValue = useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawDataLength,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n dataLength,\n autoFillData,\n handlerOffset,\n withAnimation,\n defaultIndex,\n fixedDirection,\n duration: scrollAnimationDuration,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollStart: () => !!onScrollStart && runOnJS(onScrollStart)(),\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex } =\n carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem) onSnapToItem(realIndex);\n\n if (onScrollEnd) onScrollEnd(realIndex);\n }, [\n loop,\n autoFillData,\n rawDataLength,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollStart = React.useCallback(() => {\n pauseAutoPlay();\n onScrollStart?.();\n }, [onScrollStart, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n progressValue,\n }),\n [getCurrentIndex, next, prev, scrollTo],\n );\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n return (\n <GestureHandlerRootView>\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffset}\n style={[\n styles.container,\n {\n width: width || \"100%\",\n height: height || \"100%\",\n },\n style,\n vertical ? styles.itemsVertical : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollStart={scrollViewGestureOnScrollStart}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n <ItemRenderer\n data={data}\n dataLength={dataLength}\n rawDataLength={rawDataLength}\n loop={loop}\n size={size}\n windowSize={windowSize}\n autoFillData={autoFillData}\n offsetX={offsetX}\n handlerOffset={handlerOffset}\n layoutConfig={layoutConfig}\n renderItem={renderItem}\n customAnimation={customAnimation}\n />\n </ScrollViewGesture>\n </CTX.Provider>\n </GestureHandlerRootView>\n );\n },\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>,\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: \"hidden\",\n },\n itemsHorizontal: {\n flexDirection: \"row\",\n },\n itemsVertical: {\n flexDirection: \"column\",\n },\n});\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ItemRenderer = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
11
|
+
|
|
12
|
+
var _BaseLayout = require("./BaseLayout");
|
|
13
|
+
|
|
14
|
+
var _useVisibleRanges = require("../hooks/useVisibleRanges");
|
|
15
|
+
|
|
16
|
+
var _computedWithAutoFillData = require("../utils/computed-with-auto-fill-data");
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const ItemRenderer = props => {
|
|
21
|
+
const {
|
|
22
|
+
data,
|
|
23
|
+
size,
|
|
24
|
+
windowSize,
|
|
25
|
+
handlerOffset,
|
|
26
|
+
offsetX,
|
|
27
|
+
dataLength,
|
|
28
|
+
rawDataLength,
|
|
29
|
+
loop,
|
|
30
|
+
autoFillData,
|
|
31
|
+
layoutConfig,
|
|
32
|
+
renderItem,
|
|
33
|
+
customAnimation
|
|
34
|
+
} = props;
|
|
35
|
+
const visibleRanges = (0, _useVisibleRanges.useVisibleRanges)({
|
|
36
|
+
total: dataLength,
|
|
37
|
+
viewSize: size,
|
|
38
|
+
translation: handlerOffset,
|
|
39
|
+
windowSize,
|
|
40
|
+
loop
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
const [displayedItems, setDisplayedItems] = _react.default.useState(null);
|
|
44
|
+
|
|
45
|
+
(0, _reactNativeReanimated.useAnimatedReaction)(() => visibleRanges.value, ranges => (0, _reactNativeReanimated.runOnJS)(setDisplayedItems)(ranges), [visibleRanges]);
|
|
46
|
+
if (!displayedItems) return null;
|
|
47
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, data.map((item, index) => {
|
|
48
|
+
const realIndex = (0, _computedWithAutoFillData.computedRealIndexWithAutoFillData)({
|
|
49
|
+
index,
|
|
50
|
+
dataLength: rawDataLength,
|
|
51
|
+
loop,
|
|
52
|
+
autoFillData
|
|
53
|
+
});
|
|
54
|
+
const {
|
|
55
|
+
negativeRange,
|
|
56
|
+
positiveRange
|
|
57
|
+
} = displayedItems;
|
|
58
|
+
const shouldRender = index >= negativeRange[0] && index <= negativeRange[1] || index >= positiveRange[0] && index <= positiveRange[1];
|
|
59
|
+
if (!shouldRender) return null;
|
|
60
|
+
return /*#__PURE__*/_react.default.createElement(_BaseLayout.BaseLayout, {
|
|
61
|
+
key: index,
|
|
62
|
+
index: index,
|
|
63
|
+
handlerOffset: offsetX,
|
|
64
|
+
visibleRanges: visibleRanges,
|
|
65
|
+
animationStyle: customAnimation || layoutConfig
|
|
66
|
+
}, _ref => {
|
|
67
|
+
let {
|
|
68
|
+
animationValue
|
|
69
|
+
} = _ref;
|
|
70
|
+
return renderItem({
|
|
71
|
+
item,
|
|
72
|
+
index: realIndex,
|
|
73
|
+
animationValue
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
}));
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
exports.ItemRenderer = ItemRenderer;
|
|
80
|
+
//# sourceMappingURL=ItemRenderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["ItemRenderer.tsx"],"names":["ItemRenderer","props","data","size","windowSize","handlerOffset","offsetX","dataLength","rawDataLength","loop","autoFillData","layoutConfig","renderItem","customAnimation","visibleRanges","total","viewSize","translation","displayedItems","setDisplayedItems","React","useState","value","ranges","map","item","index","realIndex","negativeRange","positiveRange","shouldRender","animationValue"],"mappings":";;;;;;;AAAA;;AAIA;;AAGA;;AAGA;;AAEA;;;;AAiBO,MAAMA,YAAuB,GAAIC,KAAD,IAAW;AAChD,QAAM;AACJC,IAAAA,IADI;AAEJC,IAAAA,IAFI;AAGJC,IAAAA,UAHI;AAIJC,IAAAA,aAJI;AAKJC,IAAAA,OALI;AAMJC,IAAAA,UANI;AAOJC,IAAAA,aAPI;AAQJC,IAAAA,IARI;AASJC,IAAAA,YATI;AAUJC,IAAAA,YAVI;AAWJC,IAAAA,UAXI;AAYJC,IAAAA;AAZI,MAaFZ,KAbJ;AAeA,QAAMa,aAAa,GAAG,wCAAiB;AACrCC,IAAAA,KAAK,EAAER,UAD8B;AAErCS,IAAAA,QAAQ,EAAEb,IAF2B;AAGrCc,IAAAA,WAAW,EAAEZ,aAHwB;AAIrCD,IAAAA,UAJqC;AAKrCK,IAAAA;AALqC,GAAjB,CAAtB;;AAQA,QAAM,CAACS,cAAD,EAAiBC,iBAAjB,IAAsCC,eAAMC,QAAN,CAA8B,IAA9B,CAA5C;;AAEA,kDACE,MAAMP,aAAa,CAACQ,KADtB,EAEEC,MAAM,IAAI,oCAAQJ,iBAAR,EAA2BI,MAA3B,CAFZ,EAGE,CAACT,aAAD,CAHF;AAMA,MAAI,CAACI,cAAL,EACE,OAAO,IAAP;AAEF,sBACE,4DAEIhB,IAAI,CAACsB,GAAL,CAAS,CAACC,IAAD,EAAOC,KAAP,KAAiB;AACxB,UAAMC,SAAS,GAAG,iEAAkC;AAClDD,MAAAA,KADkD;AAElDnB,MAAAA,UAAU,EAAEC,aAFsC;AAGlDC,MAAAA,IAHkD;AAIlDC,MAAAA;AAJkD,KAAlC,CAAlB;AAOA,UAAM;AAAEkB,MAAAA,aAAF;AAAiBC,MAAAA;AAAjB,QAAmCX,cAAzC;AAEA,UAAMY,YAAY,GAAIJ,KAAK,IAAIE,aAAa,CAAC,CAAD,CAAtB,IAA6BF,KAAK,IAAIE,aAAa,CAAC,CAAD,CAApD,IACjBF,KAAK,IAAIG,aAAa,CAAC,CAAD,CAAtB,IAA6BH,KAAK,IAAIG,aAAa,CAAC,CAAD,CADvD;AAGA,QAAI,CAACC,YAAL,EACE,OAAO,IAAP;AAEF,wBACE,6BAAC,sBAAD;AACE,MAAA,GAAG,EAAEJ,KADP;AAEE,MAAA,KAAK,EAAEA,KAFT;AAGE,MAAA,aAAa,EAAEpB,OAHjB;AAIE,MAAA,aAAa,EAAEQ,aAJjB;AAKE,MAAA,cAAc,EAAED,eAAe,IAAIF;AALrC,OAOG;AAAA,UAAC;AAAEoB,QAAAA;AAAF,OAAD;AAAA,aACCnB,UAAU,CAAC;AACTa,QAAAA,IADS;AAETC,QAAAA,KAAK,EAAEC,SAFE;AAGTI,QAAAA;AAHS,OAAD,CADX;AAAA,KAPH,CADF;AAiBD,GAjCD,CAFJ,CADF;AAwCD,CA3EM","sourcesContent":["import React from \"react\";\nimport type { FC } from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport type Animated from \"react-native-reanimated\";\nimport { useAnimatedReaction, type AnimatedStyleProp, runOnJS } from \"react-native-reanimated\";\n\nimport type { TAnimationStyle } from \"./BaseLayout\";\nimport { BaseLayout } from \"./BaseLayout\";\n\nimport type { VisibleRanges } from \"../hooks/useVisibleRanges\";\nimport { useVisibleRanges } from \"../hooks/useVisibleRanges\";\nimport type { CarouselRenderItem } from \"../types\";\nimport { computedRealIndexWithAutoFillData } from \"../utils/computed-with-auto-fill-data\";\n\ninterface Props {\n data: any[]\n dataLength: number\n rawDataLength: number\n loop: boolean\n size: number\n windowSize?: number\n autoFillData: boolean\n offsetX: Animated.SharedValue<number>\n handlerOffset: Animated.SharedValue<number>\n layoutConfig: TAnimationStyle\n renderItem: CarouselRenderItem<any>\n customAnimation?: ((value: number) => AnimatedStyleProp<ViewStyle>)\n}\n\nexport const ItemRenderer: FC<Props> = (props) => {\n const {\n data,\n size,\n windowSize,\n handlerOffset,\n offsetX,\n dataLength,\n rawDataLength,\n loop,\n autoFillData,\n layoutConfig,\n renderItem,\n customAnimation,\n } = props;\n\n const visibleRanges = useVisibleRanges({\n total: dataLength,\n viewSize: size,\n translation: handlerOffset,\n windowSize,\n loop,\n });\n\n const [displayedItems, setDisplayedItems] = React.useState<VisibleRanges>(null!);\n\n useAnimatedReaction(\n () => visibleRanges.value,\n ranges => runOnJS(setDisplayedItems)(ranges),\n [visibleRanges],\n );\n\n if (!displayedItems)\n return null;\n\n return (\n <>\n {\n data.map((item, index) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n const { negativeRange, positiveRange } = displayedItems;\n\n const shouldRender = (index >= negativeRange[0] && index <= negativeRange[1])\n || (index >= positiveRange[0] && index <= positiveRange[1]);\n\n if (!shouldRender)\n return null;\n\n return (\n <BaseLayout\n key={index}\n index={index}\n handlerOffset={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n })\n }\n </>\n );\n};\n"]}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.PaginationItem = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
|
|
13
|
+
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
15
|
+
|
|
16
|
+
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; }
|
|
17
|
+
|
|
18
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
19
|
+
|
|
20
|
+
const PaginationItem = props => {
|
|
21
|
+
const {
|
|
22
|
+
animValue,
|
|
23
|
+
dotStyle,
|
|
24
|
+
activeDotStyle,
|
|
25
|
+
index,
|
|
26
|
+
count,
|
|
27
|
+
size,
|
|
28
|
+
horizontal,
|
|
29
|
+
children
|
|
30
|
+
} = props;
|
|
31
|
+
const defaultDotSize = 10;
|
|
32
|
+
const sizes = {
|
|
33
|
+
width: size || (dotStyle === null || dotStyle === void 0 ? void 0 : dotStyle.width) || defaultDotSize,
|
|
34
|
+
height: size || (dotStyle === null || dotStyle === void 0 ? void 0 : dotStyle.height) || defaultDotSize
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* TODO: Keep this for future implementation
|
|
38
|
+
* Used to change the size of the active dot with animation
|
|
39
|
+
*/
|
|
40
|
+
// const animatedSize = {
|
|
41
|
+
// width: activeDotStyle?.width,
|
|
42
|
+
// height: activeDotStyle?.height,
|
|
43
|
+
// };
|
|
44
|
+
|
|
45
|
+
const width = sizes.width;
|
|
46
|
+
const height = sizes.height;
|
|
47
|
+
const animStyle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
|
|
48
|
+
const size = horizontal ? height : width;
|
|
49
|
+
let inputRange = [index - 1, index, index + 1];
|
|
50
|
+
let outputRange = [-size, 0, size];
|
|
51
|
+
|
|
52
|
+
if (index === 0 && (animValue === null || animValue === void 0 ? void 0 : animValue.value) > count - 1) {
|
|
53
|
+
inputRange = [count - 1, count, count + 1];
|
|
54
|
+
outputRange = [-size, 0, size];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
transform: [{
|
|
59
|
+
translateX: (0, _reactNativeReanimated.interpolate)(animValue === null || animValue === void 0 ? void 0 : animValue.value, inputRange, outputRange, _reactNativeReanimated.Extrapolate.CLAMP)
|
|
60
|
+
}]
|
|
61
|
+
};
|
|
62
|
+
}, [animValue, index, count, horizontal]);
|
|
63
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
64
|
+
style: [{
|
|
65
|
+
width,
|
|
66
|
+
height,
|
|
67
|
+
overflow: "hidden",
|
|
68
|
+
transform: [{
|
|
69
|
+
rotateZ: horizontal ? "90deg" : "0deg"
|
|
70
|
+
}]
|
|
71
|
+
}, dotStyle]
|
|
72
|
+
}, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
|
|
73
|
+
style: [{
|
|
74
|
+
backgroundColor: "black",
|
|
75
|
+
flex: 1
|
|
76
|
+
}, animStyle, activeDotStyle]
|
|
77
|
+
}, children));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
exports.PaginationItem = PaginationItem;
|
|
81
|
+
//# sourceMappingURL=PaginationItem.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["PaginationItem.tsx"],"names":["PaginationItem","props","animValue","dotStyle","activeDotStyle","index","count","size","horizontal","children","defaultDotSize","sizes","width","height","animStyle","inputRange","outputRange","value","transform","translateX","Extrapolate","CLAMP","overflow","rotateZ","backgroundColor","flex"],"mappings":";;;;;;;AACA;;AAEA;;AACA;;;;;;;;AAWO,MAAMA,cAUZ,GAAIC,KAAD,IAAW;AACb,QAAM;AACJC,IAAAA,SADI;AAEJC,IAAAA,QAFI;AAGJC,IAAAA,cAHI;AAIJC,IAAAA,KAJI;AAKJC,IAAAA,KALI;AAMJC,IAAAA,IANI;AAOJC,IAAAA,UAPI;AAQJC,IAAAA;AARI,MASFR,KATJ;AAWA,QAAMS,cAAc,GAAG,EAAvB;AAEA,QAAMC,KAAK,GAAG;AACZC,IAAAA,KAAK,EAAEL,IAAI,KAAIJ,QAAJ,aAAIA,QAAJ,uBAAIA,QAAQ,CAAES,KAAd,CAAJ,IAA2BF,cADtB;AAEZG,IAAAA,MAAM,EAAEN,IAAI,KAAIJ,QAAJ,aAAIA,QAAJ,uBAAIA,QAAQ,CAAEU,MAAd,CAAJ,IAA4BH;AAFxB,GAAd;AAKA;AACF;AACA;AACA;AACE;AACA;AACA;AACA;;AAEA,QAAME,KAAK,GAAGD,KAAK,CAACC,KAApB;AACA,QAAMC,MAAM,GAAGF,KAAK,CAACE,MAArB;AAEA,QAAM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AAFR,KADK,EAKLX,SALK,EAMLV,cANK;AADT,KAUGK,QAVH,CAfF,CADF;AA8BD,CA/FM","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport type { ViewStyle } from \"react-native\";\nimport { View } from \"react-native\";\nimport Animated, {\n Extrapolate,\n interpolate,\n useAnimatedStyle,\n} from \"react-native-reanimated\";\n\nexport type DotStyle = Omit<ViewStyle, \"width\" | \"height\"> & {\n width?: number\n height?: number\n};\n\nexport const PaginationItem: React.FC<\nPropsWithChildren<{\n index: number\n count: number\n size?: number\n animValue: Animated.SharedValue<number>\n horizontal?: boolean\n dotStyle?: DotStyle\n activeDotStyle?: DotStyle\n}>\n> = (props) => {\n const {\n animValue,\n dotStyle,\n activeDotStyle,\n index,\n count,\n size,\n horizontal,\n children,\n } = props;\n\n const defaultDotSize = 10;\n\n const sizes = {\n width: size || dotStyle?.width || defaultDotSize,\n height: size || dotStyle?.height || defaultDotSize,\n };\n\n /**\n * TODO: Keep this for future implementation\n * Used to change the size of the active dot with animation\n */\n // const animatedSize = {\n // width: activeDotStyle?.width,\n // height: activeDotStyle?.height,\n // };\n\n const width = sizes.width;\n const height = sizes.height;\n\n const animStyle = useAnimatedStyle(() => {\n const size = horizontal ? height : width;\n let inputRange = [index - 1, index, index + 1];\n let outputRange = [-size, 0, size];\n\n if (index === 0 && animValue?.value > count - 1) {\n inputRange = [count - 1, count, count + 1];\n outputRange = [-size, 0, size];\n }\n\n return {\n transform: [\n {\n translateX: interpolate(\n animValue?.value,\n inputRange,\n outputRange,\n Extrapolate.CLAMP,\n ),\n },\n ],\n };\n }, [animValue, index, count, horizontal]);\n\n return (\n <View\n style={[\n {\n width,\n height,\n overflow: \"hidden\",\n transform: [\n {\n rotateZ: horizontal ? \"90deg\" : \"0deg\",\n },\n ],\n },\n dotStyle,\n ]}\n >\n <Animated.View\n style={[\n {\n backgroundColor: \"black\",\n flex: 1,\n },\n animStyle,\n activeDotStyle,\n ]}\n >\n {children}\n </Animated.View>\n </View>\n );\n};\n"]}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Basic = void 0;
|
|
7
|
+
|
|
8
|
+
var _react = _interopRequireDefault(require("react"));
|
|
9
|
+
|
|
10
|
+
var _reactNative = require("react-native");
|
|
11
|
+
|
|
12
|
+
var _reactNativeGestureHandler = require("react-native-gesture-handler");
|
|
13
|
+
|
|
14
|
+
var _PaginationItem = require("./PaginationItem");
|
|
15
|
+
|
|
16
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
17
|
+
|
|
18
|
+
const Basic = props => {
|
|
19
|
+
const {
|
|
20
|
+
activeDotStyle,
|
|
21
|
+
dotStyle,
|
|
22
|
+
progress,
|
|
23
|
+
horizontal = true,
|
|
24
|
+
data,
|
|
25
|
+
size,
|
|
26
|
+
containerStyle,
|
|
27
|
+
renderItem,
|
|
28
|
+
onPress
|
|
29
|
+
} = props;
|
|
30
|
+
if (typeof size === "string" || typeof (dotStyle === null || dotStyle === void 0 ? void 0 : dotStyle.width) === "string" || typeof (dotStyle === null || dotStyle === void 0 ? void 0 : dotStyle.height) === "string") throw new Error("size/width/height must be a number");
|
|
31
|
+
return /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
32
|
+
style: [{
|
|
33
|
+
justifyContent: "space-between",
|
|
34
|
+
alignSelf: "center"
|
|
35
|
+
}, horizontal ? {
|
|
36
|
+
flexDirection: "row"
|
|
37
|
+
} : {
|
|
38
|
+
flexDirection: "column"
|
|
39
|
+
}, containerStyle]
|
|
40
|
+
}, data.map((item, index) => {
|
|
41
|
+
return /*#__PURE__*/_react.default.createElement(_reactNativeGestureHandler.TouchableWithoutFeedback, {
|
|
42
|
+
key: index,
|
|
43
|
+
onPress: () => onPress === null || onPress === void 0 ? void 0 : onPress(index)
|
|
44
|
+
}, /*#__PURE__*/_react.default.createElement(_PaginationItem.PaginationItem, {
|
|
45
|
+
index: index,
|
|
46
|
+
size: size,
|
|
47
|
+
count: data.length,
|
|
48
|
+
dotStyle: dotStyle,
|
|
49
|
+
animValue: progress,
|
|
50
|
+
horizontal: !horizontal,
|
|
51
|
+
activeDotStyle: activeDotStyle
|
|
52
|
+
}, renderItem === null || renderItem === void 0 ? void 0 : renderItem(item, index)));
|
|
53
|
+
}));
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
exports.Basic = Basic;
|
|
57
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Basic","props","activeDotStyle","dotStyle","progress","horizontal","data","size","containerStyle","renderItem","onPress","width","height","Error","justifyContent","alignSelf","flexDirection","map","item","index","length"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAIA;;;;AAcO,MAAMA,KAAK,GAAkBC,KAAf,IAAwC;AAC3D,QAAM;AACJC,IAAAA,cADI;AAEJC,IAAAA,QAFI;AAGJC,IAAAA,QAHI;AAIJC,IAAAA,UAAU,GAAG,IAJT;AAKJC,IAAAA,IALI;AAMJC,IAAAA,IANI;AAOJC,IAAAA,cAPI;AAQJC,IAAAA,UARI;AASJC,IAAAA;AATI,MAUFT,KAVJ;AAYA,MACE,OAAOM,IAAP,KAAgB,QAAhB,IACA,QAAOJ,QAAP,aAAOA,QAAP,uBAAOA,QAAQ,CAAEQ,KAAjB,MAA2B,QAD3B,IAEA,QAAOR,QAAP,aAAOA,QAAP,uBAAOA,QAAQ,CAAES,MAAjB,MAA4B,QAH9B,EAKE,MAAM,IAAIC,KAAJ,CAAU,oCAAV,CAAN;AAEF,sBACE,6BAAC,iBAAD;AACE,IAAA,KAAK,EAAE,CACL;AACEC,MAAAA,cAAc,EAAE,eADlB;AAEEC,MAAAA,SAAS,EAAE;AAFb,KADK,EAKLV,UAAU,GACN;AACAW,MAAAA,aAAa,EAAE;AADf,KADM,GAIN;AACAA,MAAAA,aAAa,EAAE;AADf,KATC,EAYLR,cAZK;AADT,KAgBGF,IAAI,CAACW,GAAL,CAAS,CAACC,IAAD,EAAOC,KAAP,KAAiB;AACzB,wBACE,6BAAC,mDAAD;AACE,MAAA,GAAG,EAAEA,KADP;AAEE,MAAA,OAAO,EAAE,MAAMT,OAAN,aAAMA,OAAN,uBAAMA,OAAO,CAAGS,KAAH;AAFxB,oBAIE,6BAAC,8BAAD;AACE,MAAA,KAAK,EAAEA,KADT;AAEE,MAAA,IAAI,EAAEZ,IAFR;AAGE,MAAA,KAAK,EAAED,IAAI,CAACc,MAHd;AAIE,MAAA,QAAQ,EAAEjB,QAJZ;AAKE,MAAA,SAAS,EAAEC,QALb;AAME,MAAA,UAAU,EAAE,CAACC,UANf;AAOE,MAAA,cAAc,EAAEH;AAPlB,OASGO,UATH,aASGA,UATH,uBASGA,UAAU,CAAGS,IAAH,EAASC,KAAT,CATb,CAJF,CADF;AAkBD,GAnBA,CAhBH,CADF;AAuCD,CA3DM","sourcesContent":["import React from \"react\";\nimport type { StyleProp, ViewStyle } from \"react-native\";\nimport { View } from \"react-native\";\nimport { TouchableWithoutFeedback } from \"react-native-gesture-handler\";\nimport type { SharedValue } from \"react-native-reanimated\";\n\nimport type { DotStyle } from \"./PaginationItem\";\nimport { PaginationItem } from \"./PaginationItem\";\n\nexport interface BasicProps<T extends {} = {}> {\n progress: SharedValue<number>\n horizontal?: boolean\n data: Array<T>\n renderItem?: (item: T, index: number) => React.ReactNode\n containerStyle?: StyleProp<ViewStyle>\n dotStyle?: DotStyle\n activeDotStyle?: DotStyle\n size?: number\n onPress?: (index: number) => void\n}\n\nexport const Basic = <T extends {}>(props: BasicProps<T>) => {\n const {\n activeDotStyle,\n dotStyle,\n progress,\n horizontal = true,\n data,\n size,\n containerStyle,\n renderItem,\n onPress,\n } = props;\n\n if (\n typeof size === \"string\" ||\n typeof dotStyle?.width === \"string\" ||\n typeof dotStyle?.height === \"string\"\n )\n throw new Error(\"size/width/height must be a number\");\n\n return (\n <View\n style={[\n {\n justifyContent: \"space-between\",\n alignSelf: \"center\",\n },\n horizontal\n ? {\n flexDirection: \"row\",\n }\n : {\n flexDirection: \"column\",\n },\n containerStyle,\n ]}\n >\n {data.map((item, index) => {\n return (\n <TouchableWithoutFeedback\n key={index}\n onPress={() => onPress?.(index)}\n >\n <PaginationItem\n index={index}\n size={size}\n count={data.length}\n dotStyle={dotStyle}\n animValue={progress}\n horizontal={!horizontal}\n activeDotStyle={activeDotStyle}\n >\n {renderItem?.(item, index)}\n </PaginationItem>\n </TouchableWithoutFeedback>\n );\n })}\n </View>\n );\n};\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Pagination = void 0;
|
|
7
|
+
|
|
8
|
+
var _Basic = require("./Basic");
|
|
9
|
+
|
|
10
|
+
const Pagination = {
|
|
11
|
+
Basic: _Basic.Basic
|
|
12
|
+
};
|
|
13
|
+
exports.Pagination = Pagination;
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Pagination","Basic"],"mappings":";;;;;;;AAAA;;AAEO,MAAMA,UAAU,GAAG;AACxBC,EAAAA,KAAK,EAALA;AADwB,CAAnB","sourcesContent":["import { Basic } from \"./Basic\";\n\nexport const Pagination = {\n Basic,\n};\n"]}
|