react-native-reanimated-carousel 4.0.0-alpha.5 → 4.0.0-alpha.7

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.
Files changed (88) hide show
  1. package/lib/commonjs/{layouts → components}/BaseLayout.js +4 -2
  2. package/lib/commonjs/components/BaseLayout.js.map +1 -0
  3. package/lib/commonjs/components/Carousel.js +8 -5
  4. package/lib/commonjs/components/Carousel.js.map +1 -1
  5. package/lib/commonjs/components/ScrollViewGesture.js +34 -30
  6. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
  7. package/lib/commonjs/hooks/useCarouselController.js +4 -3
  8. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  9. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
  10. package/lib/commonjs/hooks/useOffsetX.js +9 -6
  11. package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
  12. package/lib/commonjs/hooks/useOffsetX.test.js +53 -0
  13. package/lib/commonjs/hooks/useOffsetX.test.js.map +1 -0
  14. package/lib/commonjs/hooks/usePanGestureProxy.js +84 -0
  15. package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
  16. package/lib/commonjs/hooks/usePanGestureProxy.test.js +397 -0
  17. package/lib/commonjs/hooks/usePanGestureProxy.test.js.map +1 -0
  18. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -1
  19. package/lib/commonjs/hooks/useVisibleRanges.js +20 -8
  20. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
  21. package/lib/commonjs/hooks/useVisibleRanges.test.js +162 -0
  22. package/lib/commonjs/hooks/useVisibleRanges.test.js.map +1 -0
  23. package/lib/commonjs/utils/handleroffset-direction.js +5 -5
  24. package/lib/commonjs/utils/handleroffset-direction.js.map +1 -1
  25. package/lib/commonjs/utils/handleroffset-direction.test.js +46 -0
  26. package/lib/commonjs/utils/handleroffset-direction.test.js.map +1 -0
  27. package/lib/module/{layouts → components}/BaseLayout.js +4 -2
  28. package/lib/module/components/BaseLayout.js.map +1 -0
  29. package/lib/module/components/Carousel.js +7 -4
  30. package/lib/module/components/Carousel.js.map +1 -1
  31. package/lib/module/components/ScrollViewGesture.js +36 -31
  32. package/lib/module/components/ScrollViewGesture.js.map +1 -1
  33. package/lib/module/hooks/useCarouselController.js +4 -3
  34. package/lib/module/hooks/useCarouselController.js.map +1 -1
  35. package/lib/module/hooks/useLayoutConfig.js.map +1 -1
  36. package/lib/module/hooks/useOffsetX.js +9 -6
  37. package/lib/module/hooks/useOffsetX.js.map +1 -1
  38. package/lib/module/hooks/useOffsetX.test.js +48 -0
  39. package/lib/module/hooks/useOffsetX.test.js.map +1 -0
  40. package/lib/module/hooks/usePanGestureProxy.js +71 -0
  41. package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
  42. package/lib/module/hooks/usePanGestureProxy.test.js +383 -0
  43. package/lib/module/hooks/usePanGestureProxy.test.js.map +1 -0
  44. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -1
  45. package/lib/module/hooks/useVisibleRanges.js +20 -8
  46. package/lib/module/hooks/useVisibleRanges.js.map +1 -1
  47. package/lib/module/hooks/useVisibleRanges.test.js +157 -0
  48. package/lib/module/hooks/useVisibleRanges.test.js.map +1 -0
  49. package/lib/module/utils/handleroffset-direction.js +5 -5
  50. package/lib/module/utils/handleroffset-direction.js.map +1 -1
  51. package/lib/module/utils/handleroffset-direction.test.js +41 -0
  52. package/lib/module/utils/handleroffset-direction.test.js.map +1 -0
  53. package/lib/typescript/hooks/useCarouselController.d.ts +2 -1
  54. package/lib/typescript/hooks/useLayoutConfig.d.ts +1 -1
  55. package/lib/typescript/hooks/useOffsetX.test.d.ts +1 -0
  56. package/lib/typescript/hooks/usePanGestureProxy.d.ts +9 -0
  57. package/lib/typescript/hooks/usePanGestureProxy.test.d.ts +1 -0
  58. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +3 -2
  59. package/lib/typescript/hooks/useVisibleRanges.d.ts +1 -0
  60. package/lib/typescript/hooks/useVisibleRanges.test.d.ts +1 -0
  61. package/lib/typescript/types.d.ts +5 -0
  62. package/lib/typescript/utils/handleroffset-direction.d.ts +2 -1
  63. package/lib/typescript/utils/handleroffset-direction.test.d.ts +1 -0
  64. package/package.json +2 -1
  65. package/src/{layouts → components}/BaseLayout.tsx +10 -8
  66. package/src/components/Carousel.tsx +5 -2
  67. package/src/components/ScrollViewGesture.tsx +48 -43
  68. package/src/hooks/useCarouselController.tsx +16 -13
  69. package/src/hooks/useLayoutConfig.ts +1 -1
  70. package/src/hooks/useOffsetX.test.ts +54 -0
  71. package/src/hooks/useOffsetX.ts +33 -31
  72. package/src/hooks/usePanGestureProxy.test.tsx +377 -0
  73. package/src/hooks/usePanGestureProxy.ts +110 -0
  74. package/src/hooks/useUpdateGestureConfig.ts +4 -2
  75. package/src/hooks/useVisibleRanges.test.tsx +179 -0
  76. package/src/hooks/useVisibleRanges.tsx +25 -9
  77. package/src/types.ts +5 -0
  78. package/src/utils/handleroffset-direction.test.ts +52 -0
  79. package/src/utils/handleroffset-direction.ts +12 -9
  80. package/lib/commonjs/layouts/BaseLayout.js.map +0 -1
  81. package/lib/commonjs/layouts/ParallaxLayout.js +0 -84
  82. package/lib/commonjs/layouts/ParallaxLayout.js.map +0 -1
  83. package/lib/module/layouts/BaseLayout.js.map +0 -1
  84. package/lib/module/layouts/ParallaxLayout.js +0 -61
  85. package/lib/module/layouts/ParallaxLayout.js.map +0 -1
  86. package/lib/typescript/layouts/ParallaxLayout.d.ts +0 -13
  87. package/src/layouts/ParallaxLayout.tsx +0 -141
  88. /package/lib/typescript/{layouts → components}/BaseLayout.d.ts +0 -0
@@ -0,0 +1,157 @@
1
+ import { useSharedValue } from "react-native-reanimated";
2
+ import { renderHook } from "@testing-library/react-hooks";
3
+ import { useVisibleRanges } from "./useVisibleRanges";
4
+ const viewSize = 393;
5
+ describe("useVisibleRanges", () => {
6
+ it("should only display the front of the list when loop is false", async () => {
7
+ const hook = renderHook(() => {
8
+ const translation = useSharedValue(-0);
9
+ const range = useVisibleRanges({
10
+ total: 10,
11
+ translation,
12
+ viewSize,
13
+ windowSize: 4,
14
+ loop: false
15
+ });
16
+ return range;
17
+ });
18
+ const expected = hook.result.current.value;
19
+ expect(expected).toMatchInlineSnapshot(`
20
+ {
21
+ "negativeRange": [
22
+ -3,
23
+ 0,
24
+ ],
25
+ "positiveRange": [
26
+ 0,
27
+ 3,
28
+ ],
29
+ }
30
+ `);
31
+ });
32
+ it("should display the rear of the list and the front of the list when loop is true", async () => {
33
+ const hook = renderHook(() => {
34
+ const translation = useSharedValue(-0);
35
+ const range = useVisibleRanges({
36
+ total: 10,
37
+ translation,
38
+ viewSize,
39
+ windowSize: 4,
40
+ loop: true
41
+ });
42
+ return range;
43
+ });
44
+ const expected = hook.result.current.value;
45
+ expect(expected).toMatchInlineSnapshot(`
46
+ {
47
+ "negativeRange": [
48
+ 8,
49
+ 9,
50
+ ],
51
+ "positiveRange": [
52
+ 0,
53
+ 2,
54
+ ],
55
+ }
56
+ `);
57
+ });
58
+ it("should shows the increased range of the list when the loop is false and swiped the carousel.", async () => {
59
+ const slide0hook = renderHook(() => {
60
+ const translation = useSharedValue(-0 * viewSize);
61
+ const range = useVisibleRanges({
62
+ total: 10,
63
+ translation,
64
+ viewSize,
65
+ windowSize: 4,
66
+ loop: false
67
+ });
68
+ return range;
69
+ }).result.current.value;
70
+ const slide1hook = renderHook(() => {
71
+ const translation = useSharedValue(-1 * viewSize);
72
+ const range = useVisibleRanges({
73
+ total: 10,
74
+ translation,
75
+ viewSize,
76
+ windowSize: 4,
77
+ loop: false
78
+ });
79
+ return range;
80
+ }).result.current.value;
81
+ const slide2hook = renderHook(() => {
82
+ const translation = useSharedValue(-2 * viewSize);
83
+ const range = useVisibleRanges({
84
+ total: 10,
85
+ translation,
86
+ viewSize,
87
+ windowSize: 4,
88
+ loop: false
89
+ });
90
+ return range;
91
+ }).result.current.value;
92
+ const slide3hook = renderHook(() => {
93
+ const translation = useSharedValue(-3 * viewSize);
94
+ const range = useVisibleRanges({
95
+ total: 10,
96
+ translation,
97
+ viewSize,
98
+ windowSize: 4,
99
+ loop: false
100
+ });
101
+ return range;
102
+ }).result.current.value; // [0,3] Display the 0,1,2,3 items.
103
+
104
+ expect(slide0hook).toMatchInlineSnapshot(`
105
+ {
106
+ "negativeRange": [
107
+ -3,
108
+ 0,
109
+ ],
110
+ "positiveRange": [
111
+ 0,
112
+ 3,
113
+ ],
114
+ }
115
+ `); // [1,4] Display the 1,2,3,4 items.
116
+
117
+ expect(slide1hook).toMatchInlineSnapshot(`
118
+ {
119
+ "negativeRange": [
120
+ -2,
121
+ 1,
122
+ ],
123
+ "positiveRange": [
124
+ 1,
125
+ 4,
126
+ ],
127
+ }
128
+ `); // [2,5] Display the 2,3,4,5 items.
129
+
130
+ expect(slide2hook).toMatchInlineSnapshot(`
131
+ {
132
+ "negativeRange": [
133
+ -1,
134
+ 2,
135
+ ],
136
+ "positiveRange": [
137
+ 2,
138
+ 5,
139
+ ],
140
+ }
141
+ `); // [3.6] Display the 3,4,5,6 items.
142
+
143
+ expect(slide3hook).toMatchInlineSnapshot(`
144
+ {
145
+ "negativeRange": [
146
+ 0,
147
+ 3,
148
+ ],
149
+ "positiveRange": [
150
+ 3,
151
+ 6,
152
+ ],
153
+ }
154
+ `);
155
+ });
156
+ });
157
+ //# sourceMappingURL=useVisibleRanges.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["useVisibleRanges.test.tsx"],"names":["useSharedValue","renderHook","useVisibleRanges","viewSize","describe","it","hook","translation","range","total","windowSize","loop","expected","result","current","value","expect","toMatchInlineSnapshot","slide0hook","slide1hook","slide2hook","slide3hook"],"mappings":"AAAA,SAASA,cAAT,QAA+B,yBAA/B;AAEA,SAASC,UAAT,QAA2B,8BAA3B;AAEA,SAASC,gBAAT,QAAiC,oBAAjC;AAEA,MAAMC,QAAQ,GAAG,GAAjB;AAEAC,QAAQ,CAAC,kBAAD,EAAqB,MAAM;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DC,KAXlB;AAaA,UAAMM,UAAU,GAAGpB,UAAU,CAAC,MAAM;AAClC,YAAMM,WAAW,GAAGP,cAAc,CAAC,CAAC,CAAD,GAAKG,QAAN,CAAlC;AACA,YAAMK,KAAK,GAAGN,gBAAgB,CAAC;AAC7BO,QAAAA,KAAK,EAAE,EADsB;AAE7BF,QAAAA,WAF6B;AAG7BJ,QAAAA,QAH6B;AAI7BO,QAAAA,UAAU,EAAE,CAJiB;AAK7BC,QAAAA,IAAI,EAAE;AALuB,OAAD,CAA9B;AAQA,aAAOH,KAAP;AACD,KAX4B,CAAV,CAWhBK,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,9 +1,9 @@
1
- export function handlerOffsetDirection(handlerOffset) {
1
+ export function handlerOffsetDirection(handlerOffset, fixedDirection) {
2
2
  "worklet";
3
3
 
4
- const isPositiveZero = Object.is(handlerOffset.value, +0);
5
- const isNegativeZero = Object.is(handlerOffset.value, -0);
6
- const direction = isPositiveZero ? 1 : isNegativeZero ? -1 : Math.sign(handlerOffset.value);
7
- return direction;
4
+ if (fixedDirection === "negative") return -1;
5
+ if (fixedDirection === "positive") return 1;
6
+ if (handlerOffset.value === 0) return -1;
7
+ return Math.sign(handlerOffset.value);
8
8
  }
9
9
  //# sourceMappingURL=handleroffset-direction.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["handleroffset-direction.ts"],"names":["handlerOffsetDirection","handlerOffset","isPositiveZero","Object","is","value","isNegativeZero","direction","Math","sign"],"mappings":"AAEA,OAAO,SAASA,sBAAT,CAAgCC,aAAhC,EAA4E;AACjF;;AAEA,QAAMC,cAAc,GAAGC,MAAM,CAACC,EAAP,CAAUH,aAAa,CAACI,KAAxB,EAA+B,CAAC,CAAhC,CAAvB;AACA,QAAMC,cAAc,GAAGH,MAAM,CAACC,EAAP,CAAUH,aAAa,CAACI,KAAxB,EAA+B,CAAC,CAAhC,CAAvB;AACA,QAAME,SAAS,GAAGL,cAAc,GAC5B,CAD4B,GAE5BI,cAAc,GACZ,CAAC,CADW,GAEZE,IAAI,CAACC,IAAL,CAAUR,aAAa,CAACI,KAAxB,CAJN;AAMA,SAAOE,SAAP;AACD","sourcesContent":["import type { SharedValue } from \"react-native-reanimated\";\n\nexport function handlerOffsetDirection(handlerOffset: SharedValue<number>): -1 | 1 {\n \"worklet\";\n\n const isPositiveZero = Object.is(handlerOffset.value, +0);\n const isNegativeZero = Object.is(handlerOffset.value, -0);\n const direction = isPositiveZero\n ? 1\n : isNegativeZero\n ? -1\n : Math.sign(handlerOffset.value) as -1 | 1;\n\n return direction;\n}\n"]}
1
+ {"version":3,"sources":["handleroffset-direction.ts"],"names":["handlerOffsetDirection","handlerOffset","fixedDirection","value","Math","sign"],"mappings":"AAIA,OAAO,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,41 @@
1
+ import { useSharedValue } from "react-native-reanimated";
2
+ import { renderHook } from "@testing-library/react-hooks";
3
+ import { handlerOffsetDirection } from "./handleroffset-direction";
4
+ describe("handlerOffsetDirection", () => {
5
+ it("should return -1 when default value equals to zero", () => {
6
+ const result = renderHook(() => {
7
+ const handlerOffsetAnimVal = useSharedValue(0);
8
+ return handlerOffsetDirection(handlerOffsetAnimVal);
9
+ });
10
+ expect(result.result.current).toBe(-1);
11
+ });
12
+ it("should return 1 when default value is greater than zero", () => {
13
+ const result = renderHook(() => {
14
+ const handlerOffsetAnimVal = useSharedValue(1);
15
+ return handlerOffsetDirection(handlerOffsetAnimVal);
16
+ });
17
+ expect(result.result.current).toBe(1);
18
+ });
19
+ it("should return -1 when default value is less than zero", () => {
20
+ const result = renderHook(() => {
21
+ const handlerOffsetAnimVal = useSharedValue(-1);
22
+ return handlerOffsetDirection(handlerOffsetAnimVal);
23
+ });
24
+ expect(result.result.current).toBe(-1);
25
+ });
26
+ it("should return 1 when default value equals to zero and fixedDirection is negative", () => {
27
+ const result = renderHook(() => {
28
+ const handlerOffsetAnimVal = useSharedValue(-1);
29
+ return handlerOffsetDirection(handlerOffsetAnimVal, "positive");
30
+ });
31
+ expect(result.result.current).toBe(1);
32
+ });
33
+ it("should return -1 when default value is greater than zero and fixedDirection is negative", () => {
34
+ const result = renderHook(() => {
35
+ const handlerOffsetAnimVal = useSharedValue(1);
36
+ return handlerOffsetDirection(handlerOffsetAnimVal, "negative");
37
+ });
38
+ expect(result.result.current).toBe(-1);
39
+ });
40
+ });
41
+ //# sourceMappingURL=handleroffset-direction.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["handleroffset-direction.test.ts"],"names":["useSharedValue","renderHook","handlerOffsetDirection","describe","it","result","handlerOffsetAnimVal","expect","current","toBe"],"mappings":"AAAA,SAASA,cAAT,QAA+B,yBAA/B;AAEA,SAASC,UAAT,QAA2B,8BAA3B;AAEA,SAASC,sBAAT,QAAuC,2BAAvC;AAEAC,QAAQ,CAAC,wBAAD,EAA2B,MAAM;AACvCC,EAAAA,EAAE,CAAC,oDAAD,EAAuD,MAAM;AAC7D,UAAMC,MAAM,GAAGJ,UAAU,CAAC,MAAM;AAC9B,YAAMK,oBAAoB,GAAGN,cAAc,CAAC,CAAD,CAA3C;AACA,aA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,CAAC,MAAM;AAC9B,YAAMK,oBAAoB,GAAGN,cAAc,CAAC,CAAD,CAA3C;AACA,aAAOE,sBAAsB,CAACI,oBAAD,EAAuB,UAAvB,CAA7B;AACD,KAHwB,CAAzB;AAKAC,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"]}
@@ -4,9 +4,10 @@ interface IOpts {
4
4
  loop: boolean;
5
5
  size: number;
6
6
  dataLength: number;
7
- autoFillData: TCarouselProps["autoFillData"];
8
7
  handlerOffset: Animated.SharedValue<number>;
8
+ autoFillData: TCarouselProps["autoFillData"];
9
9
  withAnimation?: TCarouselProps["withAnimation"];
10
+ fixedDirection?: TCarouselProps["fixedDirection"];
10
11
  duration?: number;
11
12
  defaultIndex?: number;
12
13
  onScrollBegin?: () => void;
@@ -1,5 +1,5 @@
1
1
  import type { TInitializeCarouselProps } from "./useInitProps";
2
- import type { TAnimationStyle } from "../layouts/BaseLayout";
2
+ import type { TAnimationStyle } from "../components/BaseLayout";
3
3
  declare type TLayoutConfigOpts<T> = TInitializeCarouselProps<T> & {
4
4
  size: number;
5
5
  };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,9 @@
1
+ import type { GestureStateChangeEvent, GestureUpdateEvent, PanGesture, PanGestureHandlerEventPayload } from "react-native-gesture-handler";
2
+ import type { GestureConfig } from "./useUpdateGestureConfig";
3
+ export declare const usePanGestureProxy: (customization: {
4
+ onConfigurePanGesture?: ((gesture: PanGesture) => void) | undefined;
5
+ onGestureBegin: (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>) => void;
6
+ onGestureUpdate: (event: GestureUpdateEvent<PanGestureHandlerEventPayload>) => void;
7
+ onGestureEnd: (event: GestureStateChangeEvent<PanGestureHandlerEventPayload>, success: boolean) => void;
8
+ options?: GestureConfig | undefined;
9
+ }) => import("react-native-gesture-handler/lib/typescript/handlers/gestures/panGesture").PanGesture;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,5 @@
1
1
  import type { PanGesture } from "react-native-gesture-handler";
2
- export declare const useUpdateGestureConfig: (gesture: PanGesture, config: {
2
+ export interface GestureConfig {
3
3
  enabled?: boolean;
4
- }) => void;
4
+ }
5
+ export declare const useUpdateGestureConfig: (gesture: PanGesture, config: GestureConfig) => void;
@@ -8,4 +8,5 @@ export declare function useVisibleRanges(options: {
8
8
  viewSize: number;
9
9
  windowSize?: number;
10
10
  translation: Animated.SharedValue<number>;
11
+ loop?: boolean;
11
12
  }): IVisibleRanges;
@@ -0,0 +1 @@
1
+ export {};
@@ -141,6 +141,11 @@ export declare type TCarouselProps<T = any> = {
141
141
  * props.vertical = false => maxScrollDistancePerSwipeX
142
142
  * */
143
143
  maxScrollDistancePerSwipe?: number;
144
+ /**
145
+ * @experimental This API will be changed in the future.
146
+ * If positive, the carousel will scroll to the positive direction and vice versa.
147
+ * */
148
+ fixedDirection?: "positive" | "negative";
144
149
  /**
145
150
  * Custom carousel config.
146
151
  */
@@ -1,2 +1,3 @@
1
1
  import type { SharedValue } from "react-native-reanimated";
2
- export declare function handlerOffsetDirection(handlerOffset: SharedValue<number>): -1 | 1;
2
+ import type { TCarouselProps } from "../types";
3
+ export declare function handlerOffsetDirection(handlerOffset: SharedValue<number>, fixedDirection?: TCarouselProps["fixedDirection"]): -1 | 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-reanimated-carousel",
3
- "version": "4.0.0-alpha.5",
3
+ "version": "4.0.0-alpha.7",
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",
@@ -63,6 +63,7 @@
63
63
  "del-cli": "^5.0.0",
64
64
  "eslint": "^8.26.0",
65
65
  "eslint-config-prettier": "^7.0.0",
66
+ "eslint-plugin-jest": "^27.6.0",
66
67
  "eslint-plugin-prettier": "^3.1.3",
67
68
  "gifify": "^2.4.3",
68
69
  "husky": "^4.2.5",
@@ -8,13 +8,13 @@ import Animated, {
8
8
  useDerivedValue,
9
9
  } from "react-native-reanimated";
10
10
 
11
- import type { ILayoutConfig } from "./stack";
11
+ import { LazyView } from "./LazyView";
12
12
 
13
- import { LazyView } from "../components/LazyView";
14
13
  import { useCheckMounted } from "../hooks/useCheckMounted";
15
14
  import type { IOpts } from "../hooks/useOffsetX";
16
15
  import { useOffsetX } from "../hooks/useOffsetX";
17
16
  import type { IVisibleRanges } from "../hooks/useVisibleRanges";
17
+ import type { ILayoutConfig } from "../layouts/stack";
18
18
  import { CTX } from "../store";
19
19
 
20
20
  export type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;
@@ -30,7 +30,7 @@ export const BaseLayout: React.FC<{
30
30
  }> = (props) => {
31
31
  const mounted = useCheckMounted();
32
32
  const { handlerOffset, index, children, visibleRanges, animationStyle }
33
- = props;
33
+ = props;
34
34
 
35
35
  const context = React.useContext(CTX);
36
36
  const {
@@ -73,17 +73,19 @@ export const BaseLayout: React.FC<{
73
73
  const x = useOffsetX(offsetXConfig, visibleRanges);
74
74
  const animationValue = useDerivedValue(() => x.value / size, [x, size]);
75
75
  const animatedStyle = useAnimatedStyle(
76
- () => animationStyle(x.value / size),
76
+ () => {
77
+ return animationStyle(x.value / size);
78
+ },
77
79
  [animationStyle],
78
80
  );
79
81
 
80
82
  const updateView = React.useCallback(
81
83
  (negativeRange: number[], positiveRange: number[]) => {
82
84
  mounted.current
83
- && setShouldUpdate(
84
- (index >= negativeRange[0] && index <= negativeRange[1])
85
- || (index >= positiveRange[0] && index <= positiveRange[1]),
86
- );
85
+ && setShouldUpdate(
86
+ (index >= negativeRange[0] && index <= negativeRange[1])
87
+ || (index >= positiveRange[0] && index <= positiveRange[1]),
88
+ );
87
89
  },
88
90
  [index, mounted],
89
91
  );
@@ -3,6 +3,7 @@ import { StyleSheet } from "react-native";
3
3
  import { GestureHandlerRootView } from "react-native-gesture-handler";
4
4
  import { runOnJS, useDerivedValue } from "react-native-reanimated";
5
5
 
6
+ import { BaseLayout } from "./BaseLayout";
6
7
  import { ScrollViewGesture } from "./ScrollViewGesture";
7
8
 
8
9
  import { useAutoPlay } from "../hooks/useAutoPlay";
@@ -13,7 +14,6 @@ import { useLayoutConfig } from "../hooks/useLayoutConfig";
13
14
  import { useOnProgressChange } from "../hooks/useOnProgressChange";
14
15
  import { usePropsErrorBoundary } from "../hooks/usePropsErrorBoundary";
15
16
  import { useVisibleRanges } from "../hooks/useVisibleRanges";
16
- import { BaseLayout } from "../layouts/BaseLayout";
17
17
  import { CTX } from "../store";
18
18
  import type { ICarouselInstance, TCarouselProps } from "../types";
19
19
  import { computedRealIndexWithAutoFillData } from "../utils/computed-with-auto-fill-data";
@@ -45,6 +45,7 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
45
45
  autoPlayInterval,
46
46
  scrollAnimationDuration,
47
47
  withAnimation,
48
+ fixedDirection,
48
49
  renderItem,
49
50
  onScrollEnd,
50
51
  onSnapToItem,
@@ -85,9 +86,10 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
85
86
  handlerOffset,
86
87
  withAnimation,
87
88
  defaultIndex,
89
+ fixedDirection,
90
+ duration: scrollAnimationDuration,
88
91
  onScrollEnd: () => runOnJS(_onScrollEnd)(),
89
92
  onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),
90
- duration: scrollAnimationDuration,
91
93
  });
92
94
 
93
95
  const { next, prev, scrollTo, getSharedIndex, getCurrentIndex }
@@ -158,6 +160,7 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
158
160
  viewSize: size,
159
161
  translation: handlerOffset,
160
162
  windowSize,
163
+ loop,
161
164
  });
162
165
 
163
166
  const layoutConfig = useLayoutConfig({ ...props, size });