react-native-reanimated-carousel 4.0.0-alpha.1 → 4.0.0-alpha.3
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/lib/commonjs/components/rnr-demo.test.js +45 -0
- package/lib/commonjs/components/rnr-demo.test.js.map +1 -0
- 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/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/index.test.js +6 -6
- package/lib/commonjs/utils/index.test.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/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/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/index.test.js +6 -6
- package/lib/module/utils/index.test.js.map +1 -1
- package/lib/typescript/components/rnr-demo.test.d.ts +1 -0
- package/lib/typescript/hooks/useCommonVariables.test.d.ts +1 -0
- 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/package.json +9 -48
- package/src/components/rnr-demo.test.tsx +43 -0
- package/src/hooks/useCommonVariables.test.tsx +41 -0
- package/src/hooks/useCommonVariables.ts +35 -10
- 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/index.test.ts +6 -6
- package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js.map +0 -1
- package/lib/module/utils/computeNewIndexWhenDataChanges.js.map +0 -1
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
import { useCommonVariables } from "./useCommonVariables";
|
|
3
|
+
const input = {
|
|
4
|
+
vertical: false,
|
|
5
|
+
width: 700,
|
|
6
|
+
height: 350,
|
|
7
|
+
loop: true,
|
|
8
|
+
enabled: true,
|
|
9
|
+
testID: "xxx",
|
|
10
|
+
style: {
|
|
11
|
+
width: "100%"
|
|
12
|
+
},
|
|
13
|
+
autoPlay: false,
|
|
14
|
+
autoPlayInterval: 2000,
|
|
15
|
+
data: [0, 1, 2, 3],
|
|
16
|
+
pagingEnabled: true,
|
|
17
|
+
defaultIndex: 0,
|
|
18
|
+
autoFillData: true,
|
|
19
|
+
dataLength: 4,
|
|
20
|
+
rawData: [0, 1, 2, 3],
|
|
21
|
+
rawDataLength: 4,
|
|
22
|
+
scrollAnimationDuration: 500,
|
|
23
|
+
snapEnabled: true,
|
|
24
|
+
overscrollEnabled: true
|
|
25
|
+
};
|
|
26
|
+
describe("useCommonVariables", () => {
|
|
27
|
+
it("should return the correct values", async () => {
|
|
28
|
+
const hook = renderHook(() => useCommonVariables(input));
|
|
29
|
+
expect(hook.result.current.size).toMatchInlineSnapshot("700");
|
|
30
|
+
expect(hook.result.current.validLength).toMatchInlineSnapshot("3");
|
|
31
|
+
expect(hook.result.current.handlerOffset.value).toMatchInlineSnapshot("-0");
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
//# sourceMappingURL=useCommonVariables.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["useCommonVariables.test.tsx"],"names":["renderHook","useCommonVariables","input","vertical","width","height","loop","enabled","testID","style","autoPlay","autoPlayInterval","data","pagingEnabled","defaultIndex","autoFillData","dataLength","rawData","rawDataLength","scrollAnimationDuration","snapEnabled","overscrollEnabled","describe","it","hook","expect","result","current","size","toMatchInlineSnapshot","validLength","handlerOffset","value"],"mappings":"AAAA,SAASA,UAAT,QAA2B,8BAA3B;AAEA,SAASC,kBAAT,QAAmC,sBAAnC;AAIA,MAAMC,KAAK,GAAG;AACZC,EAAAA,QAAQ,EAAE,KADE;AAEZC,EAAAA,KAAK,EAAE,GAFK;AAGZC,EAAAA,MAAM,EAAE,GAHI;AAIZC,EAAAA,IAAI,EAAE,IAJM;AAKZC,EAAAA,OAAO,EAAE,IALG;AAMZC,EAAAA,MAAM,EAAE,KANI;AAOZC,EAAAA,KAAK,EAAE;AACLL,IAAAA,KAAK,EAAE;AADF,GAPK;AAUZM,EAAAA,QAAQ,EAAE,KAVE;AAWZC,EAAAA,gBAAgB,EAAE,IAXN;AAYZC,EAAAA,IAAI,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAZM;AAaZC,EAAAA,aAAa,EAAE,IAbH;AAcZC,EAAAA,YAAY,EAAE,CAdF;AAeZC,EAAAA,YAAY,EAAE,IAfF;AAgBZC,EAAAA,UAAU,EAAE,CAhBA;AAiBZC,EAAAA,OAAO,EAAE,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAjBG;AAkBZC,EAAAA,aAAa,EAAE,CAlBH;AAmBZC,EAAAA,uBAAuB,EAAE,GAnBb;AAoBZC,EAAAA,WAAW,EAAE,IApBD;AAqBZC,EAAAA,iBAAiB,EAAE;AArBP,CAAd;AAwBAC,QAAQ,CAAC,oBAAD,EAAuB,MAAM;AACnCC,EAAAA,EAAE,CAAC,kCAAD,EAAqC,YAAY;AACjD,UAAMC,IAAI,GAAGxB,UAAU,CAAC,MAAMC,kBAAkB,CAACC,KAAD,CAAzB,CAAvB;AAEAuB,IAAAA,MAAM,CAACD,IAAI,CAACE,MAAL,CAAYC,OAAZ,CAAoBC,IAArB,CAAN,CAAiCC,qBAAjC,CAAuD,KAAvD;AACAJ,IAAAA,MAAM,CAACD,IAAI,CAACE,MAAL,CAAYC,OAAZ,CAAoBG,WAArB,CAAN,CAAwCD,qBAAxC,CAA8D,GAA9D;AACAJ,IAAAA,MAAM,CAACD,IAAI,CAACE,MAAL,CAAYC,OAAZ,CAAoBI,aAApB,CAAkCC,KAAnC,CAAN,CAAgDH,qBAAhD,CACE,IADF;AAGD,GARC,CAAF;AASD,CAVO,CAAR","sourcesContent":["import { renderHook } from \"@testing-library/react-hooks\";\n\nimport { useCommonVariables } from \"./useCommonVariables\";\n\ntype UseCommonVariablesInput = Parameters<typeof useCommonVariables>[0];\n\nconst input = {\n vertical: false,\n width: 700,\n height: 350,\n loop: true,\n enabled: true,\n testID: \"xxx\",\n style: {\n width: \"100%\",\n },\n autoPlay: false,\n autoPlayInterval: 2000,\n data: [0, 1, 2, 3],\n pagingEnabled: true,\n defaultIndex: 0,\n autoFillData: true,\n dataLength: 4,\n rawData: [0, 1, 2, 3],\n rawDataLength: 4,\n scrollAnimationDuration: 500,\n snapEnabled: true,\n overscrollEnabled: true,\n} as unknown as UseCommonVariablesInput;\n\ndescribe(\"useCommonVariables\", () => {\n it(\"should return the correct values\", async () => {\n const hook = renderHook(() => useCommonVariables(input));\n\n expect(hook.result.current.size).toMatchInlineSnapshot(\"700\");\n expect(hook.result.current.validLength).toMatchInlineSnapshot(\"3\");\n expect(hook.result.current.handlerOffset.value).toMatchInlineSnapshot(\n \"-0\",\n );\n });\n});\n"]}
|
package/lib/module/utils/{computeNewIndexWhenDataChanges.js → compute-offset-if-data-changed.js}
RENAMED
|
@@ -4,7 +4,7 @@ export function omitZero(a, b) {
|
|
|
4
4
|
if (a === 0) return 0;
|
|
5
5
|
return b;
|
|
6
6
|
}
|
|
7
|
-
export function
|
|
7
|
+
export function computeOffsetIfDataChanged(params) {
|
|
8
8
|
"worklet";
|
|
9
9
|
|
|
10
10
|
const {
|
|
@@ -40,4 +40,4 @@ export function computeNewIndexWhenDataChanges(params) {
|
|
|
40
40
|
|
|
41
41
|
return handlerOffset;
|
|
42
42
|
}
|
|
43
|
-
//# sourceMappingURL=
|
|
43
|
+
//# 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":"AAAA,OAAO,SAASA,QAAT,CAAkBC,CAAlB,EAA6BC,CAA7B,EAAwC;AAC7C;;AACA,MAAID,CAAC,KAAK,CAAV,EACE,OAAO,CAAP;AAEF,SAAOC,CAAP;AACD;AAED,OAAO,SAASC,0BAAT,CAAoCC,MAApC,EAM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AACI,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,27 @@
|
|
|
1
|
+
import { computeOffsetIfDataChanged } from "./compute-offset-if-data-changed";
|
|
2
|
+
describe("computeOffsetIfDataChanged", () => {
|
|
3
|
+
const size = 634;
|
|
4
|
+
it("should return the correct values, if index is 0", () => {
|
|
5
|
+
const index = 0;
|
|
6
|
+
const result = computeOffsetIfDataChanged({
|
|
7
|
+
direction: -1,
|
|
8
|
+
previousLength: 4,
|
|
9
|
+
currentLength: 6,
|
|
10
|
+
size,
|
|
11
|
+
handlerOffset: index * size
|
|
12
|
+
});
|
|
13
|
+
expect(result).toMatchInlineSnapshot("0");
|
|
14
|
+
});
|
|
15
|
+
it("should return the correct values, if index is 1", () => {
|
|
16
|
+
const index = 1;
|
|
17
|
+
const result = computeOffsetIfDataChanged({
|
|
18
|
+
direction: -1,
|
|
19
|
+
previousLength: 4,
|
|
20
|
+
currentLength: 6,
|
|
21
|
+
size,
|
|
22
|
+
handlerOffset: index * size
|
|
23
|
+
});
|
|
24
|
+
expect(result).toMatchInlineSnapshot("634");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
//# sourceMappingURL=compute-offset-if-data-changed.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-data-changed.test.ts"],"names":["computeOffsetIfDataChanged","describe","size","it","index","result","direction","previousLength","currentLength","handlerOffset","expect","toMatchInlineSnapshot"],"mappings":"AAAA,SAASA,0BAAT,QAA2C,kCAA3C;AAEAC,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,GAAGL,0BAA0B,CAAC;AACxCM,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,KAAD,CAAzC;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,GAAGL,0BAA0B,CAAC;AACxCM,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,KAAD,CAAzC;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 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-size-changed.ts"],"names":["computeOffsetIfSizeChanged","params","handlerOffset","prevSize","size"],"mappings":"AAAA,OAAO,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,69 @@
|
|
|
1
|
+
import { computeOffsetIfSizeChanged } from "./compute-offset-if-size-changed";
|
|
2
|
+
describe("computeOffsetIfSizeChanged", () => {
|
|
3
|
+
it("[CASE 1] should return the correct values when size does not change", () => {
|
|
4
|
+
const prevIndex = 1;
|
|
5
|
+
const prevSize = 500;
|
|
6
|
+
const size = 500;
|
|
7
|
+
const handlerOffset = prevIndex * size;
|
|
8
|
+
const result = computeOffsetIfSizeChanged({
|
|
9
|
+
prevSize,
|
|
10
|
+
size,
|
|
11
|
+
handlerOffset
|
|
12
|
+
});
|
|
13
|
+
const finallyIndex = result / size;
|
|
14
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
15
|
+
});
|
|
16
|
+
it("[CASE 2] should return the correct values when size changes from 500 to 400", () => {
|
|
17
|
+
const prevIndex = 1;
|
|
18
|
+
const prevSize = 500;
|
|
19
|
+
const size = 400;
|
|
20
|
+
const handlerOffset = prevIndex * prevSize;
|
|
21
|
+
const result = computeOffsetIfSizeChanged({
|
|
22
|
+
prevSize,
|
|
23
|
+
size,
|
|
24
|
+
handlerOffset
|
|
25
|
+
});
|
|
26
|
+
const finallyIndex = result / size;
|
|
27
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
28
|
+
});
|
|
29
|
+
it("[CASE 3] should return the correct values when size changes from 500 to 499", () => {
|
|
30
|
+
const prevIndex = 1;
|
|
31
|
+
const prevSize = 500;
|
|
32
|
+
const size = 499;
|
|
33
|
+
const handlerOffset = prevIndex * prevSize;
|
|
34
|
+
const result = computeOffsetIfSizeChanged({
|
|
35
|
+
prevSize,
|
|
36
|
+
size,
|
|
37
|
+
handlerOffset
|
|
38
|
+
});
|
|
39
|
+
const finallyIndex = result / size;
|
|
40
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
41
|
+
});
|
|
42
|
+
it("[CASE 4] should return the correct values when size changes from 500 to 501", () => {
|
|
43
|
+
const prevIndex = 1;
|
|
44
|
+
const prevSize = 500;
|
|
45
|
+
const size = 501;
|
|
46
|
+
const handlerOffset = prevIndex * prevSize;
|
|
47
|
+
const result = computeOffsetIfSizeChanged({
|
|
48
|
+
prevSize,
|
|
49
|
+
size,
|
|
50
|
+
handlerOffset
|
|
51
|
+
});
|
|
52
|
+
const finallyIndex = result / size;
|
|
53
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
54
|
+
});
|
|
55
|
+
it("[CASE 5] should return the correct values when size changes from 224 to 524", () => {
|
|
56
|
+
const prevIndex = 1;
|
|
57
|
+
const prevSize = 224;
|
|
58
|
+
const size = 524;
|
|
59
|
+
const handlerOffset = prevIndex * prevSize;
|
|
60
|
+
const result = computeOffsetIfSizeChanged({
|
|
61
|
+
prevSize,
|
|
62
|
+
size,
|
|
63
|
+
handlerOffset
|
|
64
|
+
});
|
|
65
|
+
const finallyIndex = result / size;
|
|
66
|
+
expect(finallyIndex).toEqual(prevIndex);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
//# sourceMappingURL=compute-offset-if-size-changed.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["compute-offset-if-size-changed.test.ts"],"names":["computeOffsetIfSizeChanged","describe","it","prevIndex","prevSize","size","handlerOffset","result","finallyIndex","expect","toEqual"],"mappings":"AAAA,SAASA,0BAAT,QAA2C,kCAA3C;AAEAC,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,GAAGP,0BAA0B,CAAC;AACxCI,MAAAA,QADwC;AAExCC,MAAAA,IAFwC;AAGxCC,MAAAA;AAHwC,KAAD,CAAzC;AAMA,UAAME,YAAY,GAAGD,MAAM,GAAGF,IAA9B;AACAI,IAAAA,MAAM,CAACD,YAAD,CAAN,CAAqBE,OAArB,CAA6BP,SAA7B;AACD,GAbC,CAAF;AAeAD,EAAAA,EAAE,CAAC,6EAAD,EAAgF,MAAM;AACtF,UA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B;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,GAAGP,0BAA0B,CAAC;AACxCI,MAAAA,QADwC;AAExCC,MAAAA,IAFwC;AAGxCC,MAAAA;AAHwC,KAAD,CAAzC;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"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { computeOffsetIfDataChanged } from "./compute-offset-if-data-changed";
|
|
2
2
|
describe("should work as expected", () => {
|
|
3
3
|
const size = 375;
|
|
4
4
|
const positive = -1;
|
|
@@ -23,7 +23,7 @@ describe("should work as expected", () => {
|
|
|
23
23
|
|
|
24
24
|
it("The direction is negative, And changing length of data set from 4 to 3, the new index will to be 2.", async () => {
|
|
25
25
|
const currentIndex = 1;
|
|
26
|
-
const handlerOffset =
|
|
26
|
+
const handlerOffset = computeOffsetIfDataChanged(params({
|
|
27
27
|
currentIndex,
|
|
28
28
|
direction: "negative",
|
|
29
29
|
previousLength: 4,
|
|
@@ -32,7 +32,7 @@ describe("should work as expected", () => {
|
|
|
32
32
|
expect(handlerOffset / size).toBe(2 * positive);
|
|
33
33
|
});
|
|
34
34
|
it("The direction is negative, Changing length of data set from 4 to 3, the index remains original.", async () => {
|
|
35
|
-
const handlerOffset =
|
|
35
|
+
const handlerOffset = computeOffsetIfDataChanged(params({
|
|
36
36
|
currentIndex: 2,
|
|
37
37
|
direction: "negative",
|
|
38
38
|
previousLength: 4,
|
|
@@ -41,7 +41,7 @@ describe("should work as expected", () => {
|
|
|
41
41
|
expect(handlerOffset / size).toBe(1 * negative);
|
|
42
42
|
});
|
|
43
43
|
it("The direction is positive, Changing length of data set from 4 to 5, the index remains original.", async () => {
|
|
44
|
-
const handlerOffset =
|
|
44
|
+
const handlerOffset = computeOffsetIfDataChanged(params({
|
|
45
45
|
currentIndex: 3,
|
|
46
46
|
direction: "positive",
|
|
47
47
|
previousLength: 4,
|
|
@@ -50,7 +50,7 @@ describe("should work as expected", () => {
|
|
|
50
50
|
expect(handlerOffset / size).toBe(3 * positive);
|
|
51
51
|
});
|
|
52
52
|
it("The direction is negative, Changing length of data set from 4 to 5, the index remains original.", async () => {
|
|
53
|
-
const handlerOffset =
|
|
53
|
+
const handlerOffset = computeOffsetIfDataChanged(params({
|
|
54
54
|
currentIndex: 3,
|
|
55
55
|
direction: "negative",
|
|
56
56
|
previousLength: 4,
|
|
@@ -59,7 +59,7 @@ describe("should work as expected", () => {
|
|
|
59
59
|
expect(handlerOffset / size).toBe(4 * negative);
|
|
60
60
|
});
|
|
61
61
|
it("Changing length of data set from 0 to 3, the index remains original.", async () => {
|
|
62
|
-
const handlerOffset =
|
|
62
|
+
const handlerOffset = computeOffsetIfDataChanged(params({
|
|
63
63
|
currentIndex: 0,
|
|
64
64
|
direction: "positive",
|
|
65
65
|
previousLength: 0,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["index.test.ts"],"names":["
|
|
1
|
+
{"version":3,"sources":["index.test.ts"],"names":["computeOffsetIfDataChanged","describe","size","positive","negative","params","currentIndex","direction","_direction","previousLength","currentLength","handlerOffset","it","expect","toBe"],"mappings":"AAAA,SAASA,0BAAT,QAA2C,kCAA3C;AAEAC,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,QAA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,KAAD,CAAP,CAAhD;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,GAAGX,0BAA0B,CAACK,MAAM,CAAC;AACtDC,MAAAA,YAAY,EAAE,CADwC;AAEtDC,MAAAA,SAAS,EAAE,UAF2C;AAGtDE,MAAAA,cAAc,EAAE,CAHsC;AAItDC,MAAAA,aAAa,EAAE;AAJuC,KAAD,CAAP,CAAhD;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,GAAGX,0BAA0B,CAACK,MAAM,CAAC;AACtDC,MAAAA,YAAY,EAAE,CADwC;AAEtDC,MAAAA,SAAS,EAAE,UAF2C;AAGtDE,MAAAA,cAAc,EAAE,CAHsC;AAItDC,MAAAA,aAAa,EAAE;AAJuC,KAAD,CAAP,CAAhD;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"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-reanimated-carousel",
|
|
3
|
-
"version": "4.0.0-alpha.
|
|
3
|
+
"version": "4.0.0-alpha.3",
|
|
4
4
|
"description": "Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -14,14 +14,12 @@
|
|
|
14
14
|
"scripts": {
|
|
15
15
|
"gif": "node scripts/makegif.js ./scripts/gif-works-directory",
|
|
16
16
|
"test": "jest run src/**/*",
|
|
17
|
-
"test:dev": "jest dev src/**/*",
|
|
17
|
+
"test:dev": "jest dev src/**/* --watch",
|
|
18
18
|
"typescript": "tsc --noEmit",
|
|
19
19
|
"lint": "eslint 'src/**/*.{js,ts,tsx}'",
|
|
20
20
|
"lint:fix": "eslint 'src/**/*.{js,ts,tsx}' --fix",
|
|
21
21
|
"dev": "watch 'yarn prepare' ./src",
|
|
22
22
|
"prepare": "bob build",
|
|
23
|
-
"release": "yarn prepare && dotenv release-it --no-git.requireUpstream",
|
|
24
|
-
"preRelease": "yarn prepare && dotenv release-it --no-git.requireUpstream --preRelease=beta",
|
|
25
23
|
"ios": "yarn --cwd exampleExpo ios",
|
|
26
24
|
"ios:pretty": "yarn --cwd exampleExpo ios:pretty",
|
|
27
25
|
"web": "yarn --cwd exampleExpo web",
|
|
@@ -50,22 +48,24 @@
|
|
|
50
48
|
"registry": "https://registry.npmjs.org/"
|
|
51
49
|
},
|
|
52
50
|
"devDependencies": {
|
|
51
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
52
|
+
"@babel/plugin-proposal-private-methods": "^7.18.6",
|
|
53
53
|
"@babel/plugin-syntax-dynamic-import": "^7.8.3",
|
|
54
54
|
"@changesets/changelog-github": "^0.5.0",
|
|
55
55
|
"@changesets/cli": "latest",
|
|
56
56
|
"@commitlint/config-conventional": "^11.0.0",
|
|
57
57
|
"@dohooo/eslint-config": "^0.0.7",
|
|
58
58
|
"@react-native-community/eslint-config": "^2.0.0",
|
|
59
|
-
"@
|
|
59
|
+
"@testing-library/jest-native": "^4.0.4",
|
|
60
|
+
"@testing-library/react-hooks": "^8.0.0",
|
|
61
|
+
"@testing-library/react-native": "^7.1.0",
|
|
60
62
|
"@types/jest": "^29.2.5",
|
|
61
63
|
"@types/react": "^18.2.15",
|
|
62
64
|
"@types/react-native": "^0.66.16",
|
|
63
|
-
"@types/react-
|
|
64
|
-
"babel-plugin-inline-dotenv": "^1.6.0",
|
|
65
|
+
"@types/react-test-renderer": "^18.0.7",
|
|
65
66
|
"babel-plugin-module-resolver": "^4.1.0",
|
|
66
67
|
"commitlint": "^11.0.0",
|
|
67
68
|
"cz-conventional-changelog": "^3.3.0",
|
|
68
|
-
"dotenv-cli": "^5.1.0",
|
|
69
69
|
"eslint": "^8.26.0",
|
|
70
70
|
"eslint-config-prettier": "^7.0.0",
|
|
71
71
|
"eslint-plugin-prettier": "^3.1.3",
|
|
@@ -80,7 +80,7 @@
|
|
|
80
80
|
"react-native-builder-bob": "^0.18.1",
|
|
81
81
|
"react-native-gesture-handler": "~2.12.0",
|
|
82
82
|
"react-native-reanimated": "~3.3.0",
|
|
83
|
-
"
|
|
83
|
+
"react-test-renderer": "^18.2.0",
|
|
84
84
|
"sponsorkit": "^0.1.3",
|
|
85
85
|
"typescript": "^4.0.8",
|
|
86
86
|
"watch": "^1.0.2"
|
|
@@ -101,14 +101,6 @@
|
|
|
101
101
|
"optional": true
|
|
102
102
|
}
|
|
103
103
|
},
|
|
104
|
-
"jest": {
|
|
105
|
-
"preset": "react-native",
|
|
106
|
-
"modulePathIgnorePatterns": [
|
|
107
|
-
"<rootDir>/exampleExpo/node_modules",
|
|
108
|
-
"<rootDir>/exampleBare/node_modules",
|
|
109
|
-
"<rootDir>/lib/"
|
|
110
|
-
]
|
|
111
|
-
},
|
|
112
104
|
"husky": {
|
|
113
105
|
"hooks": {
|
|
114
106
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
|
|
@@ -120,37 +112,6 @@
|
|
|
120
112
|
"@commitlint/config-conventional"
|
|
121
113
|
]
|
|
122
114
|
},
|
|
123
|
-
"release-it": {
|
|
124
|
-
"git": {
|
|
125
|
-
"commitMessage": "chore: release ${version}",
|
|
126
|
-
"tagName": "v${version}"
|
|
127
|
-
},
|
|
128
|
-
"npm": {
|
|
129
|
-
"publish": true
|
|
130
|
-
},
|
|
131
|
-
"github": {
|
|
132
|
-
"release": true
|
|
133
|
-
},
|
|
134
|
-
"plugins": {
|
|
135
|
-
"@release-it/conventional-changelog": {
|
|
136
|
-
"preset": {
|
|
137
|
-
"name": "angular",
|
|
138
|
-
"types": [
|
|
139
|
-
{
|
|
140
|
-
"type": "feat",
|
|
141
|
-
"section": "Features"
|
|
142
|
-
},
|
|
143
|
-
{
|
|
144
|
-
"type": "fix",
|
|
145
|
-
"section": "Bug Fixes"
|
|
146
|
-
},
|
|
147
|
-
{}
|
|
148
|
-
]
|
|
149
|
-
},
|
|
150
|
-
"infile": "CHANGELOG.md"
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
},
|
|
154
115
|
"react-native-builder-bob": {
|
|
155
116
|
"source": "src",
|
|
156
117
|
"output": "lib",
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { FC } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import Animated, { useAnimatedStyle, useDerivedValue } from "react-native-reanimated";
|
|
4
|
+
import renderer from "react-test-renderer";
|
|
5
|
+
|
|
6
|
+
describe("useSharedValue", () => {
|
|
7
|
+
it("retains value on rerender", () => {
|
|
8
|
+
const initialValue = 0;
|
|
9
|
+
const updatedValue = 1;
|
|
10
|
+
|
|
11
|
+
interface Props {
|
|
12
|
+
key: string
|
|
13
|
+
value: number
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const TestComponent: FC<Props> = (props) => {
|
|
17
|
+
const opacity = useDerivedValue(() => props.value, [props.value]);
|
|
18
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
19
|
+
opacity: opacity.value,
|
|
20
|
+
}), [opacity]);
|
|
21
|
+
|
|
22
|
+
return <Animated.View style={animatedStyle} />;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
// When rendering with initial value
|
|
26
|
+
const wrapper = renderer.create(<TestComponent key="box" value={initialValue} />);
|
|
27
|
+
|
|
28
|
+
expect(
|
|
29
|
+
typeof wrapper.root.children[0] !== "string"
|
|
30
|
+
? wrapper.root.children[0].props.style.animatedStyle.current.value.opacity
|
|
31
|
+
: false,
|
|
32
|
+
).toBe(initialValue);
|
|
33
|
+
|
|
34
|
+
// When rendering with updated value
|
|
35
|
+
wrapper.update(<TestComponent key="box" value={updatedValue} />);
|
|
36
|
+
|
|
37
|
+
expect(
|
|
38
|
+
typeof wrapper.root.children[0] !== "string"
|
|
39
|
+
? wrapper.root.children[0].props.style.animatedStyle.current.value.opacity
|
|
40
|
+
: false,
|
|
41
|
+
).toBe(initialValue);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-hooks";
|
|
2
|
+
|
|
3
|
+
import { useCommonVariables } from "./useCommonVariables";
|
|
4
|
+
|
|
5
|
+
type UseCommonVariablesInput = Parameters<typeof useCommonVariables>[0];
|
|
6
|
+
|
|
7
|
+
const input = {
|
|
8
|
+
vertical: false,
|
|
9
|
+
width: 700,
|
|
10
|
+
height: 350,
|
|
11
|
+
loop: true,
|
|
12
|
+
enabled: true,
|
|
13
|
+
testID: "xxx",
|
|
14
|
+
style: {
|
|
15
|
+
width: "100%",
|
|
16
|
+
},
|
|
17
|
+
autoPlay: false,
|
|
18
|
+
autoPlayInterval: 2000,
|
|
19
|
+
data: [0, 1, 2, 3],
|
|
20
|
+
pagingEnabled: true,
|
|
21
|
+
defaultIndex: 0,
|
|
22
|
+
autoFillData: true,
|
|
23
|
+
dataLength: 4,
|
|
24
|
+
rawData: [0, 1, 2, 3],
|
|
25
|
+
rawDataLength: 4,
|
|
26
|
+
scrollAnimationDuration: 500,
|
|
27
|
+
snapEnabled: true,
|
|
28
|
+
overscrollEnabled: true,
|
|
29
|
+
} as unknown as UseCommonVariablesInput;
|
|
30
|
+
|
|
31
|
+
describe("useCommonVariables", () => {
|
|
32
|
+
it("should return the correct values", async () => {
|
|
33
|
+
const hook = renderHook(() => useCommonVariables(input));
|
|
34
|
+
|
|
35
|
+
expect(hook.result.current.size).toMatchInlineSnapshot("700");
|
|
36
|
+
expect(hook.result.current.validLength).toMatchInlineSnapshot("3");
|
|
37
|
+
expect(hook.result.current.handlerOffset.value).toMatchInlineSnapshot(
|
|
38
|
+
"-0",
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from "react";
|
|
2
1
|
import type Animated from "react-native-reanimated";
|
|
3
2
|
import { useSharedValue, useAnimatedReaction } from "react-native-reanimated";
|
|
4
3
|
|
|
5
4
|
import type { TInitializeCarouselProps } from "./useInitProps";
|
|
6
5
|
|
|
7
|
-
import {
|
|
6
|
+
import { computeOffsetIfDataChanged } from "../utils/compute-offset-if-data-changed";
|
|
7
|
+
import { computeOffsetIfSizeChanged } from "../utils/compute-offset-if-size-changed";
|
|
8
8
|
import { handlerOffsetDirection } from "../utils/handleroffset-direction";
|
|
9
9
|
|
|
10
10
|
interface ICommonVariables {
|
|
@@ -26,21 +26,20 @@ export function useCommonVariables(
|
|
|
26
26
|
loop,
|
|
27
27
|
} = props;
|
|
28
28
|
const size = vertical ? height : width;
|
|
29
|
-
const validLength = dataLength - 1;
|
|
30
29
|
const defaultHandlerOffsetValue = -Math.abs(defaultIndex * size);
|
|
31
30
|
const _handlerOffset = useSharedValue<number>(defaultHandlerOffsetValue);
|
|
32
31
|
const handlerOffset = defaultScrollOffsetValue ?? _handlerOffset;
|
|
33
32
|
const prevDataLength = useSharedValue(dataLength);
|
|
33
|
+
const prevSize = useSharedValue(size);
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
/**
|
|
36
|
+
* When data changes, we need to compute new index for handlerOffset
|
|
37
|
+
*/
|
|
39
38
|
useAnimatedReaction(() => {
|
|
40
39
|
const previousLength = prevDataLength.value;
|
|
41
40
|
const currentLength = dataLength;
|
|
42
41
|
const isLengthChanged = previousLength !== currentLength;
|
|
43
|
-
const shouldComputed = isLengthChanged && loop;
|
|
42
|
+
const shouldComputed = (isLengthChanged && loop);
|
|
44
43
|
|
|
45
44
|
if (shouldComputed)
|
|
46
45
|
prevDataLength.value = dataLength;
|
|
@@ -55,7 +54,7 @@ export function useCommonVariables(
|
|
|
55
54
|
// direction -> 1 | -1
|
|
56
55
|
const direction = handlerOffsetDirection(handlerOffset);
|
|
57
56
|
|
|
58
|
-
handlerOffset.value =
|
|
57
|
+
handlerOffset.value = computeOffsetIfDataChanged({
|
|
59
58
|
direction,
|
|
60
59
|
previousLength,
|
|
61
60
|
currentLength,
|
|
@@ -65,9 +64,35 @@ export function useCommonVariables(
|
|
|
65
64
|
}
|
|
66
65
|
}, [dataLength, loop]);
|
|
67
66
|
|
|
67
|
+
/**
|
|
68
|
+
* When size changes, we need to compute new index for handlerOffset
|
|
69
|
+
*/
|
|
70
|
+
useAnimatedReaction(() => {
|
|
71
|
+
const previousSize = prevSize.value;
|
|
72
|
+
const isSizeChanged = previousSize !== size;
|
|
73
|
+
const shouldComputed = isSizeChanged;
|
|
74
|
+
|
|
75
|
+
if (shouldComputed)
|
|
76
|
+
prevSize.value = size;
|
|
77
|
+
|
|
78
|
+
return {
|
|
79
|
+
shouldComputed,
|
|
80
|
+
previousSize,
|
|
81
|
+
size,
|
|
82
|
+
};
|
|
83
|
+
}, ({ shouldComputed, previousSize, size }) => {
|
|
84
|
+
if (shouldComputed) {
|
|
85
|
+
handlerOffset.value = computeOffsetIfSizeChanged({
|
|
86
|
+
handlerOffset: handlerOffset.value,
|
|
87
|
+
prevSize: previousSize,
|
|
88
|
+
size,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}, [size]);
|
|
92
|
+
|
|
68
93
|
return {
|
|
69
94
|
size,
|
|
70
|
-
validLength,
|
|
95
|
+
validLength: dataLength - 1,
|
|
71
96
|
handlerOffset,
|
|
72
97
|
};
|
|
73
98
|
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { computeOffsetIfDataChanged } from "./compute-offset-if-data-changed";
|
|
2
|
+
|
|
3
|
+
describe("computeOffsetIfDataChanged", () => {
|
|
4
|
+
const size = 634;
|
|
5
|
+
it("should return the correct values, if index is 0", () => {
|
|
6
|
+
const index = 0;
|
|
7
|
+
const result = computeOffsetIfDataChanged({
|
|
8
|
+
direction: -1,
|
|
9
|
+
previousLength: 4,
|
|
10
|
+
currentLength: 6,
|
|
11
|
+
size,
|
|
12
|
+
handlerOffset: index * size,
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
expect(result).toMatchInlineSnapshot("0");
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it("should return the correct values, if index is 1", () => {
|
|
19
|
+
const index = 1;
|
|
20
|
+
const result = computeOffsetIfDataChanged({
|
|
21
|
+
direction: -1,
|
|
22
|
+
previousLength: 4,
|
|
23
|
+
currentLength: 6,
|
|
24
|
+
size,
|
|
25
|
+
handlerOffset: index * size,
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(result).toMatchInlineSnapshot("634");
|
|
29
|
+
});
|
|
30
|
+
});
|