react-native-reanimated-carousel 4.0.0-alpha.1 → 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 +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 +25 -46
- 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/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/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.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 +24 -42
- 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/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/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.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/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 +1 -0
- package/lib/typescript/types.d.ts +13 -4
- 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 +16 -59
- package/src/{layouts → components}/BaseLayout.tsx +7 -35
- package/src/components/Carousel.tsx +24 -58
- package/src/components/ItemRenderer.tsx +105 -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/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 +2 -0
- package/src/types.ts +13 -4
- 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
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["useVisibleRanges.tsx"],"names":["useVisibleRanges","options","total","viewSize","translation","windowSize","_windowSize","ranges","positiveCount","Math","round","negativeCount","
|
|
1
|
+
{"version":3,"sources":["useVisibleRanges.tsx"],"names":["useVisibleRanges","options","total","viewSize","translation","windowSize","_windowSize","loop","cachedRanges","ranges","positiveCount","Math","round","negativeCount","currentIndex","value","newRanges","negativeRange","positiveRange","isArraysEqual","current","a","b","length","every","index"],"mappings":";;;;;;;AAAA;;AAEA;;AAWO,SAASA,gBAAT,CAA0BC,OAA1B,EAMY;AACjB,QAAM;AACJC,IAAAA,KAAK,GAAG,CADJ;AAEJC,IAAAA,QAFI;AAGJC,IAAAA,WAHI;AAIJC,IAAAA,UAAU,EAAEC,WAJR;AAKJC,IAAAA;AALI,MAMFN,OANJ;AAQA,QAAMI,UAAU,GAAGC,WAAH,aAAGA,WAAH,cAAGA,WAAH,GAAkBJ,KAAlC;AACA,QAAMM,YAAY,GAA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a,CAAC,CAAD,CAAb,GAAmB,CAAnB;AACD;;AACD,UAAIA,aAAa,CAAC,CAAD,CAAb,GAAmBA,aAAa,CAAC,CAAD,CAApC,EAAyC;AACvCD,QAAAA,aAAa,CAAC,CAAD,CAAb,GAAmBf,KAAK,GAAG,CAA3B;AACAgB,QAAAA,aAAa,CAAC,CAAD,CAAb,GAAmB,CAAnB;AACD,OAlBE,CAoBH;;;AACAF,MAAAA,SAAS,GAAG;AAAEC,QAAAA,aAAF;AAAiBC,QAAAA;AAAjB,OAAZ;AACD;;AAED,QACEC,aAAa,oDACXX,YAAY,CAACY,OADF,2DACX,uBAAsBH,aADX,yEAC4B,EAD5B,EAEXD,SAAS,CAACC,aAFC,CAAb,IAIGE,aAAa,qDACdX,YAAY,CAACY,OADC,2DACd,uBAAsBF,aADR,2EACyB,EADzB,EAEdF,SAAS,CAACE,aAFI,CALlB,EAUE,OAAOV,YAAY,CAACY,OAApB;AAEFZ,IAAAA,YAAY,CAACY,OAAb,GAAuBJ,SAAvB;AACA,WAAOR,YAAY,CAACY,OAApB;AACD,GAvDc,EAuDZ,CAACb,IAAD,EAAOL,KAAP,EAAcG,UAAd,EAA0BD,WAA1B,CAvDY,CAAf;AAyDA,SAAOK,MAAP;AACD;;AAED,SAASU,aAAT,CAAuBE,CAAvB,EAAoCC,CAApC,EAA0D;AACxD;;AACA,MAAID,CAAC,CAACE,MAAF,KAAaD,CAAC,CAACC,MAAnB,EAA2B,OAAO,KAAP;AAE3B,SAAOF,CAAC,CAACG,KAAF,CAAQ,CAACT,KAAD,EAAQU,KAAR,KAAkBV,KAAK,KAAKO,CAAC,CAACG,KAAD,CAArC,CAAP;AACD","sourcesContent":["import { useRef } from \"react\";\nimport type Animated from \"react-native-reanimated\";\nimport { useDerivedValue } from \"react-native-reanimated\";\n\ntype Range = [number, number];\n\nexport interface VisibleRanges {\n negativeRange: Range\n positiveRange: Range\n}\n\nexport type IVisibleRanges = Animated.SharedValue<VisibleRanges>;\n\nexport function useVisibleRanges(options: {\n total: number\n viewSize: number\n windowSize?: number\n translation: Animated.SharedValue<number>\n loop?: boolean\n}): IVisibleRanges {\n const {\n total = 0,\n viewSize,\n translation,\n windowSize: _windowSize,\n loop,\n } = options;\n\n const windowSize = _windowSize ?? total;\n const cachedRanges = useRef<VisibleRanges>(null!);\n\n const ranges = useDerivedValue(() => {\n const positiveCount = Math.round(windowSize / 2);\n const negativeCount = windowSize - positiveCount;\n\n let currentIndex = Math.round(-translation.value / viewSize);\n currentIndex = currentIndex < 0 ? (currentIndex % total) + total : currentIndex;\n\n let newRanges: VisibleRanges;\n\n if (!loop) {\n // Adjusting negative range if the carousel is not loopable.\n // So, It will be only displayed the positive items.\n newRanges = {\n negativeRange: [0 + currentIndex - (windowSize - 1), 0 + currentIndex],\n positiveRange: [0 + currentIndex, currentIndex + (windowSize - 1)],\n };\n }\n else {\n const negativeRange: Range = [\n (currentIndex - negativeCount + total) % total,\n (currentIndex - 1 + total) % total,\n ];\n\n const positiveRange: Range = [\n (currentIndex + total) % total,\n (currentIndex + positiveCount + total) % total,\n ];\n\n if (negativeRange[0] < total && negativeRange[0] > negativeRange[1]) {\n negativeRange[1] = total - 1;\n positiveRange[0] = 0;\n }\n if (positiveRange[0] > positiveRange[1]) {\n negativeRange[1] = total - 1;\n positiveRange[0] = 0;\n }\n\n // console.log({ negativeRange, positiveRange ,total,windowSize,a:total <= _windowSize})\n newRanges = { negativeRange, positiveRange };\n }\n\n if (\n isArraysEqual(\n cachedRanges.current?.negativeRange ?? [],\n newRanges.negativeRange,\n )\n && isArraysEqual(\n cachedRanges.current?.positiveRange ?? [],\n newRanges.positiveRange,\n )\n )\n return cachedRanges.current;\n\n cachedRanges.current = newRanges;\n return cachedRanges.current;\n }, [loop, total, windowSize, translation]);\n\n return ranges;\n}\n\nfunction isArraysEqual(a: number[], b: number[]): boolean {\n \"worklet\";\n if (a.length !== b.length) return false;\n\n return a.every((value, index) => value === b[index]);\n}\n"]}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
4
|
+
|
|
5
|
+
var _reactHooks = require("@testing-library/react-hooks");
|
|
6
|
+
|
|
7
|
+
var _useVisibleRanges = require("./useVisibleRanges");
|
|
8
|
+
|
|
9
|
+
const viewSize = 393;
|
|
10
|
+
describe("useVisibleRanges", () => {
|
|
11
|
+
it("should only display the front of the list when loop is false", async () => {
|
|
12
|
+
const hook = (0, _reactHooks.renderHook)(() => {
|
|
13
|
+
const translation = (0, _reactNativeReanimated.useSharedValue)(-0);
|
|
14
|
+
const range = (0, _useVisibleRanges.useVisibleRanges)({
|
|
15
|
+
total: 10,
|
|
16
|
+
translation,
|
|
17
|
+
viewSize,
|
|
18
|
+
windowSize: 4,
|
|
19
|
+
loop: false
|
|
20
|
+
});
|
|
21
|
+
return range;
|
|
22
|
+
});
|
|
23
|
+
const expected = hook.result.current.value;
|
|
24
|
+
expect(expected).toMatchInlineSnapshot(`
|
|
25
|
+
{
|
|
26
|
+
"negativeRange": [
|
|
27
|
+
-3,
|
|
28
|
+
0,
|
|
29
|
+
],
|
|
30
|
+
"positiveRange": [
|
|
31
|
+
0,
|
|
32
|
+
3,
|
|
33
|
+
],
|
|
34
|
+
}
|
|
35
|
+
`);
|
|
36
|
+
});
|
|
37
|
+
it("should display the rear of the list and the front of the list when loop is true", async () => {
|
|
38
|
+
const hook = (0, _reactHooks.renderHook)(() => {
|
|
39
|
+
const translation = (0, _reactNativeReanimated.useSharedValue)(-0);
|
|
40
|
+
const range = (0, _useVisibleRanges.useVisibleRanges)({
|
|
41
|
+
total: 10,
|
|
42
|
+
translation,
|
|
43
|
+
viewSize,
|
|
44
|
+
windowSize: 4,
|
|
45
|
+
loop: true
|
|
46
|
+
});
|
|
47
|
+
return range;
|
|
48
|
+
});
|
|
49
|
+
const expected = hook.result.current.value;
|
|
50
|
+
expect(expected).toMatchInlineSnapshot(`
|
|
51
|
+
{
|
|
52
|
+
"negativeRange": [
|
|
53
|
+
8,
|
|
54
|
+
9,
|
|
55
|
+
],
|
|
56
|
+
"positiveRange": [
|
|
57
|
+
0,
|
|
58
|
+
2,
|
|
59
|
+
],
|
|
60
|
+
}
|
|
61
|
+
`);
|
|
62
|
+
});
|
|
63
|
+
it("should shows the increased range of the list when the loop is false and swiped the carousel.", async () => {
|
|
64
|
+
const slide0hook = (0, _reactHooks.renderHook)(() => {
|
|
65
|
+
const translation = (0, _reactNativeReanimated.useSharedValue)(-0 * viewSize);
|
|
66
|
+
const range = (0, _useVisibleRanges.useVisibleRanges)({
|
|
67
|
+
total: 10,
|
|
68
|
+
translation,
|
|
69
|
+
viewSize,
|
|
70
|
+
windowSize: 4,
|
|
71
|
+
loop: false
|
|
72
|
+
});
|
|
73
|
+
return range;
|
|
74
|
+
}).result.current.value;
|
|
75
|
+
const slide1hook = (0, _reactHooks.renderHook)(() => {
|
|
76
|
+
const translation = (0, _reactNativeReanimated.useSharedValue)(-1 * viewSize);
|
|
77
|
+
const range = (0, _useVisibleRanges.useVisibleRanges)({
|
|
78
|
+
total: 10,
|
|
79
|
+
translation,
|
|
80
|
+
viewSize,
|
|
81
|
+
windowSize: 4,
|
|
82
|
+
loop: false
|
|
83
|
+
});
|
|
84
|
+
return range;
|
|
85
|
+
}).result.current.value;
|
|
86
|
+
const slide2hook = (0, _reactHooks.renderHook)(() => {
|
|
87
|
+
const translation = (0, _reactNativeReanimated.useSharedValue)(-2 * viewSize);
|
|
88
|
+
const range = (0, _useVisibleRanges.useVisibleRanges)({
|
|
89
|
+
total: 10,
|
|
90
|
+
translation,
|
|
91
|
+
viewSize,
|
|
92
|
+
windowSize: 4,
|
|
93
|
+
loop: false
|
|
94
|
+
});
|
|
95
|
+
return range;
|
|
96
|
+
}).result.current.value;
|
|
97
|
+
const slide3hook = (0, _reactHooks.renderHook)(() => {
|
|
98
|
+
const translation = (0, _reactNativeReanimated.useSharedValue)(-3 * viewSize);
|
|
99
|
+
const range = (0, _useVisibleRanges.useVisibleRanges)({
|
|
100
|
+
total: 10,
|
|
101
|
+
translation,
|
|
102
|
+
viewSize,
|
|
103
|
+
windowSize: 4,
|
|
104
|
+
loop: false
|
|
105
|
+
});
|
|
106
|
+
return range;
|
|
107
|
+
}).result.current.value; // [0,3] Display the 0,1,2,3 items.
|
|
108
|
+
|
|
109
|
+
expect(slide0hook).toMatchInlineSnapshot(`
|
|
110
|
+
{
|
|
111
|
+
"negativeRange": [
|
|
112
|
+
-3,
|
|
113
|
+
0,
|
|
114
|
+
],
|
|
115
|
+
"positiveRange": [
|
|
116
|
+
0,
|
|
117
|
+
3,
|
|
118
|
+
],
|
|
119
|
+
}
|
|
120
|
+
`); // [1,4] Display the 1,2,3,4 items.
|
|
121
|
+
|
|
122
|
+
expect(slide1hook).toMatchInlineSnapshot(`
|
|
123
|
+
{
|
|
124
|
+
"negativeRange": [
|
|
125
|
+
-2,
|
|
126
|
+
1,
|
|
127
|
+
],
|
|
128
|
+
"positiveRange": [
|
|
129
|
+
1,
|
|
130
|
+
4,
|
|
131
|
+
],
|
|
132
|
+
}
|
|
133
|
+
`); // [2,5] Display the 2,3,4,5 items.
|
|
134
|
+
|
|
135
|
+
expect(slide2hook).toMatchInlineSnapshot(`
|
|
136
|
+
{
|
|
137
|
+
"negativeRange": [
|
|
138
|
+
-1,
|
|
139
|
+
2,
|
|
140
|
+
],
|
|
141
|
+
"positiveRange": [
|
|
142
|
+
2,
|
|
143
|
+
5,
|
|
144
|
+
],
|
|
145
|
+
}
|
|
146
|
+
`); // [3.6] Display the 3,4,5,6 items.
|
|
147
|
+
|
|
148
|
+
expect(slide3hook).toMatchInlineSnapshot(`
|
|
149
|
+
{
|
|
150
|
+
"negativeRange": [
|
|
151
|
+
0,
|
|
152
|
+
3,
|
|
153
|
+
],
|
|
154
|
+
"positiveRange": [
|
|
155
|
+
3,
|
|
156
|
+
6,
|
|
157
|
+
],
|
|
158
|
+
}
|
|
159
|
+
`);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
//# sourceMappingURL=useVisibleRanges.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useVisibleRanges.test.tsx"],"names":["viewSize","describe","it","hook","translation","range","total","windowSize","loop","expected","result","current","value","expect","toMatchInlineSnapshot","slide0hook","slide1hook","slide2hook","slide3hook"],"mappings":";;AAAA;;AAEA;;AAEA;;AAEA,MAAMA,QAAQ,GAAG,GAAjB;AAEAC,QAAQ,CAAC,kBAAD,EAAqB,MAAM;AACjCC,EAAAA,EAAE,CAAC,8DAAD,EAAiE,YAAY;AAC7E,UAAMC,IAAI,GAAG,4BAAW,MAAM;AAC5B,YAAMC,WAAW,GAAG,2CAAe,CAAC,CAAhB,CAApB;AACA,YAAMC,KAAK,GAAG,wCAAiB;AAC7BC,QAAAA,KAAK,EAAE,EADsB;AAE7BF,QAAAA,WAF6B;AAG7BJ,QAAAA,QAH6B;AAI7BO,QAAAA,UAAU,EAAE,CAJiB;AAK7BC,QAAAA,IAAI,EAAE;AALuB,OAAjB,CAAd;AAQA,aAAOH,KAAP;AACD,KAXY,CAAb;AAaA,UAAMI,QAAQ,GAAGN,IAAI,CAACO,MAAL,CAAYC,OAAZ,CAAoBC,KAArC;AAEAC,IAAAA,MAAM,CAACJ,QAAD,CAAN,CAAiBK,qBAAjB,CAAwC;AAC5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAXI;AAYD,GA5BC,CAAF;AA8BAZ,EAAAA,EAAE,CAAC,iFAAD,EAAoF,YAAY;AAChG,UAAMC,IAAI,GAAG,4BAAW,MAAM;AAC5B,YAAMC,WAAW,GAAG,2CAAe,CAAC,CAAhB,CAApB;AACA,YAAMC,KAAK,GAAG,wCAAiB;AAC7BC,QAAAA,KAAK,EAAE,EADsB;AAE7BF,QAAAA,WAF6B;AAG7BJ,QAAAA,QAH6B;AAI7BO,QAAAA,UAAU,EAAE,CAJiB;AAK7BC,QAAAA,IAAI,EAAE;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AE,EADsB;AAE7BF,QAAAA,WAF6B;AAG7BJ,QAAAA,QAH6B;AAI7BO,QAAAA,UAAU,EAAE,CAJiB;AAK7BC,QAAAA,IAAI,EAAE;AALuB,OAAjB,CAAd;AAQA,aAAOH,KAAP;AACD,KAXkB,EAWhBK,MAXgB,CAWTC,OAXS,CAWDC,KAXlB;AAaA,UAAMM,UAAU,GAAG,4BAAW,MAAM;AAClC,YAAMd,WAAW,GAAG,2CAAe,CAAC,CAAD,GAAKJ,QAApB,CAApB;AACA,YAAMK,KAAK,GAAG,wCAAiB;AAC7BC,QAAAA,KAAK,EAAE,EADsB;AAE7BF,QAAAA,WAF6B;AAG7BJ,QAAAA,QAH6B;AAI7BO,QAAAA,UAAU,EAAE,CAJiB;AAK7BC,QAAAA,IAAI,EAAE;AALuB,OAAjB,CAAd;AAQA,aAAOH,KAAP;AACD,KAXkB,EAWhBK,MAXgB,CAWTC,OAXS,CAWDC,KAXlB,CAxC6G,CAqD7G;;AACAC,IAAAA,MAAM,CAACE,UAAD,CAAN,CAAmBD,qBAAnB,CAA0C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAXI,EAtD6G,CAmE7G;;AACAD,IAAAA,MAAM,CAACG,UAAD,CAAN,CAAmBF,qBAAnB,CAA0C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAXI,EApE6G,CAiF7G;;AACAD,IAAAA,MAAM,CAACI,UAAD,CAAN,CAAmBH,qBAAnB,CAA0C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAXI,EAlF6G,CA+F7G;;AACAD,IAAAA,MAAM,CAACK,UAAD,CAAN,CAAmBJ,qBAAnB,CAA0C;AAC9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAXI;AAYD,GA5GC,CAAF;AA6GD,CA1KO,CAAR","sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\n\nimport { renderHook } from \"@testing-library/react-hooks\";\n\nimport { useVisibleRanges } from \"./useVisibleRanges\";\n\nconst viewSize = 393;\n\ndescribe(\"useVisibleRanges\", () => {\n it(\"should only display the front of the list when loop is false\", async () => {\n const hook = renderHook(() => {\n const translation = useSharedValue(-0);\n const range = useVisibleRanges({\n total: 10,\n translation,\n viewSize,\n windowSize: 4,\n loop: false,\n });\n\n return range;\n });\n\n const expected = hook.result.current.value;\n\n expect(expected).toMatchInlineSnapshot(`\n {\n \"negativeRange\": [\n -3,\n 0,\n ],\n \"positiveRange\": [\n 0,\n 3,\n ],\n }\n `);\n });\n\n it(\"should display the rear of the list and the front of the list when loop is true\", async () => {\n const hook = renderHook(() => {\n const translation = useSharedValue(-0);\n const range = useVisibleRanges({\n total: 10,\n translation,\n viewSize,\n windowSize: 4,\n loop: true,\n });\n\n return range;\n });\n\n const expected = hook.result.current.value;\n\n expect(expected).toMatchInlineSnapshot(`\n {\n \"negativeRange\": [\n 8,\n 9,\n ],\n \"positiveRange\": [\n 0,\n 2,\n ],\n }\n `);\n });\n\n it(\"should shows the increased range of the list when the loop is false and swiped the carousel.\", async () => {\n const slide0hook = renderHook(() => {\n const translation = useSharedValue(-0 * viewSize);\n const range = useVisibleRanges({\n total: 10,\n translation,\n viewSize,\n windowSize: 4,\n loop: false,\n });\n\n return range;\n }).result.current.value;\n\n const slide1hook = renderHook(() => {\n const translation = useSharedValue(-1 * viewSize);\n const range = useVisibleRanges({\n total: 10,\n translation,\n viewSize,\n windowSize: 4,\n loop: false,\n });\n\n return range;\n }).result.current.value;\n\n const slide2hook = renderHook(() => {\n const translation = useSharedValue(-2 * viewSize);\n const range = useVisibleRanges({\n total: 10,\n translation,\n viewSize,\n windowSize: 4,\n loop: false,\n });\n\n return range;\n }).result.current.value;\n\n const slide3hook = renderHook(() => {\n const translation = useSharedValue(-3 * viewSize);\n const range = useVisibleRanges({\n total: 10,\n translation,\n viewSize,\n windowSize: 4,\n loop: false,\n });\n\n return range;\n }).result.current.value;\n\n // [0,3] Display the 0,1,2,3 items.\n expect(slide0hook).toMatchInlineSnapshot(`\n {\n \"negativeRange\": [\n -3,\n 0,\n ],\n \"positiveRange\": [\n 0,\n 3,\n ],\n }\n `);\n\n // [1,4] Display the 1,2,3,4 items.\n expect(slide1hook).toMatchInlineSnapshot(`\n {\n \"negativeRange\": [\n -2,\n 1,\n ],\n \"positiveRange\": [\n 1,\n 4,\n ],\n }\n `);\n\n // [2,5] Display the 2,3,4,5 items.\n expect(slide2hook).toMatchInlineSnapshot(`\n {\n \"negativeRange\": [\n -1,\n 2,\n ],\n \"positiveRange\": [\n 2,\n 5,\n ],\n }\n `);\n\n // [3.6] Display the 3,4,5,6 items.\n expect(slide3hook).toMatchInlineSnapshot(`\n {\n \"negativeRange\": [\n 0,\n 3,\n ],\n \"positiveRange\": [\n 3,\n 6,\n ],\n }\n `);\n });\n});\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.tsx"],"names":["Carousel"],"mappings":";;;;;;;AAAA;;;;
|
|
1
|
+
{"version":3,"sources":["index.tsx"],"names":["Carousel"],"mappings":";;;;;;;AAAA;;;;eAWeA,iB","sourcesContent":["import Carousel from \"./components/Carousel\";\n\nexport type {\n TCarouselProps,\n ICarouselInstance,\n IComputedDirectionTypes,\n CarouselRenderItem,\n} from \"./types\";\nexport type { TAnimationStyle } from \"./components/BaseLayout\";\nexport type { ILayoutConfig } from \"./layouts/stack\";\n\nexport default Carousel;\n"]}
|
package/lib/commonjs/utils/{computeNewIndexWhenDataChanges.js → compute-offset-if-data-changed.js}
RENAMED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
6
|
+
exports.computeOffsetIfDataChanged = computeOffsetIfDataChanged;
|
|
7
7
|
exports.omitZero = omitZero;
|
|
8
8
|
|
|
9
9
|
function omitZero(a, b) {
|
|
@@ -13,7 +13,7 @@ function omitZero(a, b) {
|
|
|
13
13
|
return b;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
function
|
|
16
|
+
function computeOffsetIfDataChanged(params) {
|
|
17
17
|
"worklet";
|
|
18
18
|
|
|
19
19
|
const {
|
|
@@ -49,4 +49,4 @@ function computeNewIndexWhenDataChanges(params) {
|
|
|
49
49
|
|
|
50
50
|
return handlerOffset;
|
|
51
51
|
}
|
|
52
|
-
//# sourceMappingURL=
|
|
52
|
+
//# sourceMappingURL=compute-offset-if-data-changed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-data-changed.ts"],"names":["omitZero","a","b","computeOffsetIfDataChanged","params","direction","handlerOffset","_handlerOffset","size","previousLength","currentLength","positionIndex","round","isPositive","Math","abs","parseInt","String","prevOffset","prevIndex","changedLength","changedOffset"],"mappings":";;;;;;;;AAAO,SAASA,QAAT,CAAkBC,CAAlB,EAA6BC,CAA7B,EAAwC;AAC7C;;AACA,MAAID,CAAC,KAAK,CAAV,EACE,OAAO,CAAP;AAEF,SAAOC,CAAP;AACD;;AAEM,SAASC,0BAAT,CAAoCC,MAApC,EAMJ;AACD;;AACA,QAAM;AAAEC,IAAAA,SAAF;AAAaC,IAAAA,aAAa,EAAEC,cAA5B;AAA4CC,IAAAA,IAA5C;AAAkDC,IAAAA,cAAlD;AAAkEC,IAAAA;AAAlE,MAAoFN,MAA1F;AAEA,MAAIE,aAAa,GAAGC,cAApB;AACA,MAAII,aAAJ;AACA,MAAIC,KAAJ;AAEA,QAAMC,UAAU,GAAGR,SAAS,GAAG,CAA/B;;AAEA,MAAIQ,UAAJ,EAAgB;AACdF,IAAAA,aAAa,GAAIG,IAAI,CAACC,GAAL,CAAST,aAAT,CAAD,GAA4BE,IAA5C;AACAI,IAAAA,KAAK,GAAGI,QAAQ,CAACC,MAAM,CAACjB,QAAQ,CAACS,cAAD,EAAiBE,aAAa,GAAGF,cAAjC,CAAT,CAAP,CAAhB;AACD,GAHD,MAIK;AACHE,IAAAA,aAAa,GAAG,CAACG,IAAI,CAACC,GAAL,CAAST,aAAT,IAA0BE,IAA3B,IAAmCA,IAAnD;AACAI,IAAAA,KAAK,GAAGI,QAAQ,CAACC,MAAM,CAACjB,QAAQ,CAACS,cAAD,EAAiBE,aAAa,GAAGF,cAAjC,CAAT,CAAP,CAAR,GAA6E,CAArF;AACD;;AAED,QAAMS,UAAU,GAAGlB,QAAQ,CAACS,cAAD,EAAiBE,aAAa,GAAGF,cAAjC,CAA3B;AACA,QAAMU,SAAS,GAAGN,UAAU,GAAGK,UAAH,GAAgBT,cAAc,GAAGS,UAAjB,GAA8B,CAA1E;AACA,QAAME,aAAa,GAAGR,KAAK,IAAIF,aAAa,GAAGD,cAApB,CAA3B;AACA,QAAMY,aAAa,GAAGD,aAAa,GAAGZ,IAAtC;;AACA,MAAIW,SAAS,GAAGT,aAAa,GAAG,CAA5B,IAAiCA,aAAa,GAAGD,cAArD,EAAqE;AACnE,QAAII,UAAJ,EACEP,aAAa,GAAG,CAACI,aAAa,GAAG,CAAjB,IAAsBF,IAAtB,GAA6BH,SAA7C,CADF,KAIEC,aAAa,GAAG,CAACI,aAAa,GAAG,CAAjB,IAAsBF,IAAtB,GAA6B,CAAC,CAA9C;AACH,GAND,MAOK;AACHF,IAAAA,aAAa,IAAIe,aAAa,GAAGhB,SAAjC;AACD;;AAED,SAAOC,aAAP;AACD","sourcesContent":["export function omitZero(a: number, b: number) {\n \"worklet\";\n if (a === 0)\n return 0;\n\n return b;\n}\n\nexport function computeOffsetIfDataChanged(params: {\n direction: number\n handlerOffset: number\n size: number\n previousLength: number\n currentLength: number\n}) {\n \"worklet\";\n const { direction, handlerOffset: _handlerOffset, size, previousLength, currentLength } = params;\n\n let handlerOffset = _handlerOffset;\n let positionIndex;\n let round;\n\n const isPositive = direction < 0;\n\n if (isPositive) {\n positionIndex = (Math.abs(handlerOffset)) / size;\n round = parseInt(String(omitZero(previousLength, positionIndex / previousLength)));\n }\n else {\n positionIndex = (Math.abs(handlerOffset) - size) / size;\n round = parseInt(String(omitZero(previousLength, positionIndex / previousLength))) + 1;\n }\n\n const prevOffset = omitZero(previousLength, positionIndex % previousLength);\n const prevIndex = isPositive ? prevOffset : previousLength - prevOffset - 1;\n const changedLength = round * (currentLength - previousLength);\n const changedOffset = changedLength * size;\n if (prevIndex > currentLength - 1 && currentLength < previousLength) {\n if (isPositive)\n handlerOffset = (currentLength - 1) * size * direction;\n\n else\n handlerOffset = (currentLength - 1) * size * -1;\n }\n else {\n handlerOffset += changedOffset * direction;\n }\n\n return handlerOffset;\n}\n\n"]}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _computeOffsetIfDataChanged = require("./compute-offset-if-data-changed");
|
|
4
|
+
|
|
5
|
+
describe("computeOffsetIfDataChanged", () => {
|
|
6
|
+
const size = 634;
|
|
7
|
+
it("should return the correct values, if index is 0", () => {
|
|
8
|
+
const index = 0;
|
|
9
|
+
const result = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)({
|
|
10
|
+
direction: -1,
|
|
11
|
+
previousLength: 4,
|
|
12
|
+
currentLength: 6,
|
|
13
|
+
size,
|
|
14
|
+
handlerOffset: index * size
|
|
15
|
+
});
|
|
16
|
+
expect(result).toMatchInlineSnapshot("0");
|
|
17
|
+
});
|
|
18
|
+
it("should return the correct values, if index is 1", () => {
|
|
19
|
+
const index = 1;
|
|
20
|
+
const result = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)({
|
|
21
|
+
direction: -1,
|
|
22
|
+
previousLength: 4,
|
|
23
|
+
currentLength: 6,
|
|
24
|
+
size,
|
|
25
|
+
handlerOffset: index * size
|
|
26
|
+
});
|
|
27
|
+
expect(result).toMatchInlineSnapshot("634");
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
//# sourceMappingURL=compute-offset-if-data-changed.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-data-changed.test.ts"],"names":["describe","size","it","index","result","direction","previousLength","currentLength","handlerOffset","expect","toMatchInlineSnapshot"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,4BAAD,EAA+B,MAAM;AAC3C,QAAMC,IAAI,GAAG,GAAb;AACAC,EAAAA,EAAE,CAAC,iDAAD,EAAoD,MAAM;AAC1D,UAAMC,KAAK,GAAG,CAAd;AACA,UAAMC,MAAM,GAAG,4DAA2B;AACxCC,MAAAA,SAAS,EAAE,CAAC,CAD4B;AAExCC,MAAAA,cAAc,EAAE,CAFwB;AAGxCC,MAAAA,aAAa,EAAE,CAHyB;AAIxCN,MAAAA,IAJwC;AAKxCO,MAAAA,aAAa,EAAEL,KAAK,GAAGF;AALiB,KAA3B,CAAf;AAQAQ,IAAAA,MAAM,CAACL,MAAD,CAAN,CAAeM,qBAAf,CAAqC,GAArC;AACD,GAXC,CAAF;AAaAR,EAAAA,EAAE,CAAC,iDAAD,EAAoD,MAAM;AAC1D,UAAMC,KAAK,GAAG,CAAd;AACA,UAAMC,MAAM,GAAG,4DAA2B;AACxCC,MAAAA,SAAS,EAAE,CAAC,CAD4B;AAExCC,MAAAA,cAAc,EAAE,CAFwB;AAGxCC,MAAAA,aAAa,EAAE,CAHyB;AAIxCN,MAAAA,IAJwC;AAKxCO,MAAAA,aAAa,EAAEL,KAAK,GAAGF;AALiB,KAA3B,CAAf;AAQAQ,IAAAA,MAAM,CAACL,MAAD,CAAN,CAAeM,qBAAf,CAAqC,KAArC;AACD,GAXC,CAAF;AAYD,CA3BO,CAAR","sourcesContent":["import { computeOffsetIfDataChanged } from \"./compute-offset-if-data-changed\";\n\ndescribe(\"computeOffsetIfDataChanged\", () => {\n const size = 634;\n it(\"should return the correct values, if index is 0\", () => {\n const index = 0;\n const result = computeOffsetIfDataChanged({\n direction: -1,\n previousLength: 4,\n currentLength: 6,\n size,\n handlerOffset: index * size,\n });\n\n expect(result).toMatchInlineSnapshot(\"0\");\n });\n\n it(\"should return the correct values, if index is 1\", () => {\n const index = 1;\n const result = computeOffsetIfDataChanged({\n direction: -1,\n previousLength: 4,\n currentLength: 6,\n size,\n handlerOffset: index * size,\n });\n\n expect(result).toMatchInlineSnapshot(\"634\");\n });\n});\n"]}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.computeOffsetIfSizeChanged = computeOffsetIfSizeChanged;
|
|
7
|
+
|
|
8
|
+
function computeOffsetIfSizeChanged(params) {
|
|
9
|
+
"worklet";
|
|
10
|
+
|
|
11
|
+
const {
|
|
12
|
+
handlerOffset,
|
|
13
|
+
prevSize,
|
|
14
|
+
size
|
|
15
|
+
} = params;
|
|
16
|
+
return handlerOffset / prevSize * size;
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=compute-offset-if-size-changed.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-size-changed.ts"],"names":["computeOffsetIfSizeChanged","params","handlerOffset","prevSize","size"],"mappings":";;;;;;;AAAO,SAASA,0BAAT,CAAoCC,MAApC,EAIJ;AACD;;AACA,QAAM;AAAEC,IAAAA,aAAF;AAAiBC,IAAAA,QAAjB;AAA2BC,IAAAA;AAA3B,MAAoCH,MAA1C;AAEA,SAAOC,aAAa,GAAGC,QAAhB,GAA2BC,IAAlC;AACD","sourcesContent":["export function computeOffsetIfSizeChanged(params: {\n handlerOffset: number\n prevSize: number\n size: number\n}) {\n \"worklet\";\n const { handlerOffset, prevSize, size } = params;\n\n return handlerOffset / prevSize * size;\n}\n\n"]}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _computeOffsetIfSizeChanged = require("./compute-offset-if-size-changed");
|
|
4
|
+
|
|
5
|
+
describe("computeOffsetIfSizeChanged", () => {
|
|
6
|
+
it("[CASE 1] should return the correct values when size does not change", () => {
|
|
7
|
+
const prevIndex = 1;
|
|
8
|
+
const prevSize = 500;
|
|
9
|
+
const size = 500;
|
|
10
|
+
const handlerOffset = prevIndex * size;
|
|
11
|
+
const result = (0, _computeOffsetIfSizeChanged.computeOffsetIfSizeChanged)({
|
|
12
|
+
prevSize,
|
|
13
|
+
size,
|
|
14
|
+
handlerOffset
|
|
15
|
+
});
|
|
16
|
+
const finallyIndex = result / size;
|
|
17
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
18
|
+
});
|
|
19
|
+
it("[CASE 2] should return the correct values when size changes from 500 to 400", () => {
|
|
20
|
+
const prevIndex = 1;
|
|
21
|
+
const prevSize = 500;
|
|
22
|
+
const size = 400;
|
|
23
|
+
const handlerOffset = prevIndex * prevSize;
|
|
24
|
+
const result = (0, _computeOffsetIfSizeChanged.computeOffsetIfSizeChanged)({
|
|
25
|
+
prevSize,
|
|
26
|
+
size,
|
|
27
|
+
handlerOffset
|
|
28
|
+
});
|
|
29
|
+
const finallyIndex = result / size;
|
|
30
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
31
|
+
});
|
|
32
|
+
it("[CASE 3] should return the correct values when size changes from 500 to 499", () => {
|
|
33
|
+
const prevIndex = 1;
|
|
34
|
+
const prevSize = 500;
|
|
35
|
+
const size = 499;
|
|
36
|
+
const handlerOffset = prevIndex * prevSize;
|
|
37
|
+
const result = (0, _computeOffsetIfSizeChanged.computeOffsetIfSizeChanged)({
|
|
38
|
+
prevSize,
|
|
39
|
+
size,
|
|
40
|
+
handlerOffset
|
|
41
|
+
});
|
|
42
|
+
const finallyIndex = result / size;
|
|
43
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
44
|
+
});
|
|
45
|
+
it("[CASE 4] should return the correct values when size changes from 500 to 501", () => {
|
|
46
|
+
const prevIndex = 1;
|
|
47
|
+
const prevSize = 500;
|
|
48
|
+
const size = 501;
|
|
49
|
+
const handlerOffset = prevIndex * prevSize;
|
|
50
|
+
const result = (0, _computeOffsetIfSizeChanged.computeOffsetIfSizeChanged)({
|
|
51
|
+
prevSize,
|
|
52
|
+
size,
|
|
53
|
+
handlerOffset
|
|
54
|
+
});
|
|
55
|
+
const finallyIndex = result / size;
|
|
56
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
57
|
+
});
|
|
58
|
+
it("[CASE 5] should return the correct values when size changes from 224 to 524", () => {
|
|
59
|
+
const prevIndex = 1;
|
|
60
|
+
const prevSize = 224;
|
|
61
|
+
const size = 524;
|
|
62
|
+
const handlerOffset = prevIndex * prevSize;
|
|
63
|
+
const result = (0, _computeOffsetIfSizeChanged.computeOffsetIfSizeChanged)({
|
|
64
|
+
prevSize,
|
|
65
|
+
size,
|
|
66
|
+
handlerOffset
|
|
67
|
+
});
|
|
68
|
+
const finallyIndex = result / size;
|
|
69
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
//# sourceMappingURL=compute-offset-if-size-changed.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-size-changed.test.ts"],"names":["describe","it","prevIndex","prevSize","size","handlerOffset","result","finallyIndex","expect","toEqual"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,4BAAD,EAA+B,MAAM;AAC3CC,EAAAA,EAAE,CAAC,qEAAD,EAAwE,MAAM;AAC9E,UAAMC,SAAS,GAAG,CAAlB;AACA,UAAMC,QAAQ,GAAG,GAAjB;AACA,UAAMC,IAAI,GAAG,GAAb;AACA,UAAMC,aAAa,GAAGH,SAAS,GAAGE,IAAlC;AACA,UAAME,MAAM,GAAG,4DAA2B;AACxCH,MAAAA,QADwC;AAExCC,MAAAA,IAFwC;AAGxCC,MAAAA;AAHwC,KAA3B,CAAf;AAMA,UAAME,YAAY,GAAGD,MAAM,GAAGF,IAA9B;AACAI,IAAAA,MAAM,CAACD,YAAD,CAAN,CAAqBE,OAArB,CAA6BP,S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AAA,MAAM,CAACD,YAAD,CAAN,CAAqBE,OAArB,CAA6BP,SAA7B;AACD,GAbC,CAAF;AAeAD,EAAAA,EAAE,CAAC,6EAAD,EAAgF,MAAM;AACtF,UAAMC,SAAS,GAAG,CAAlB;AACA,UAAMC,QAAQ,GAAG,GAAjB;AACA,UAAMC,IAAI,GAAG,GAAb;AACA,UAAMC,aAAa,GAAGH,SAAS,GAAGC,QAAlC;AACA,UAAMG,MAAM,GAAG,4DAA2B;AACxCH,MAAAA,QADwC;AAExCC,MAAAA,IAFwC;AAGxCC,MAAAA;AAHwC,KAA3B,CAAf;AAMA,UAAME,YAAY,GAAGD,MAAM,GAAGF,IAA9B;AACAI,IAAAA,MAAM,CAACD,YAAD,CAAN,CAAqBE,OAArB,CAA6BP,SAA7B;AACD,GAbC,CAAF;AAcD,CA3EO,CAAR","sourcesContent":["import { computeOffsetIfSizeChanged } from \"./compute-offset-if-size-changed\";\n\ndescribe(\"computeOffsetIfSizeChanged\", () => {\n it(\"[CASE 1] should return the correct values when size does not change\", () => {\n const prevIndex = 1;\n const prevSize = 500;\n const size = 500;\n const handlerOffset = prevIndex * size;\n const result = computeOffsetIfSizeChanged({\n prevSize,\n size,\n handlerOffset,\n });\n\n const finallyIndex = result / size;\n expect(finallyIndex).toEqual(prevIndex);\n });\n\n it(\"[CASE 2] should return the correct values when size changes from 500 to 400\", () => {\n const prevIndex = 1;\n const prevSize = 500;\n const size = 400;\n const handlerOffset = prevIndex * prevSize;\n const result = computeOffsetIfSizeChanged({\n prevSize,\n size,\n handlerOffset,\n });\n\n const finallyIndex = result / size;\n expect(finallyIndex).toEqual(prevIndex);\n });\n\n it(\"[CASE 3] should return the correct values when size changes from 500 to 499\", () => {\n const prevIndex = 1;\n const prevSize = 500;\n const size = 499;\n const handlerOffset = prevIndex * prevSize;\n const result = computeOffsetIfSizeChanged({\n prevSize,\n size,\n handlerOffset,\n });\n\n const finallyIndex = result / size;\n expect(finallyIndex).toEqual(prevIndex);\n });\n\n it(\"[CASE 4] should return the correct values when size changes from 500 to 501\", () => {\n const prevIndex = 1;\n const prevSize = 500;\n const size = 501;\n const handlerOffset = prevIndex * prevSize;\n const result = computeOffsetIfSizeChanged({\n prevSize,\n size,\n handlerOffset,\n });\n\n const finallyIndex = result / size;\n expect(finallyIndex).toEqual(prevIndex);\n });\n\n it(\"[CASE 5] should return the correct values when size changes from 224 to 524\", () => {\n const prevIndex = 1;\n const prevSize = 224;\n const size = 524;\n const handlerOffset = prevIndex * prevSize;\n const result = computeOffsetIfSizeChanged({\n prevSize,\n size,\n handlerOffset,\n });\n\n const finallyIndex = result / size;\n expect(finallyIndex).toEqual(prevIndex);\n });\n});\n"]}
|
|
@@ -5,12 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.handlerOffsetDirection = handlerOffsetDirection;
|
|
7
7
|
|
|
8
|
-
function handlerOffsetDirection(handlerOffset) {
|
|
8
|
+
function handlerOffsetDirection(handlerOffset, fixedDirection) {
|
|
9
9
|
"worklet";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return
|
|
11
|
+
if (fixedDirection === "negative") return -1;
|
|
12
|
+
if (fixedDirection === "positive") return 1;
|
|
13
|
+
if (handlerOffset.value === 0) return -1;
|
|
14
|
+
return Math.sign(handlerOffset.value);
|
|
15
15
|
}
|
|
16
16
|
//# sourceMappingURL=handleroffset-direction.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["handleroffset-direction.ts"],"names":["handlerOffsetDirection","handlerOffset","
|
|
1
|
+
{"version":3,"sources":["handleroffset-direction.ts"],"names":["handlerOffsetDirection","handlerOffset","fixedDirection","value","Math","sign"],"mappings":";;;;;;;AAIO,SAASA,sBAAT,CAAgCC,aAAhC,EAAoEC,cAApE,EAA+H;AACpI;;AAEA,MAAIA,cAAc,KAAK,UAAvB,EACE,OAAO,CAAC,CAAR;AAEF,MAAIA,cAAc,KAAK,UAAvB,EACE,OAAO,CAAP;AAEF,MAAID,aAAa,CAACE,KAAd,KAAwB,CAA5B,EACE,OAAO,CAAC,CAAR;AAEF,SAAOC,IAAI,CAACC,IAAL,CAAUJ,aAAa,CAACE,KAAxB,CAAP;AACD","sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nimport type { TCarouselProps } from \"../types\";\n\nexport function handlerOffsetDirection(handlerOffset: SharedValue<number>, fixedDirection?: TCarouselProps[\"fixedDirection\"]): -1 | 1 {\n \"worklet\";\n\n if (fixedDirection === \"negative\")\n return -1;\n\n if (fixedDirection === \"positive\")\n return 1;\n\n if (handlerOffset.value === 0)\n return -1;\n\n return Math.sign(handlerOffset.value) as -1 | 1;\n}\n"]}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _reactNativeReanimated = require("react-native-reanimated");
|
|
4
|
+
|
|
5
|
+
var _reactHooks = require("@testing-library/react-hooks");
|
|
6
|
+
|
|
7
|
+
var _handleroffsetDirection = require("./handleroffset-direction");
|
|
8
|
+
|
|
9
|
+
describe("handlerOffsetDirection", () => {
|
|
10
|
+
it("should return -1 when default value equals to zero", () => {
|
|
11
|
+
const result = (0, _reactHooks.renderHook)(() => {
|
|
12
|
+
const handlerOffsetAnimVal = (0, _reactNativeReanimated.useSharedValue)(0);
|
|
13
|
+
return (0, _handleroffsetDirection.handlerOffsetDirection)(handlerOffsetAnimVal);
|
|
14
|
+
});
|
|
15
|
+
expect(result.result.current).toBe(-1);
|
|
16
|
+
});
|
|
17
|
+
it("should return 1 when default value is greater than zero", () => {
|
|
18
|
+
const result = (0, _reactHooks.renderHook)(() => {
|
|
19
|
+
const handlerOffsetAnimVal = (0, _reactNativeReanimated.useSharedValue)(1);
|
|
20
|
+
return (0, _handleroffsetDirection.handlerOffsetDirection)(handlerOffsetAnimVal);
|
|
21
|
+
});
|
|
22
|
+
expect(result.result.current).toBe(1);
|
|
23
|
+
});
|
|
24
|
+
it("should return -1 when default value is less than zero", () => {
|
|
25
|
+
const result = (0, _reactHooks.renderHook)(() => {
|
|
26
|
+
const handlerOffsetAnimVal = (0, _reactNativeReanimated.useSharedValue)(-1);
|
|
27
|
+
return (0, _handleroffsetDirection.handlerOffsetDirection)(handlerOffsetAnimVal);
|
|
28
|
+
});
|
|
29
|
+
expect(result.result.current).toBe(-1);
|
|
30
|
+
});
|
|
31
|
+
it("should return 1 when default value equals to zero and fixedDirection is negative", () => {
|
|
32
|
+
const result = (0, _reactHooks.renderHook)(() => {
|
|
33
|
+
const handlerOffsetAnimVal = (0, _reactNativeReanimated.useSharedValue)(-1);
|
|
34
|
+
return (0, _handleroffsetDirection.handlerOffsetDirection)(handlerOffsetAnimVal, "positive");
|
|
35
|
+
});
|
|
36
|
+
expect(result.result.current).toBe(1);
|
|
37
|
+
});
|
|
38
|
+
it("should return -1 when default value is greater than zero and fixedDirection is negative", () => {
|
|
39
|
+
const result = (0, _reactHooks.renderHook)(() => {
|
|
40
|
+
const handlerOffsetAnimVal = (0, _reactNativeReanimated.useSharedValue)(1);
|
|
41
|
+
return (0, _handleroffsetDirection.handlerOffsetDirection)(handlerOffsetAnimVal, "negative");
|
|
42
|
+
});
|
|
43
|
+
expect(result.result.current).toBe(-1);
|
|
44
|
+
});
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=handleroffset-direction.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["handleroffset-direction.test.ts"],"names":["describe","it","result","handlerOffsetAnimVal","expect","current","toBe"],"mappings":";;AAAA;;AAEA;;AAEA;;AAEAA,QAAQ,CAAC,wBAAD,EAA2B,MAAM;AACvCC,EAAAA,EAAE,CAAC,oDAAD,EAAuD,MAAM;AAC7D,UAAMC,MAAM,GAAG,4BAAW,MAAM;AAC9B,YAAMC,oBAAoB,GAAG,2CAAe,CAAf,CAA7B;AACA,aAAO,oDAAuBA,oBAAvB,CAAP;AACD,KAHc,CAAf;AAKAC,IA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AC,IAAAA,MAAM,CAACF,MAAM,CAACA,MAAP,CAAcG,OAAf,CAAN,CAA8BC,IAA9B,CAAmC,CAAC,CAApC;AACD,GAPC,CAAF;AAQD,CA7CO,CAAR","sourcesContent":["import { useSharedValue } from \"react-native-reanimated\";\n\nimport { renderHook } from \"@testing-library/react-hooks\";\n\nimport { handlerOffsetDirection } from \"./handleroffset-direction\";\n\ndescribe(\"handlerOffsetDirection\", () => {\n it(\"should return -1 when default value equals to zero\", () => {\n const result = renderHook(() => {\n const handlerOffsetAnimVal = useSharedValue(0);\n return handlerOffsetDirection(handlerOffsetAnimVal);\n });\n\n expect(result.result.current).toBe(-1);\n });\n\n it(\"should return 1 when default value is greater than zero\", () => {\n const result = renderHook(() => {\n const handlerOffsetAnimVal = useSharedValue(1);\n return handlerOffsetDirection(handlerOffsetAnimVal);\n });\n\n expect(result.result.current).toBe(1);\n });\n\n it(\"should return -1 when default value is less than zero\", () => {\n const result = renderHook(() => {\n const handlerOffsetAnimVal = useSharedValue(-1);\n return handlerOffsetDirection(handlerOffsetAnimVal);\n });\n\n expect(result.result.current).toBe(-1);\n });\n\n it(\"should return 1 when default value equals to zero and fixedDirection is negative\", () => {\n const result = renderHook(() => {\n const handlerOffsetAnimVal = useSharedValue(-1);\n return handlerOffsetDirection(handlerOffsetAnimVal, \"positive\");\n });\n\n expect(result.result.current).toBe(1);\n });\n\n it(\"should return -1 when default value is greater than zero and fixedDirection is negative\", () => {\n const result = renderHook(() => {\n const handlerOffsetAnimVal = useSharedValue(1);\n return handlerOffsetDirection(handlerOffsetAnimVal, \"negative\");\n });\n\n expect(result.result.current).toBe(-1);\n });\n});\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _computeOffsetIfDataChanged = require("./compute-offset-if-data-changed");
|
|
4
4
|
|
|
5
5
|
describe("should work as expected", () => {
|
|
6
6
|
const size = 375;
|
|
@@ -26,7 +26,7 @@ describe("should work as expected", () => {
|
|
|
26
26
|
|
|
27
27
|
it("The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.", async () => {
|
|
28
28
|
const currentIndex = 1;
|
|
29
|
-
const handlerOffset = (0,
|
|
29
|
+
const handlerOffset = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)(params({
|
|
30
30
|
currentIndex,
|
|
31
31
|
direction: "negative",
|
|
32
32
|
previousLength: 4,
|
|
@@ -35,7 +35,7 @@ describe("should work as expected", () => {
|
|
|
35
35
|
expect(handlerOffset / size).toBe(2 * positive);
|
|
36
36
|
});
|
|
37
37
|
it("The direction is negative, Changing length of data set from 4 to 3, the index remains original.", async () => {
|
|
38
|
-
const handlerOffset = (0,
|
|
38
|
+
const handlerOffset = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)(params({
|
|
39
39
|
currentIndex: 2,
|
|
40
40
|
direction: "negative",
|
|
41
41
|
previousLength: 4,
|
|
@@ -44,7 +44,7 @@ describe("should work as expected", () => {
|
|
|
44
44
|
expect(handlerOffset / size).toBe(1 * negative);
|
|
45
45
|
});
|
|
46
46
|
it("The direction is positive, Changing length of data set from 4 to 5, the index remains original.", async () => {
|
|
47
|
-
const handlerOffset = (0,
|
|
47
|
+
const handlerOffset = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)(params({
|
|
48
48
|
currentIndex: 3,
|
|
49
49
|
direction: "positive",
|
|
50
50
|
previousLength: 4,
|
|
@@ -53,7 +53,7 @@ describe("should work as expected", () => {
|
|
|
53
53
|
expect(handlerOffset / size).toBe(3 * positive);
|
|
54
54
|
});
|
|
55
55
|
it("The direction is negative, Changing length of data set from 4 to 5, the index remains original.", async () => {
|
|
56
|
-
const handlerOffset = (0,
|
|
56
|
+
const handlerOffset = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)(params({
|
|
57
57
|
currentIndex: 3,
|
|
58
58
|
direction: "negative",
|
|
59
59
|
previousLength: 4,
|
|
@@ -62,7 +62,7 @@ describe("should work as expected", () => {
|
|
|
62
62
|
expect(handlerOffset / size).toBe(4 * negative);
|
|
63
63
|
});
|
|
64
64
|
it("Changing length of data set from 0 to 3, the index remains original.", async () => {
|
|
65
|
-
const handlerOffset = (0,
|
|
65
|
+
const handlerOffset = (0, _computeOffsetIfDataChanged.computeOffsetIfDataChanged)(params({
|
|
66
66
|
currentIndex: 0,
|
|
67
67
|
direction: "positive",
|
|
68
68
|
previousLength: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.test.ts"],"names":["describe","size","positive","negative","params","currentIndex","direction","_direction","previousLength","currentLength","handlerOffset","it","expect","toBe"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,yBAAD,EAA4B,MAAM;AACxC,QAAMC,IAAI,GAAG,GAAb;AACA,QAAMC,QAAQ,GAAG,CAAC,CAAlB;AACA,QAAMC,QAAQ,GAAG,CAAjB;;AAEA,QAAMC,MAAM,GAAIA,MAAD,IAKT;AACJ,UAAM;AAAEC,MAAAA,YAAF;AAAgBC,MAAAA,SAAS,EAAEC,UAA3B;AAAuCC,MAAAA,cAAvC;AAAuDC,MAAAA;AAAvD,QAAyEL,MAA/E;AACA,UAAME,SAAS,GAAGC,UAAU,KAAK,UAAf,GAA4BJ,QAA5B,GAAuCD,QAAzD;AACA,WAAO;AACLI,MAAAA,SADK;AAELI,MAAAA,aAAa,EAAET,IAAI,GAAGI,YAAP,GAAsBC,SAFhC;AAGLL,MAAAA,IAHK;AAILO,MAAAA,cAJK;AAKLC,MAAAA;AALK,KAAP;AAOD,GAfD;;AAiBAE,EAAAA,EAAE,CAAC,qGAAD,EAAwG,YAAY;AACpH,UAAMN,YAAY,GAAG,CAArB;AACA,UAAMK,aAAa,GAAG,
|
|
1
|
+
{"version":3,"sources":["index.test.ts"],"names":["describe","size","positive","negative","params","currentIndex","direction","_direction","previousLength","currentLength","handlerOffset","it","expect","toBe"],"mappings":";;AAAA;;AAEAA,QAAQ,CAAC,yBAAD,EAA4B,M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tC;AACD,GATC,CAAF;AAWAQ,EAAAA,EAAE,CAAC,iGAAD,EAAoG,YAAY;AAChH,UAAMD,aAAa,GAAG,4DAA2BN,MAAM,CAAC;AACtDC,MAAAA,YAAY,EAAE,CADwC;AAEtDC,MAAAA,SAAS,EAAE,UAF2C;AAGtDE,MAAAA,cAAc,EAAE,CAHsC;AAItDC,MAAAA,aAAa,EAAE;AAJuC,KAAD,CAAjC,CAAtB;AAOAG,IAAAA,MAAM,CAACF,aAAa,GAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,IAAIX,QAAtC;AACD,GATC,CAAF;AAWAS,EAAAA,EAAE,CAAC,iGAAD,EAAoG,YAAY;AAChH,UAAMD,aAAa,GAAG,4DAA2BN,MAAM,CAAC;AACtDC,MAAAA,YAAY,EAAE,CADwC;AAEtDC,MAAAA,SAAS,EAAE,UAF2C;AAGtDE,MAAAA,cAAc,EAAE,CAHsC;AAItDC,MAAAA,aAAa,EAAE;AAJuC,KAAD,CAAjC,CAAtB;AAOAG,IAAAA,MAAM,CAACF,aAAa,GAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,IAAIV,QAAtC;AACD,GATC,CAAF;AAWAQ,EAAAA,EAAE,CAAC,sEAAD,EAAyE,YAAY;AACrF,UAAMD,aAAa,GAAG,4DAA2BN,MAAM,CAAC;AACtDC,MAAAA,YAAY,EAAE,CADwC;AAEtDC,MAAAA,SAAS,EAAE,UAF2C;AAGtDE,MAAAA,cAAc,EAAE,CAHsC;AAItDC,MAAAA,aAAa,EAAE;AAJuC,KAAD,CAAjC,CAAtB;AAOAG,IAAAA,MAAM,CAACF,aAAa,GAAGT,IAAjB,CAAN,CAA6BY,IAA7B,CAAkC,IAAIX,QAAtC;AACD,GATC,CAAF;AAUD,CA7EO,CAAR","sourcesContent":["import { computeOffsetIfDataChanged } from \"./compute-offset-if-data-changed\";\n\ndescribe(\"should work as expected\", () => {\n const size = 375;\n const positive = -1;\n const negative = 1;\n\n const params = (params: {\n direction: \"positive\" | \"negative\"\n currentIndex: number\n previousLength: number\n currentLength: number\n }) => {\n const { currentIndex, direction: _direction, previousLength, currentLength } = params;\n const direction = _direction === \"negative\" ? negative : positive;\n return {\n direction,\n handlerOffset: size * currentIndex * direction,\n size,\n previousLength,\n currentLength,\n };\n };\n\n it(\"The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.\", async () => {\n const currentIndex = 1;\n const handlerOffset = computeOffsetIfDataChanged(params({\n currentIndex,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(2 * positive);\n });\n\n it(\"The direction is negative, Changing length of data set from 4 to 3, the index remains original.\", async () => {\n const handlerOffset = computeOffsetIfDataChanged(params({\n currentIndex: 2,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(1 * negative);\n });\n\n it(\"The direction is positive, Changing length of data set from 4 to 5, the index remains original.\", async () => {\n const handlerOffset = computeOffsetIfDataChanged(params({\n currentIndex: 3,\n direction: \"positive\",\n previousLength: 4,\n currentLength: 5,\n }));\n\n expect(handlerOffset / size).toBe(3 * positive);\n });\n\n it(\"The direction is negative, Changing length of data set from 4 to 5, the index remains original.\", async () => {\n const handlerOffset = computeOffsetIfDataChanged(params({\n currentIndex: 3,\n direction: \"negative\",\n previousLength: 4,\n currentLength: 5,\n }));\n\n expect(handlerOffset / size).toBe(4 * negative);\n });\n\n it(\"Changing length of data set from 0 to 3, the index remains original.\", async () => {\n const handlerOffset = computeOffsetIfDataChanged(params({\n currentIndex: 0,\n direction: \"positive\",\n previousLength: 0,\n currentLength: 3,\n }));\n\n expect(handlerOffset / size).toBe(0 * positive);\n });\n});\n"]}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import Animated, {
|
|
3
|
-
import { LazyView } from "../components/LazyView";
|
|
4
|
-
import { useCheckMounted } from "../hooks/useCheckMounted";
|
|
2
|
+
import Animated, { useAnimatedStyle, useDerivedValue } from "react-native-reanimated";
|
|
5
3
|
import { useOffsetX } from "../hooks/useOffsetX";
|
|
6
4
|
import { CTX } from "../store";
|
|
7
5
|
export const BaseLayout = props => {
|
|
8
|
-
const mounted = useCheckMounted();
|
|
9
6
|
const {
|
|
10
7
|
handlerOffset,
|
|
11
8
|
index,
|
|
@@ -27,7 +24,6 @@ export const BaseLayout = props => {
|
|
|
27
24
|
}
|
|
28
25
|
} = context;
|
|
29
26
|
const size = vertical ? height : width;
|
|
30
|
-
const [shouldUpdate, setShouldUpdate] = React.useState(false);
|
|
31
27
|
let offsetXConfig = {
|
|
32
28
|
handlerOffset,
|
|
33
29
|
index,
|
|
@@ -55,13 +51,9 @@ export const BaseLayout = props => {
|
|
|
55
51
|
|
|
56
52
|
const x = useOffsetX(offsetXConfig, visibleRanges);
|
|
57
53
|
const animationValue = useDerivedValue(() => x.value / size, [x, size]);
|
|
58
|
-
const animatedStyle = useAnimatedStyle(() =>
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}, [index, mounted]);
|
|
62
|
-
useAnimatedReaction(() => visibleRanges.value, () => {
|
|
63
|
-
runOnJS(updateView)(visibleRanges.value.negativeRange, visibleRanges.value.positiveRange);
|
|
64
|
-
}, [visibleRanges.value]);
|
|
54
|
+
const animatedStyle = useAnimatedStyle(() => {
|
|
55
|
+
return animationStyle(x.value / size);
|
|
56
|
+
}, [animationStyle]);
|
|
65
57
|
return /*#__PURE__*/React.createElement(Animated.View, {
|
|
66
58
|
style: [{
|
|
67
59
|
width: width || "100%",
|
|
@@ -74,11 +66,9 @@ export const BaseLayout = props => {
|
|
|
74
66
|
* The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.
|
|
75
67
|
* */
|
|
76
68
|
,
|
|
77
|
-
testID: `__CAROUSEL_ITEM_${index}
|
|
78
|
-
}, /*#__PURE__*/React.createElement(LazyView, {
|
|
79
|
-
shouldUpdate: shouldUpdate
|
|
69
|
+
testID: `__CAROUSEL_ITEM_${index}__`
|
|
80
70
|
}, children({
|
|
81
71
|
animationValue
|
|
82
|
-
}))
|
|
72
|
+
}));
|
|
83
73
|
};
|
|
84
74
|
//# sourceMappingURL=BaseLayout.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["BaseLayout.tsx"],"names":["React","Animated","useAnimatedStyle","useDerivedValue","useOffsetX","CTX","BaseLayout","props","handlerOffset","index","children","visibleRanges","animationStyle","context","useContext","loop","dataLength","width","height","vertical","customConfig","mode","modeConfig","size","offsetXConfig","snapDirection","showLength","type","viewCount","x","animationValue","value","animatedStyle","position"],"mappings":"AAAA,OAAOA,KAAP,MAAkB,OAAlB;AAGA,OAAOC,QAAP,IACEC,gBADF,EAEEC,eAFF,QAGO,yBAHP;AAMA,SAASC,UAAT,QAA2B,qBAA3B;AAGA,SAASC,GAAT,QAAoB,UAApB;AAIA,OAAO,MAAMC,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,GAAGb,KAAK,CAACc,UAAN,CAAiBT,GAAjB,CAAhB;AACA,QAAM;AACJE,IAAAA,KAAK,EAAE;AACLQ,MAAAA,IADK;AAELC,MAAAA,UAFK;AAGLC,MAAAA,KAHK;AAILC,MAAAA,MAJK;AAKLC,MAAAA,QALK;AAMLC,MAAAA,YANK;AAOLC,MAAAA,IAPK;AAQLC,MAAAA;AARK;AADH,MAWFT,OAXJ;AAYA,QAAMU,IAAI,GAAGJ,QAAQ,GAAGD,MAAH,GAAYD,KAAjC;AAEA,MAAIO,aAAoB,GAAG;AACzBhB,IAAAA,aADyB;AAEzBC,IAAAA,KAFyB;AAGzBc,IAAAA,IAHyB;AAIzBP,IAAAA,UAJyB;AAKzBD,IAAAA,IALyB;AAMzB,QAAI,OAAOK,YAAP,KAAwB,UAAxB,GAAqCA,YAAY,EAAjD,GAAsD,EAA1D;AANyB,GAA3B;;AASA,MAAIC,IAAI,KAAK,kBAAb,EAAiC;AAC/B,UAAM;AAAEI,MAAAA,aAAF;AAAiBC,MAAAA;AAAjB,QAAgCJ,UAAtC;AAEAE,IAAAA,aAAa,GAAG;AACdhB,MAAAA,aADc;AAEdC,MAAAA,KAFc;AAGdc,MAAAA,IAHc;AAIdP,MAAAA,UAJc;AAKdD,MAAAA,IALc;AAMdY,MAAAA,IAAI,EAAEF,aAAa,KAAK,OAAlB,GAA4B,UAA5B,GAAyC,UANjC;AAOdG,MAAAA,SAAS,EAAEF;AAPG,KAAhB;AASD;;AAED,QAAMG,CAAC,GAAGzB,UAAU,CAACoB,aAAD,EAAgBb,aAAhB,CAApB;AACA,QAAMmB,cAAc,GAAG3B,eAAe,CAAC,MAAM0B,CAAC,CAACE,KAAF,GAAUR,IAAjB,EAAuB,CAACM,CAAD,EAAIN,IAAJ,CAAvB,CAAtC;AACA,QAAMS,aAAa,GAAG9B,gBAAgB,CACpC,MAAM;AACJ,WAAOU,cAAc,CAACiB,CAAC,CAACE,KAAF,GAAUR,IAAX,CAArB;AACD,GAHmC,EAIpC,CAACX,cAAD,CAJoC,CAAtC;AAOA,sBACE,oBAAC,QAAD,CAAU,IAAV;AACE,IAAA,KAAK,EAAE,CACL;AACEK,MAAAA,KAAK,EAAEA,KAAK,IAAI,MADlB;AAEEC,MAAAA,MAAM,EAAEA,MAAM,IAAI,MAFpB;AAGEe,MAAAA,QAAQ,EAAE;AAHZ,KADK,EAMLD,aANK;AAQP;AACN;AACA;AACA;AACA;AAbI;AAcE,IAAA,MAAM,EAAG,mBAAkBvB,KAAM;AAdnC,KAgBGC,QAAQ,CAAC;AAAEoB,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"]}
|