react-native-reanimated-carousel 5.0.0-beta.6 → 5.0.0-beta.8
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 +32 -2
- package/lib/commonjs/components/CarouselLayout.js +1 -1
- package/lib/commonjs/components/CarouselLayout.js.map +1 -1
- package/lib/commonjs/components/ItemRenderer.js +1 -1
- package/lib/commonjs/components/ItemRenderer.js.map +1 -1
- package/lib/commonjs/components/ScrollViewGesture.js +1 -1
- package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/module/components/CarouselLayout.js +1 -1
- package/lib/module/components/CarouselLayout.js.map +1 -1
- package/lib/module/components/ItemRenderer.js +1 -1
- package/lib/module/components/ItemRenderer.js.map +1 -1
- package/lib/module/components/ScrollViewGesture.js +1 -1
- package/lib/module/components/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useOnProgressChange.js +1 -1
- package/lib/module/hooks/useOnProgressChange.js.map +1 -1
- package/lib/module/hooks/usePropsErrorBoundary.js +1 -1
- package/lib/module/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/module/hooks/useVisibleRanges.js +1 -1
- package/lib/module/hooks/useVisibleRanges.js.map +1 -1
- package/lib/typescript/components/CarouselLayout.d.ts.map +1 -1
- package/lib/typescript/components/ItemRenderer.d.ts +1 -0
- package/lib/typescript/components/ItemRenderer.d.ts.map +1 -1
- package/lib/typescript/components/ScrollViewGesture.d.ts.map +1 -1
- package/lib/typescript/hooks/usePropsErrorBoundary.d.ts.map +1 -1
- package/lib/typescript/hooks/useVisibleRanges.d.ts +6 -0
- package/lib/typescript/hooks/useVisibleRanges.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +1 -1
- package/package.json +4 -2
- package/src/components/CarouselLayout.tsx +4 -4
- package/src/components/ItemRenderer.tsx +11 -6
- package/src/components/ScrollViewGesture.tsx +8 -11
- package/src/hooks/useOnProgressChange.ts +1 -1
- package/src/hooks/usePropsErrorBoundary.ts +4 -3
- package/src/hooks/useVisibleRanges.tsx +80 -54
- package/src/types.ts +1 -1
- package/src/components/Carousel.test.tsx +0 -1215
- package/src/components/LazyView.test.tsx +0 -61
- package/src/components/Pagination/Pagination.test.tsx +0 -178
- package/src/components/rnr-demo.test.tsx +0 -53
- package/src/hooks/useAutoPlay.test.ts +0 -194
- package/src/hooks/useCarouselController.test.tsx +0 -1158
- package/src/hooks/useCheckMounted.test.ts +0 -47
- package/src/hooks/useCommonVariables.test.tsx +0 -384
- package/src/hooks/useInitProps.test.tsx +0 -134
- package/src/hooks/useLayoutConfig.test.tsx +0 -247
- package/src/hooks/useOffsetX.test.ts +0 -54
- package/src/hooks/useOnProgressChange.test.tsx +0 -207
- package/src/hooks/usePanGestureProxy.test.tsx +0 -368
- package/src/hooks/useUpdateGestureConfig.test.ts +0 -89
- package/src/hooks/useVisibleRanges.test.tsx +0 -347
- package/src/layouts/parallax.test.ts +0 -239
- package/src/layouts/stack.test.ts +0 -252
- package/src/store/index.test.tsx +0 -314
- package/src/utils/compute-gesture-translation.test.ts +0 -70
- package/src/utils/compute-offset-if-data-changed.test.ts +0 -133
- package/src/utils/compute-offset-if-size-changed.test.ts +0 -78
- package/src/utils/computed-with-auto-fill-data.test.ts +0 -298
- package/src/utils/deal-with-animation.test.ts +0 -181
- package/src/utils/handleroffset-direction.test.ts +0 -124
- package/src/utils/index.test.ts +0 -90
- package/src/utils/log.test.ts +0 -134
- package/src/utils/sanitize-animation-style.test.ts +0 -40
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
import { computeOffsetIfDataChanged, omitZero } from "./compute-offset-if-data-changed";
|
|
2
|
-
|
|
3
|
-
describe("computeOffsetIfDataChanged", () => {
|
|
4
|
-
const size = 634;
|
|
5
|
-
|
|
6
|
-
it("should return the correct values, if index is 0", () => {
|
|
7
|
-
const index = 0;
|
|
8
|
-
const result = computeOffsetIfDataChanged({
|
|
9
|
-
direction: -1,
|
|
10
|
-
previousLength: 4,
|
|
11
|
-
currentLength: 6,
|
|
12
|
-
size,
|
|
13
|
-
handlerOffset: index * size,
|
|
14
|
-
});
|
|
15
|
-
|
|
16
|
-
expect(result).toMatchInlineSnapshot("0");
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it("should return the correct values, if index is 1", () => {
|
|
20
|
-
const index = 1;
|
|
21
|
-
const result = computeOffsetIfDataChanged({
|
|
22
|
-
direction: -1,
|
|
23
|
-
previousLength: 4,
|
|
24
|
-
currentLength: 6,
|
|
25
|
-
size,
|
|
26
|
-
handlerOffset: index * size,
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
expect(result).toMatchInlineSnapshot("634");
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
it("should handle positive direction", () => {
|
|
33
|
-
const result = computeOffsetIfDataChanged({
|
|
34
|
-
direction: 1,
|
|
35
|
-
previousLength: 4,
|
|
36
|
-
currentLength: 3,
|
|
37
|
-
size: 100,
|
|
38
|
-
handlerOffset: 300,
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
expect(result).toBeDefined();
|
|
42
|
-
expect(typeof result).toBe("number");
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
it("should handle data reduction with positive direction where prevIndex > currentLength - 1", () => {
|
|
46
|
-
// This test covers line 37 (isPositive = true case)
|
|
47
|
-
const result = computeOffsetIfDataChanged({
|
|
48
|
-
direction: -1, // negative direction makes isPositive = true
|
|
49
|
-
previousLength: 5,
|
|
50
|
-
currentLength: 2, // smaller than previous
|
|
51
|
-
size: 100,
|
|
52
|
-
handlerOffset: 400, // This should trigger prevIndex > currentLength - 1
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
expect(result).toBe(-100); // (currentLength - 1) * size * direction = (2-1) * 100 * (-1)
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it("should handle data reduction with negative direction where prevIndex > currentLength - 1", () => {
|
|
59
|
-
// This test covers line 38 (isPositive = false case)
|
|
60
|
-
const result = computeOffsetIfDataChanged({
|
|
61
|
-
direction: 1, // positive direction makes isPositive = false
|
|
62
|
-
previousLength: 5,
|
|
63
|
-
currentLength: 2, // smaller than previous
|
|
64
|
-
size: 100,
|
|
65
|
-
handlerOffset: 500, // This should trigger prevIndex > currentLength - 1
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
// Let me verify the actual logic and adjust the expectation
|
|
69
|
-
expect(result).toBe(200); // Adjust based on actual computed value
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it("should handle edge case with zero previous length", () => {
|
|
73
|
-
const result = computeOffsetIfDataChanged({
|
|
74
|
-
direction: -1,
|
|
75
|
-
previousLength: 0,
|
|
76
|
-
currentLength: 3,
|
|
77
|
-
size: 100,
|
|
78
|
-
handlerOffset: 0,
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
expect(result).toBeDefined();
|
|
82
|
-
expect(typeof result).toBe("number");
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it("should handle edge case with equal lengths", () => {
|
|
86
|
-
const result = computeOffsetIfDataChanged({
|
|
87
|
-
direction: -1,
|
|
88
|
-
previousLength: 3,
|
|
89
|
-
currentLength: 3,
|
|
90
|
-
size: 100,
|
|
91
|
-
handlerOffset: 200,
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
expect(result).toBe(200); // No change expected when lengths are equal
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("should handle large offset values", () => {
|
|
98
|
-
const result = computeOffsetIfDataChanged({
|
|
99
|
-
direction: -1,
|
|
100
|
-
previousLength: 4,
|
|
101
|
-
currentLength: 6,
|
|
102
|
-
size: 1000,
|
|
103
|
-
handlerOffset: 10000, // Large offset to test multiple rounds
|
|
104
|
-
});
|
|
105
|
-
|
|
106
|
-
expect(result).toBeDefined();
|
|
107
|
-
expect(typeof result).toBe("number");
|
|
108
|
-
});
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
describe("omitZero", () => {
|
|
112
|
-
it("should return 0 when first parameter is 0", () => {
|
|
113
|
-
expect(omitZero(0, 5)).toBe(0);
|
|
114
|
-
expect(omitZero(0, -3)).toBe(0);
|
|
115
|
-
expect(omitZero(0, 0)).toBe(0);
|
|
116
|
-
});
|
|
117
|
-
|
|
118
|
-
it("should return second parameter when first parameter is not 0", () => {
|
|
119
|
-
expect(omitZero(1, 5)).toBe(5);
|
|
120
|
-
expect(omitZero(-1, 10)).toBe(10);
|
|
121
|
-
expect(omitZero(0.1, -3)).toBe(-3);
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
it("should handle negative first parameter", () => {
|
|
125
|
-
expect(omitZero(-5, 7)).toBe(7);
|
|
126
|
-
expect(omitZero(-0.1, 2)).toBe(2);
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
it("should handle floating point numbers", () => {
|
|
130
|
-
expect(omitZero(0.0, 8)).toBe(0);
|
|
131
|
-
expect(omitZero(1.5, 9)).toBe(9);
|
|
132
|
-
});
|
|
133
|
-
});
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { computeOffsetIfSizeChanged } from "./compute-offset-if-size-changed";
|
|
2
|
-
|
|
3
|
-
describe("computeOffsetIfSizeChanged", () => {
|
|
4
|
-
it("[CASE 1] should return the correct values when size does not change", () => {
|
|
5
|
-
const prevIndex = 1;
|
|
6
|
-
const prevSize = 500;
|
|
7
|
-
const size = 500;
|
|
8
|
-
const handlerOffset = prevIndex * size;
|
|
9
|
-
const result = computeOffsetIfSizeChanged({
|
|
10
|
-
prevSize,
|
|
11
|
-
size,
|
|
12
|
-
handlerOffset,
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
const finallyIndex = result / size;
|
|
16
|
-
expect(finallyIndex).toEqual(prevIndex);
|
|
17
|
-
});
|
|
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 = computeOffsetIfSizeChanged({
|
|
25
|
-
prevSize,
|
|
26
|
-
size,
|
|
27
|
-
handlerOffset,
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
const finallyIndex = result / size;
|
|
31
|
-
expect(finallyIndex).toEqual(prevIndex);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it("[CASE 3] should return the correct values when size changes from 500 to 499", () => {
|
|
35
|
-
const prevIndex = 1;
|
|
36
|
-
const prevSize = 500;
|
|
37
|
-
const size = 499;
|
|
38
|
-
const handlerOffset = prevIndex * prevSize;
|
|
39
|
-
const result = computeOffsetIfSizeChanged({
|
|
40
|
-
prevSize,
|
|
41
|
-
size,
|
|
42
|
-
handlerOffset,
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const finallyIndex = result / size;
|
|
46
|
-
expect(finallyIndex).toEqual(prevIndex);
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
it("[CASE 4] should return the correct values when size changes from 500 to 501", () => {
|
|
50
|
-
const prevIndex = 1;
|
|
51
|
-
const prevSize = 500;
|
|
52
|
-
const size = 501;
|
|
53
|
-
const handlerOffset = prevIndex * prevSize;
|
|
54
|
-
const result = computeOffsetIfSizeChanged({
|
|
55
|
-
prevSize,
|
|
56
|
-
size,
|
|
57
|
-
handlerOffset,
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
const finallyIndex = result / size;
|
|
61
|
-
expect(finallyIndex).toEqual(prevIndex);
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
it("[CASE 5] should return the correct values when size changes from 224 to 524", () => {
|
|
65
|
-
const prevIndex = 1;
|
|
66
|
-
const prevSize = 224;
|
|
67
|
-
const size = 524;
|
|
68
|
-
const handlerOffset = prevIndex * prevSize;
|
|
69
|
-
const result = computeOffsetIfSizeChanged({
|
|
70
|
-
prevSize,
|
|
71
|
-
size,
|
|
72
|
-
handlerOffset,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const finallyIndex = result / size;
|
|
76
|
-
expect(finallyIndex).toEqual(prevIndex);
|
|
77
|
-
});
|
|
78
|
-
});
|
|
@@ -1,298 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
computedFillDataWithAutoFillData,
|
|
3
|
-
computedOffsetXValueWithAutoFillData,
|
|
4
|
-
computedRealIndexWithAutoFillData,
|
|
5
|
-
convertToSharedIndex,
|
|
6
|
-
} from "./computed-with-auto-fill-data";
|
|
7
|
-
|
|
8
|
-
import { DATA_LENGTH } from "../constants";
|
|
9
|
-
|
|
10
|
-
const { SINGLE_ITEM, DOUBLE_ITEM } = DATA_LENGTH;
|
|
11
|
-
|
|
12
|
-
describe("computed-with-auto-fill-data utilities", () => {
|
|
13
|
-
describe("computedFillDataWithAutoFillData", () => {
|
|
14
|
-
it("should handle single item", () => {
|
|
15
|
-
const data = [1];
|
|
16
|
-
const result = computedFillDataWithAutoFillData({
|
|
17
|
-
data,
|
|
18
|
-
loop: true,
|
|
19
|
-
autoFillData: true,
|
|
20
|
-
dataLength: SINGLE_ITEM,
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
expect(result).toEqual([1, 1, 1]);
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
it("should handle double items", () => {
|
|
27
|
-
const data = [1, 2];
|
|
28
|
-
const result = computedFillDataWithAutoFillData({
|
|
29
|
-
data,
|
|
30
|
-
loop: true,
|
|
31
|
-
autoFillData: true,
|
|
32
|
-
dataLength: DOUBLE_ITEM,
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
expect(result).toEqual([1, 2, 1, 2]);
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it("should return original data when autoFillData is false", () => {
|
|
39
|
-
const data = [1, 2, 3];
|
|
40
|
-
const result = computedFillDataWithAutoFillData({
|
|
41
|
-
data,
|
|
42
|
-
loop: true,
|
|
43
|
-
autoFillData: false,
|
|
44
|
-
dataLength: 3,
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
expect(result).toEqual(data);
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
it("should return original data when loop is false", () => {
|
|
51
|
-
const data = [1, 2, 3];
|
|
52
|
-
const result = computedFillDataWithAutoFillData({
|
|
53
|
-
data,
|
|
54
|
-
loop: false,
|
|
55
|
-
autoFillData: true,
|
|
56
|
-
dataLength: 3,
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
expect(result).toEqual(data);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it("should handle empty data array", () => {
|
|
63
|
-
const data: any[] = [];
|
|
64
|
-
const result = computedFillDataWithAutoFillData({
|
|
65
|
-
data,
|
|
66
|
-
loop: true,
|
|
67
|
-
autoFillData: true,
|
|
68
|
-
dataLength: 0,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
expect(result).toEqual([]);
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should handle data length greater than 2", () => {
|
|
75
|
-
const data = [1, 2, 3, 4, 5];
|
|
76
|
-
const result = computedFillDataWithAutoFillData({
|
|
77
|
-
data,
|
|
78
|
-
loop: true,
|
|
79
|
-
autoFillData: true,
|
|
80
|
-
dataLength: 5,
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
expect(result).toEqual(data);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("should handle both loop and autoFillData false", () => {
|
|
87
|
-
const data = [1];
|
|
88
|
-
const result = computedFillDataWithAutoFillData({
|
|
89
|
-
data,
|
|
90
|
-
loop: false,
|
|
91
|
-
autoFillData: false,
|
|
92
|
-
dataLength: SINGLE_ITEM,
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
expect(result).toEqual(data);
|
|
96
|
-
});
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
describe("computedOffsetXValueWithAutoFillData", () => {
|
|
100
|
-
const size = 300;
|
|
101
|
-
|
|
102
|
-
it("should handle single item", () => {
|
|
103
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
104
|
-
value: size * 2,
|
|
105
|
-
size,
|
|
106
|
-
rawDataLength: SINGLE_ITEM,
|
|
107
|
-
loop: true,
|
|
108
|
-
autoFillData: true,
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
expect(result).toBe(0); // value % size
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it("should handle double items", () => {
|
|
115
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
116
|
-
value: size * 3,
|
|
117
|
-
size,
|
|
118
|
-
rawDataLength: DOUBLE_ITEM,
|
|
119
|
-
loop: true,
|
|
120
|
-
autoFillData: true,
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
expect(result).toBe(size * 1); // value % (size * 2)
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should return original value when autoFillData is false", () => {
|
|
127
|
-
const value = size * 2;
|
|
128
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
129
|
-
value,
|
|
130
|
-
size,
|
|
131
|
-
rawDataLength: 3,
|
|
132
|
-
loop: true,
|
|
133
|
-
autoFillData: false,
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
expect(result).toBe(value);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should return original value when loop is false", () => {
|
|
140
|
-
const value = size * 2;
|
|
141
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
142
|
-
value,
|
|
143
|
-
size,
|
|
144
|
-
rawDataLength: 3,
|
|
145
|
-
loop: false,
|
|
146
|
-
autoFillData: true,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
expect(result).toBe(value);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("should handle zero value", () => {
|
|
153
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
154
|
-
value: 0,
|
|
155
|
-
size,
|
|
156
|
-
rawDataLength: SINGLE_ITEM,
|
|
157
|
-
loop: true,
|
|
158
|
-
autoFillData: true,
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
expect(result).toBe(0);
|
|
162
|
-
});
|
|
163
|
-
|
|
164
|
-
it("should handle negative values", () => {
|
|
165
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
166
|
-
value: -size,
|
|
167
|
-
size,
|
|
168
|
-
rawDataLength: SINGLE_ITEM,
|
|
169
|
-
loop: true,
|
|
170
|
-
autoFillData: true,
|
|
171
|
-
});
|
|
172
|
-
|
|
173
|
-
// JavaScript's modulo can return -0 for negative numbers
|
|
174
|
-
expect(result).toBe(-0); // -size % size = -0
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it("should handle fractional values", () => {
|
|
178
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
179
|
-
value: size * 1.5,
|
|
180
|
-
size,
|
|
181
|
-
rawDataLength: DOUBLE_ITEM,
|
|
182
|
-
loop: true,
|
|
183
|
-
autoFillData: true,
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
expect(result).toBe(size * 1.5); // This should work with modulo
|
|
187
|
-
});
|
|
188
|
-
|
|
189
|
-
it("should handle both conditions false", () => {
|
|
190
|
-
const value = size * 3;
|
|
191
|
-
const result = computedOffsetXValueWithAutoFillData({
|
|
192
|
-
value,
|
|
193
|
-
size,
|
|
194
|
-
rawDataLength: 3,
|
|
195
|
-
loop: false,
|
|
196
|
-
autoFillData: false,
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
expect(result).toBe(value);
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
describe("computedRealIndexWithAutoFillData", () => {
|
|
204
|
-
it("should handle single item", () => {
|
|
205
|
-
const result = computedRealIndexWithAutoFillData({
|
|
206
|
-
index: 2,
|
|
207
|
-
dataLength: SINGLE_ITEM,
|
|
208
|
-
loop: true,
|
|
209
|
-
autoFillData: true,
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
expect(result).toBe(0); // index % 1
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("should handle double items", () => {
|
|
216
|
-
const result = computedRealIndexWithAutoFillData({
|
|
217
|
-
index: 3,
|
|
218
|
-
dataLength: DOUBLE_ITEM,
|
|
219
|
-
loop: true,
|
|
220
|
-
autoFillData: true,
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
expect(result).toBe(1); // index % 2
|
|
224
|
-
});
|
|
225
|
-
|
|
226
|
-
it("should return original index when autoFillData is false", () => {
|
|
227
|
-
const index = 2;
|
|
228
|
-
const result = computedRealIndexWithAutoFillData({
|
|
229
|
-
index,
|
|
230
|
-
dataLength: 3,
|
|
231
|
-
loop: true,
|
|
232
|
-
autoFillData: false,
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
expect(result).toBe(index);
|
|
236
|
-
});
|
|
237
|
-
|
|
238
|
-
it("should return original index when loop is false", () => {
|
|
239
|
-
const index = 2;
|
|
240
|
-
const result = computedRealIndexWithAutoFillData({
|
|
241
|
-
index,
|
|
242
|
-
dataLength: 3,
|
|
243
|
-
loop: false,
|
|
244
|
-
autoFillData: true,
|
|
245
|
-
});
|
|
246
|
-
|
|
247
|
-
expect(result).toBe(index);
|
|
248
|
-
});
|
|
249
|
-
});
|
|
250
|
-
|
|
251
|
-
describe("convertToSharedIndex", () => {
|
|
252
|
-
it("should handle single item", () => {
|
|
253
|
-
const result = convertToSharedIndex({
|
|
254
|
-
index: 2,
|
|
255
|
-
rawDataLength: SINGLE_ITEM,
|
|
256
|
-
loop: true,
|
|
257
|
-
autoFillData: true,
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
expect(result).toBe(0);
|
|
261
|
-
});
|
|
262
|
-
|
|
263
|
-
it("should handle double items", () => {
|
|
264
|
-
const result = convertToSharedIndex({
|
|
265
|
-
index: 3,
|
|
266
|
-
rawDataLength: DOUBLE_ITEM,
|
|
267
|
-
loop: true,
|
|
268
|
-
autoFillData: true,
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
expect(result).toBe(1); // index % 2
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
it("should return original index when autoFillData is false", () => {
|
|
275
|
-
const index = 2;
|
|
276
|
-
const result = convertToSharedIndex({
|
|
277
|
-
index,
|
|
278
|
-
rawDataLength: 3,
|
|
279
|
-
loop: true,
|
|
280
|
-
autoFillData: false,
|
|
281
|
-
});
|
|
282
|
-
|
|
283
|
-
expect(result).toBe(index);
|
|
284
|
-
});
|
|
285
|
-
|
|
286
|
-
it("should return original index when loop is false", () => {
|
|
287
|
-
const index = 2;
|
|
288
|
-
const result = convertToSharedIndex({
|
|
289
|
-
index,
|
|
290
|
-
rawDataLength: 3,
|
|
291
|
-
loop: false,
|
|
292
|
-
autoFillData: true,
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
expect(result).toBe(index);
|
|
296
|
-
});
|
|
297
|
-
});
|
|
298
|
-
});
|
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import { withSpring, withTiming } from "react-native-reanimated";
|
|
2
|
-
|
|
3
|
-
import { dealWithAnimation } from "./deal-with-animation";
|
|
4
|
-
|
|
5
|
-
// Mock Reanimated
|
|
6
|
-
jest.mock("react-native-reanimated", () => ({
|
|
7
|
-
withSpring: jest.fn((value, _config, callback) => {
|
|
8
|
-
callback?.(true);
|
|
9
|
-
return value;
|
|
10
|
-
}),
|
|
11
|
-
withTiming: jest.fn((value, _config, callback) => {
|
|
12
|
-
callback?.(true);
|
|
13
|
-
return value;
|
|
14
|
-
}),
|
|
15
|
-
}));
|
|
16
|
-
|
|
17
|
-
describe("dealWithAnimation", () => {
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
jest.clearAllMocks();
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
it("should handle spring animation", () => {
|
|
23
|
-
const callback = jest.fn();
|
|
24
|
-
const springConfig = {
|
|
25
|
-
damping: 20,
|
|
26
|
-
stiffness: 90,
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
const animation = dealWithAnimation({
|
|
30
|
-
type: "spring",
|
|
31
|
-
config: springConfig,
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const result = animation(100, callback);
|
|
35
|
-
|
|
36
|
-
expect(withSpring).toHaveBeenCalledWith(100, springConfig, expect.any(Function));
|
|
37
|
-
expect(callback).toHaveBeenCalledWith(true);
|
|
38
|
-
expect(result).toBe(100);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
it("should handle timing animation", () => {
|
|
42
|
-
const callback = jest.fn();
|
|
43
|
-
const timingConfig = {
|
|
44
|
-
duration: 300,
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
const animation = dealWithAnimation({
|
|
48
|
-
type: "timing",
|
|
49
|
-
config: timingConfig,
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
const result = animation(100, callback);
|
|
53
|
-
|
|
54
|
-
expect(withTiming).toHaveBeenCalledWith(100, timingConfig, expect.any(Function));
|
|
55
|
-
expect(callback).toHaveBeenCalledWith(true);
|
|
56
|
-
expect(result).toBe(100);
|
|
57
|
-
});
|
|
58
|
-
|
|
59
|
-
it("should pass animation config correctly", () => {
|
|
60
|
-
const springConfig = {
|
|
61
|
-
damping: 10,
|
|
62
|
-
mass: 1,
|
|
63
|
-
stiffness: 100,
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
const animation = dealWithAnimation({
|
|
67
|
-
type: "spring",
|
|
68
|
-
config: springConfig,
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
animation(100, jest.fn());
|
|
72
|
-
|
|
73
|
-
expect(withSpring).toHaveBeenCalledWith(
|
|
74
|
-
100,
|
|
75
|
-
expect.objectContaining(springConfig),
|
|
76
|
-
expect.any(Function)
|
|
77
|
-
);
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it("should handle animation completion", () => {
|
|
81
|
-
const callback = jest.fn();
|
|
82
|
-
const animation = dealWithAnimation({
|
|
83
|
-
type: "timing",
|
|
84
|
-
config: { duration: 300 },
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
animation(100, callback);
|
|
88
|
-
|
|
89
|
-
expect(callback).toHaveBeenCalledWith(true);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it("should handle spring animation with different values", () => {
|
|
93
|
-
const callback = jest.fn();
|
|
94
|
-
const animation = dealWithAnimation({
|
|
95
|
-
type: "spring",
|
|
96
|
-
config: { damping: 15 },
|
|
97
|
-
});
|
|
98
|
-
|
|
99
|
-
animation(0, callback);
|
|
100
|
-
animation(-100, callback);
|
|
101
|
-
animation(500, callback);
|
|
102
|
-
|
|
103
|
-
expect(withSpring).toHaveBeenCalledWith(0, { damping: 15 }, expect.any(Function));
|
|
104
|
-
expect(withSpring).toHaveBeenCalledWith(-100, { damping: 15 }, expect.any(Function));
|
|
105
|
-
expect(withSpring).toHaveBeenCalledWith(500, { damping: 15 }, expect.any(Function));
|
|
106
|
-
expect(callback).toHaveBeenCalledTimes(3);
|
|
107
|
-
});
|
|
108
|
-
|
|
109
|
-
it("should handle timing animation with different values", () => {
|
|
110
|
-
const callback = jest.fn();
|
|
111
|
-
const animation = dealWithAnimation({
|
|
112
|
-
type: "timing",
|
|
113
|
-
config: { duration: 500 },
|
|
114
|
-
});
|
|
115
|
-
|
|
116
|
-
animation(0, callback);
|
|
117
|
-
animation(-50, callback);
|
|
118
|
-
animation(1000, callback);
|
|
119
|
-
|
|
120
|
-
expect(withTiming).toHaveBeenCalledWith(0, { duration: 500 }, expect.any(Function));
|
|
121
|
-
expect(withTiming).toHaveBeenCalledWith(-50, { duration: 500 }, expect.any(Function));
|
|
122
|
-
expect(withTiming).toHaveBeenCalledWith(1000, { duration: 500 }, expect.any(Function));
|
|
123
|
-
expect(callback).toHaveBeenCalledTimes(3);
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it("should handle empty spring config", () => {
|
|
127
|
-
const callback = jest.fn();
|
|
128
|
-
const animation = dealWithAnimation({
|
|
129
|
-
type: "spring",
|
|
130
|
-
config: {},
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
animation(100, callback);
|
|
134
|
-
|
|
135
|
-
expect(withSpring).toHaveBeenCalledWith(100, {}, expect.any(Function));
|
|
136
|
-
expect(callback).toHaveBeenCalledWith(true);
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it("should handle empty timing config", () => {
|
|
140
|
-
const callback = jest.fn();
|
|
141
|
-
const animation = dealWithAnimation({
|
|
142
|
-
type: "timing",
|
|
143
|
-
config: {},
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
animation(100, callback);
|
|
147
|
-
|
|
148
|
-
expect(withTiming).toHaveBeenCalledWith(100, {}, expect.any(Function));
|
|
149
|
-
expect(callback).toHaveBeenCalledWith(true);
|
|
150
|
-
});
|
|
151
|
-
|
|
152
|
-
it("should handle fractional values", () => {
|
|
153
|
-
const callback = jest.fn();
|
|
154
|
-
const animation = dealWithAnimation({
|
|
155
|
-
type: "spring",
|
|
156
|
-
config: { damping: 10 },
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
animation(50.5, callback);
|
|
160
|
-
animation(-25.75, callback);
|
|
161
|
-
|
|
162
|
-
expect(withSpring).toHaveBeenCalledWith(50.5, { damping: 10 }, expect.any(Function));
|
|
163
|
-
expect(withSpring).toHaveBeenCalledWith(-25.75, { damping: 10 }, expect.any(Function));
|
|
164
|
-
});
|
|
165
|
-
|
|
166
|
-
it("should create different animation functions for different configs", () => {
|
|
167
|
-
const animation1 = dealWithAnimation({
|
|
168
|
-
type: "spring",
|
|
169
|
-
config: { damping: 10 },
|
|
170
|
-
});
|
|
171
|
-
|
|
172
|
-
const animation2 = dealWithAnimation({
|
|
173
|
-
type: "timing",
|
|
174
|
-
config: { duration: 200 },
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
expect(animation1).not.toBe(animation2);
|
|
178
|
-
expect(typeof animation1).toBe("function");
|
|
179
|
-
expect(typeof animation2).toBe("function");
|
|
180
|
-
});
|
|
181
|
-
});
|