react-native-reanimated-carousel 4.0.0-alpha.1 → 4.0.0-alpha.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (173) hide show
  1. package/README.md +2 -3
  2. package/lib/commonjs/{layouts → components}/BaseLayout.js +5 -21
  3. package/lib/commonjs/components/BaseLayout.js.map +1 -0
  4. package/lib/commonjs/components/Carousel.js +28 -48
  5. package/lib/commonjs/components/Carousel.js.map +1 -1
  6. package/lib/commonjs/components/ItemRenderer.js +80 -0
  7. package/lib/commonjs/components/ItemRenderer.js.map +1 -0
  8. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js +81 -0
  9. package/lib/commonjs/components/Pagination/Basic/PaginationItem.js.map +1 -0
  10. package/lib/commonjs/components/Pagination/Basic/index.js +57 -0
  11. package/lib/commonjs/components/Pagination/Basic/index.js.map +1 -0
  12. package/lib/commonjs/components/Pagination/index.js +14 -0
  13. package/lib/commonjs/components/Pagination/index.js.map +1 -0
  14. package/lib/commonjs/components/ScrollViewGesture.js +51 -33
  15. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -1
  16. package/lib/commonjs/components/rnr-demo.test.js +45 -0
  17. package/lib/commonjs/components/rnr-demo.test.js.map +1 -0
  18. package/lib/commonjs/hooks/useCarouselController.js +12 -11
  19. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  20. package/lib/commonjs/hooks/useCommonVariables.js +38 -12
  21. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
  22. package/lib/commonjs/hooks/useCommonVariables.test.js +38 -0
  23. package/lib/commonjs/hooks/useCommonVariables.test.js.map +1 -0
  24. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
  25. package/lib/commonjs/hooks/useOffsetX.js +9 -6
  26. package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
  27. package/lib/commonjs/hooks/useOffsetX.test.js +53 -0
  28. package/lib/commonjs/hooks/useOffsetX.test.js.map +1 -0
  29. package/lib/commonjs/hooks/useOnProgressChange.js +4 -1
  30. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
  31. package/lib/commonjs/hooks/usePanGestureProxy.js +84 -0
  32. package/lib/commonjs/hooks/usePanGestureProxy.js.map +1 -0
  33. package/lib/commonjs/hooks/usePanGestureProxy.test.js +397 -0
  34. package/lib/commonjs/hooks/usePanGestureProxy.test.js.map +1 -0
  35. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -1
  36. package/lib/commonjs/hooks/useVisibleRanges.js +48 -19
  37. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
  38. package/lib/commonjs/hooks/useVisibleRanges.test.js +162 -0
  39. package/lib/commonjs/hooks/useVisibleRanges.test.js.map +1 -0
  40. package/lib/commonjs/index.js +8 -0
  41. package/lib/commonjs/index.js.map +1 -1
  42. package/lib/commonjs/utils/{computeNewIndexWhenDataChanges.js → compute-offset-if-data-changed.js} +3 -3
  43. package/lib/commonjs/utils/compute-offset-if-data-changed.js.map +1 -0
  44. package/lib/commonjs/utils/compute-offset-if-data-changed.test.js +30 -0
  45. package/lib/commonjs/utils/compute-offset-if-data-changed.test.js.map +1 -0
  46. package/lib/commonjs/utils/compute-offset-if-size-changed.js +18 -0
  47. package/lib/commonjs/utils/compute-offset-if-size-changed.js.map +1 -0
  48. package/lib/commonjs/utils/compute-offset-if-size-changed.test.js +72 -0
  49. package/lib/commonjs/utils/compute-offset-if-size-changed.test.js.map +1 -0
  50. package/lib/commonjs/utils/handleroffset-direction.js +5 -5
  51. package/lib/commonjs/utils/handleroffset-direction.js.map +1 -1
  52. package/lib/commonjs/utils/handleroffset-direction.test.js +46 -0
  53. package/lib/commonjs/utils/handleroffset-direction.test.js.map +1 -0
  54. package/lib/commonjs/utils/index.test.js +6 -6
  55. package/lib/commonjs/utils/index.test.js.map +1 -1
  56. package/lib/module/{layouts → components}/BaseLayout.js +6 -16
  57. package/lib/module/components/BaseLayout.js.map +1 -0
  58. package/lib/module/components/Carousel.js +27 -44
  59. package/lib/module/components/Carousel.js.map +1 -1
  60. package/lib/module/components/ItemRenderer.js +62 -0
  61. package/lib/module/components/ItemRenderer.js.map +1 -0
  62. package/lib/module/components/Pagination/Basic/PaginationItem.js +63 -0
  63. package/lib/module/components/Pagination/Basic/PaginationItem.js.map +1 -0
  64. package/lib/module/components/Pagination/Basic/index.js +42 -0
  65. package/lib/module/components/Pagination/Basic/index.js.map +1 -0
  66. package/lib/module/components/Pagination/index.js +5 -0
  67. package/lib/module/components/Pagination/index.js.map +1 -0
  68. package/lib/module/components/ScrollViewGesture.js +53 -34
  69. package/lib/module/components/ScrollViewGesture.js.map +1 -1
  70. package/lib/module/components/rnr-demo.test.js +33 -0
  71. package/lib/module/components/rnr-demo.test.js.map +1 -0
  72. package/lib/module/hooks/useCarouselController.js +12 -11
  73. package/lib/module/hooks/useCarouselController.js.map +1 -1
  74. package/lib/module/hooks/useCommonVariables.js +38 -8
  75. package/lib/module/hooks/useCommonVariables.js.map +1 -1
  76. package/lib/module/hooks/useCommonVariables.test.js +34 -0
  77. package/lib/module/hooks/useCommonVariables.test.js.map +1 -0
  78. package/lib/module/hooks/useLayoutConfig.js.map +1 -1
  79. package/lib/module/hooks/useOffsetX.js +9 -6
  80. package/lib/module/hooks/useOffsetX.js.map +1 -1
  81. package/lib/module/hooks/useOffsetX.test.js +48 -0
  82. package/lib/module/hooks/useOffsetX.test.js.map +1 -0
  83. package/lib/module/hooks/useOnProgressChange.js +4 -1
  84. package/lib/module/hooks/useOnProgressChange.js.map +1 -1
  85. package/lib/module/hooks/usePanGestureProxy.js +71 -0
  86. package/lib/module/hooks/usePanGestureProxy.js.map +1 -0
  87. package/lib/module/hooks/usePanGestureProxy.test.js +383 -0
  88. package/lib/module/hooks/usePanGestureProxy.test.js.map +1 -0
  89. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -1
  90. package/lib/module/hooks/useVisibleRanges.js +47 -19
  91. package/lib/module/hooks/useVisibleRanges.js.map +1 -1
  92. package/lib/module/hooks/useVisibleRanges.test.js +157 -0
  93. package/lib/module/hooks/useVisibleRanges.test.js.map +1 -0
  94. package/lib/module/index.js +1 -0
  95. package/lib/module/index.js.map +1 -1
  96. package/lib/module/utils/{computeNewIndexWhenDataChanges.js → compute-offset-if-data-changed.js} +2 -2
  97. package/lib/module/utils/compute-offset-if-data-changed.js.map +1 -0
  98. package/lib/module/utils/compute-offset-if-data-changed.test.js +27 -0
  99. package/lib/module/utils/compute-offset-if-data-changed.test.js.map +1 -0
  100. package/lib/module/utils/compute-offset-if-size-changed.js +11 -0
  101. package/lib/module/utils/compute-offset-if-size-changed.js.map +1 -0
  102. package/lib/module/utils/compute-offset-if-size-changed.test.js +69 -0
  103. package/lib/module/utils/compute-offset-if-size-changed.test.js.map +1 -0
  104. package/lib/module/utils/handleroffset-direction.js +5 -5
  105. package/lib/module/utils/handleroffset-direction.js.map +1 -1
  106. package/lib/module/utils/handleroffset-direction.test.js +41 -0
  107. package/lib/module/utils/handleroffset-direction.test.js.map +1 -0
  108. package/lib/module/utils/index.test.js +6 -6
  109. package/lib/module/utils/index.test.js.map +1 -1
  110. package/lib/typescript/components/ItemRenderer.d.ts +22 -0
  111. package/lib/typescript/components/Pagination/Basic/PaginationItem.d.ts +17 -0
  112. package/lib/typescript/components/Pagination/Basic/index.d.ts +16 -0
  113. package/lib/typescript/components/Pagination/index.d.ts +3 -0
  114. package/lib/typescript/components/ScrollViewGesture.d.ts +1 -1
  115. package/lib/typescript/components/rnr-demo.test.d.ts +1 -0
  116. package/lib/typescript/hooks/useCarouselController.d.ts +3 -2
  117. package/lib/typescript/hooks/useCommonVariables.test.d.ts +1 -0
  118. package/lib/typescript/hooks/useLayoutConfig.d.ts +1 -1
  119. package/lib/typescript/hooks/useOffsetX.test.d.ts +1 -0
  120. package/lib/typescript/hooks/usePanGestureProxy.d.ts +9 -0
  121. package/lib/typescript/hooks/usePanGestureProxy.test.d.ts +1 -0
  122. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +3 -2
  123. package/lib/typescript/hooks/useVisibleRanges.d.ts +8 -4
  124. package/lib/typescript/hooks/useVisibleRanges.test.d.ts +1 -0
  125. package/lib/typescript/index.d.ts +2 -0
  126. package/lib/typescript/types.d.ts +27 -16
  127. package/lib/typescript/utils/{computeNewIndexWhenDataChanges.d.ts → compute-offset-if-data-changed.d.ts} +1 -1
  128. package/lib/typescript/utils/compute-offset-if-data-changed.test.d.ts +1 -0
  129. package/lib/typescript/utils/compute-offset-if-size-changed.d.ts +5 -0
  130. package/lib/typescript/utils/compute-offset-if-size-changed.test.d.ts +1 -0
  131. package/lib/typescript/utils/handleroffset-direction.d.ts +2 -1
  132. package/lib/typescript/utils/handleroffset-direction.test.d.ts +1 -0
  133. package/package.json +18 -60
  134. package/src/{layouts → components}/BaseLayout.tsx +7 -35
  135. package/src/components/Carousel.tsx +33 -71
  136. package/src/components/ItemRenderer.tsx +105 -0
  137. package/src/components/Pagination/Basic/PaginationItem.tsx +111 -0
  138. package/src/components/Pagination/Basic/index.tsx +81 -0
  139. package/src/components/Pagination/index.tsx +5 -0
  140. package/src/components/ScrollViewGesture.tsx +74 -49
  141. package/src/components/rnr-demo.test.tsx +43 -0
  142. package/src/hooks/useCarouselController.tsx +24 -21
  143. package/src/hooks/useCommonVariables.test.tsx +41 -0
  144. package/src/hooks/useCommonVariables.ts +35 -10
  145. package/src/hooks/useLayoutConfig.ts +1 -1
  146. package/src/hooks/useOffsetX.test.ts +54 -0
  147. package/src/hooks/useOffsetX.ts +33 -31
  148. package/src/hooks/useOnProgressChange.ts +7 -2
  149. package/src/hooks/usePanGestureProxy.test.tsx +376 -0
  150. package/src/hooks/usePanGestureProxy.ts +110 -0
  151. package/src/hooks/useUpdateGestureConfig.ts +4 -2
  152. package/src/hooks/useVisibleRanges.test.tsx +179 -0
  153. package/src/hooks/useVisibleRanges.tsx +72 -24
  154. package/src/index.tsx +3 -0
  155. package/src/types.ts +28 -17
  156. package/src/utils/compute-offset-if-data-changed.test.ts +30 -0
  157. package/src/utils/{computeNewIndexWhenDataChanges.ts → compute-offset-if-data-changed.ts} +1 -1
  158. package/src/utils/compute-offset-if-size-changed.test.ts +78 -0
  159. package/src/utils/compute-offset-if-size-changed.ts +11 -0
  160. package/src/utils/handleroffset-direction.test.ts +52 -0
  161. package/src/utils/handleroffset-direction.ts +12 -9
  162. package/src/utils/index.test.ts +6 -6
  163. package/lib/commonjs/layouts/BaseLayout.js.map +0 -1
  164. package/lib/commonjs/layouts/ParallaxLayout.js +0 -84
  165. package/lib/commonjs/layouts/ParallaxLayout.js.map +0 -1
  166. package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js.map +0 -1
  167. package/lib/module/layouts/BaseLayout.js.map +0 -1
  168. package/lib/module/layouts/ParallaxLayout.js +0 -61
  169. package/lib/module/layouts/ParallaxLayout.js.map +0 -1
  170. package/lib/module/utils/computeNewIndexWhenDataChanges.js.map +0 -1
  171. package/lib/typescript/layouts/ParallaxLayout.d.ts +0 -13
  172. package/src/layouts/ParallaxLayout.tsx +0 -141
  173. /package/lib/typescript/{layouts → components}/BaseLayout.d.ts +0 -0
@@ -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
+ onGestureStart: (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;
@@ -1,11 +1,15 @@
1
1
  import type Animated from "react-native-reanimated";
2
- export declare type IVisibleRanges = Animated.SharedValue<{
3
- negativeRange: number[];
4
- positiveRange: number[];
5
- }>;
2
+ declare type Range = [number, number];
3
+ export interface VisibleRanges {
4
+ negativeRange: Range;
5
+ positiveRange: Range;
6
+ }
7
+ export declare type IVisibleRanges = Animated.SharedValue<VisibleRanges>;
6
8
  export declare function useVisibleRanges(options: {
7
9
  total: number;
8
10
  viewSize: number;
9
11
  windowSize?: number;
10
12
  translation: Animated.SharedValue<number>;
13
+ loop?: boolean;
11
14
  }): IVisibleRanges;
15
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,4 +1,6 @@
1
1
  import Carousel from "./components/Carousel";
2
+ export { Pagination } from "./components/Pagination";
2
3
  export type { TCarouselProps, ICarouselInstance, IComputedDirectionTypes, CarouselRenderItem, } from "./types";
4
+ export type { TAnimationStyle } from "./components/BaseLayout";
3
5
  export type { ILayoutConfig } from "./layouts/stack";
4
6
  export default Carousel;
@@ -137,10 +137,19 @@ export declare type TCarouselProps<T = any> = {
137
137
  testID?: string;
138
138
  /**
139
139
  * Maximum offset value for once scroll.
140
- * props.vertical = true => maxScrollDistancePerSwipeY
141
- * props.vertical = false => maxScrollDistancePerSwipeX
140
+ * Carousel cannot scroll over than this value.
142
141
  * */
143
142
  maxScrollDistancePerSwipe?: number;
143
+ /**
144
+ * Minimum offset value for once scroll.
145
+ * If the translation value is less than this value, the carousel will not scroll.
146
+ * */
147
+ minScrollDistancePerSwipe?: number;
148
+ /**
149
+ * @experimental This API will be changed in the future.
150
+ * If positive, the carousel will scroll to the positive direction and vice versa.
151
+ * */
152
+ fixedDirection?: "positive" | "negative";
144
153
  /**
145
154
  * Custom carousel config.
146
155
  */
@@ -159,9 +168,9 @@ export declare type TCarouselProps<T = any> = {
159
168
  */
160
169
  onSnapToItem?: (index: number) => void;
161
170
  /**
162
- * On scroll begin
171
+ * On scroll start
163
172
  */
164
- onScrollBegin?: () => void;
173
+ onScrollStart?: () => void;
165
174
  /**
166
175
  * On scroll end
167
176
  */
@@ -170,8 +179,10 @@ export declare type TCarouselProps<T = any> = {
170
179
  * On progress change
171
180
  * @param offsetProgress Total of offset distance (0 390 780 ...)
172
181
  * @param absoluteProgress Convert to index (0 1 2 ...)
182
+ *
183
+ * If you want to update a shared value automatically, you can use the shared value as a parameter directly.
173
184
  */
174
- onProgressChange?: (offsetProgress: number, absoluteProgress: number) => void;
185
+ onProgressChange?: ((offsetProgress: number, absoluteProgress: number) => void) | SharedValue<number>;
175
186
  /**
176
187
  * If enabled, releasing the touch will scroll to the nearest item.
177
188
  * valid when pagingEnabled=false
@@ -181,23 +192,23 @@ export declare type TCarouselProps<T = any> = {
181
192
  } & (TParallaxModeProps | TStackModeProps);
182
193
  export interface ICarouselInstance {
183
194
  /**
184
- * Scroll to previous item, it takes one optional argument (count),
185
- * which allows you to specify how many items to cross
186
- */
195
+ * Scroll to previous item, it takes one optional argument (count),
196
+ * which allows you to specify how many items to cross
197
+ */
187
198
  prev: (opts?: Omit<TCarouselActionOptions, "index">) => void;
188
199
  /**
189
- * Scroll to next item, it takes one optional argument (count),
190
- * which allows you to specify how many items to cross
191
- */
200
+ * Scroll to next item, it takes one optional argument (count),
201
+ * which allows you to specify how many items to cross
202
+ */
192
203
  next: (opts?: Omit<TCarouselActionOptions, "index">) => void;
193
204
  /**
194
- * Get current item index
195
- */
205
+ * Get current item index
206
+ */
196
207
  getCurrentIndex: () => number;
197
208
  /**
198
- * Use value to scroll to a position where relative to the current position,
199
- * scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
200
- */
209
+ * Use value to scroll to a position where relative to the current position,
210
+ * scrollTo({count: -2}) is equivalent to prev(2), scrollTo({count: 2}) is equivalent to next(2)
211
+ */
201
212
  scrollTo: (opts?: TCarouselActionOptions) => void;
202
213
  }
203
214
  export interface CarouselRenderItemInfo<ItemT> {
@@ -1,5 +1,5 @@
1
1
  export declare function omitZero(a: number, b: number): number;
2
- export declare function computeNewIndexWhenDataChanges(params: {
2
+ export declare function computeOffsetIfDataChanged(params: {
3
3
  direction: number;
4
4
  handlerOffset: number;
5
5
  size: number;
@@ -0,0 +1,5 @@
1
+ export declare function computeOffsetIfSizeChanged(params: {
2
+ handlerOffset: number;
3
+ prevSize: number;
4
+ size: number;
5
+ }): number;
@@ -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.1",
3
+ "version": "4.0.0-alpha.11",
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,24 +14,13 @@
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
- "ios": "yarn --cwd exampleExpo ios",
26
- "ios:pretty": "yarn --cwd exampleExpo ios:pretty",
27
- "web": "yarn --cwd exampleExpo web",
28
- "web:pretty": "yarn --cwd exampleExpo web:pretty",
29
- "android": "yarn --cwd exampleExpo android",
30
- "android:pretty": "yarn --cwd exampleExpo android:pretty",
31
- "pods": "cd exampleExpo && pod-install --quiet",
32
- "bootstrap": "yarn && yarn pods",
33
- "deploy": "cd exampleExpo && yarn deploy",
34
- "publish": "yarn run prepare && changeset publish",
23
+ "clean": "del-cli lib",
35
24
  "version": "changeset version"
36
25
  },
37
26
  "keywords": [
@@ -39,7 +28,10 @@
39
28
  "ios",
40
29
  "android"
41
30
  ],
42
- "repository": "https://github.com/dohooo/react-native-reanimated-carousel",
31
+ "repository": {
32
+ "type": "git",
33
+ "url": "git+https://github.com/dohooo/react-native-reanimated-carousel.git"
34
+ },
43
35
  "author": "Doho <zhaodonghao586@outlook.com> (https://github.com/dohooo)",
44
36
  "license": "MIT",
45
37
  "bugs": {
@@ -50,24 +42,29 @@
50
42
  "registry": "https://registry.npmjs.org/"
51
43
  },
52
44
  "devDependencies": {
45
+ "@babel/plugin-proposal-class-properties": "^7.18.6",
46
+ "@babel/plugin-proposal-private-methods": "^7.18.6",
53
47
  "@babel/plugin-syntax-dynamic-import": "^7.8.3",
54
48
  "@changesets/changelog-github": "^0.5.0",
55
49
  "@changesets/cli": "latest",
56
50
  "@commitlint/config-conventional": "^11.0.0",
57
51
  "@dohooo/eslint-config": "^0.0.7",
58
52
  "@react-native-community/eslint-config": "^2.0.0",
59
- "@release-it/conventional-changelog": "^2.0.0",
53
+ "@stylistic/eslint-plugin-js": "^1.8.0",
54
+ "@testing-library/jest-native": "^4.0.4",
55
+ "@testing-library/react-hooks": "^8.0.0",
56
+ "@testing-library/react-native": "^7.1.0",
60
57
  "@types/jest": "^29.2.5",
61
58
  "@types/react": "^18.2.15",
62
59
  "@types/react-native": "^0.66.16",
63
- "@types/react-native-snap-carousel": "^3.8.5",
64
- "babel-plugin-inline-dotenv": "^1.6.0",
60
+ "@types/react-test-renderer": "^18.0.7",
65
61
  "babel-plugin-module-resolver": "^4.1.0",
66
62
  "commitlint": "^11.0.0",
67
63
  "cz-conventional-changelog": "^3.3.0",
68
- "dotenv-cli": "^5.1.0",
69
- "eslint": "^8.26.0",
64
+ "del-cli": "^5.0.0",
65
+ "eslint": "^8.57.0",
70
66
  "eslint-config-prettier": "^7.0.0",
67
+ "eslint-plugin-jest": "^27.6.0",
71
68
  "eslint-plugin-prettier": "^3.1.3",
72
69
  "gifify": "^2.4.3",
73
70
  "husky": "^4.2.5",
@@ -80,7 +77,7 @@
80
77
  "react-native-builder-bob": "^0.18.1",
81
78
  "react-native-gesture-handler": "~2.12.0",
82
79
  "react-native-reanimated": "~3.3.0",
83
- "release-it": "^14.2.2",
80
+ "react-test-renderer": "^18.2.0",
84
81
  "sponsorkit": "^0.1.3",
85
82
  "typescript": "^4.0.8",
86
83
  "watch": "^1.0.2"
@@ -101,14 +98,6 @@
101
98
  "optional": true
102
99
  }
103
100
  },
104
- "jest": {
105
- "preset": "react-native",
106
- "modulePathIgnorePatterns": [
107
- "<rootDir>/exampleExpo/node_modules",
108
- "<rootDir>/exampleBare/node_modules",
109
- "<rootDir>/lib/"
110
- ]
111
- },
112
101
  "husky": {
113
102
  "hooks": {
114
103
  "commit-msg": "commitlint -E HUSKY_GIT_PARAMS",
@@ -120,37 +109,6 @@
120
109
  "@commitlint/config-conventional"
121
110
  ]
122
111
  },
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
112
  "react-native-builder-bob": {
155
113
  "source": "src",
156
114
  "output": "lib",
@@ -2,19 +2,14 @@ import React from "react";
2
2
  import type { ViewStyle } from "react-native";
3
3
  import type { AnimatedStyleProp } from "react-native-reanimated";
4
4
  import Animated, {
5
- runOnJS,
6
- useAnimatedReaction,
7
5
  useAnimatedStyle,
8
6
  useDerivedValue,
9
7
  } from "react-native-reanimated";
10
8
 
11
- import type { ILayoutConfig } from "./stack";
12
-
13
- import { LazyView } from "../components/LazyView";
14
- import { useCheckMounted } from "../hooks/useCheckMounted";
15
9
  import type { IOpts } from "../hooks/useOffsetX";
16
10
  import { useOffsetX } from "../hooks/useOffsetX";
17
11
  import type { IVisibleRanges } from "../hooks/useVisibleRanges";
12
+ import type { ILayoutConfig } from "../layouts/stack";
18
13
  import { CTX } from "../store";
19
14
 
20
15
  export type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;
@@ -28,9 +23,8 @@ export const BaseLayout: React.FC<{
28
23
  animationValue: Animated.SharedValue<number>
29
24
  }) => React.ReactElement
30
25
  }> = (props) => {
31
- const mounted = useCheckMounted();
32
26
  const { handlerOffset, index, children, visibleRanges, animationStyle }
33
- = props;
27
+ = props;
34
28
 
35
29
  const context = React.useContext(CTX);
36
30
  const {
@@ -46,7 +40,7 @@ export const BaseLayout: React.FC<{
46
40
  },
47
41
  } = context;
48
42
  const size = vertical ? height : width;
49
- const [shouldUpdate, setShouldUpdate] = React.useState(false);
43
+
50
44
  let offsetXConfig: IOpts = {
51
45
  handlerOffset,
52
46
  index,
@@ -73,30 +67,10 @@ export const BaseLayout: React.FC<{
73
67
  const x = useOffsetX(offsetXConfig, visibleRanges);
74
68
  const animationValue = useDerivedValue(() => x.value / size, [x, size]);
75
69
  const animatedStyle = useAnimatedStyle(
76
- () => animationStyle(x.value / size),
77
- [animationStyle],
78
- );
79
-
80
- const updateView = React.useCallback(
81
- (negativeRange: number[], positiveRange: number[]) => {
82
- mounted.current
83
- && setShouldUpdate(
84
- (index >= negativeRange[0] && index <= negativeRange[1])
85
- || (index >= positiveRange[0] && index <= positiveRange[1]),
86
- );
87
- },
88
- [index, mounted],
89
- );
90
-
91
- useAnimatedReaction(
92
- () => visibleRanges.value,
93
70
  () => {
94
- runOnJS(updateView)(
95
- visibleRanges.value.negativeRange,
96
- visibleRanges.value.positiveRange,
97
- );
71
+ return animationStyle(x.value / size);
98
72
  },
99
- [visibleRanges.value],
73
+ [animationStyle],
100
74
  );
101
75
 
102
76
  return (
@@ -114,11 +88,9 @@ export const BaseLayout: React.FC<{
114
88
  * e.g.
115
89
  * The testID of first item will be changed to __CAROUSEL_ITEM_0_READY__ from __CAROUSEL_ITEM_0_NOT_READY__ when the item is ready.
116
90
  * */
117
- testID={`__CAROUSEL_ITEM_${index}_${shouldUpdate ? "READY" : "NOT_READY"}__`}
91
+ testID={`__CAROUSEL_ITEM_${index}__`}
118
92
  >
119
- <LazyView shouldUpdate={shouldUpdate}>
120
- {children({ animationValue })}
121
- </LazyView>
93
+ {children({ animationValue })}
122
94
  </Animated.View>
123
95
  );
124
96
  };
@@ -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 { ItemRenderer } from "./ItemRenderer";
6
7
  import { ScrollViewGesture } from "./ScrollViewGesture";
7
8
 
8
9
  import { useAutoPlay } from "../hooks/useAutoPlay";
@@ -12,8 +13,6 @@ import { useInitProps } from "../hooks/useInitProps";
12
13
  import { useLayoutConfig } from "../hooks/useLayoutConfig";
13
14
  import { useOnProgressChange } from "../hooks/useOnProgressChange";
14
15
  import { usePropsErrorBoundary } from "../hooks/usePropsErrorBoundary";
15
- import { useVisibleRanges } from "../hooks/useVisibleRanges";
16
- import { BaseLayout } from "../layouts/BaseLayout";
17
16
  import { CTX } from "../store";
18
17
  import type { ICarouselInstance, TCarouselProps } from "../types";
19
18
  import { computedRealIndexWithAutoFillData } from "../utils/computed-with-auto-fill-data";
@@ -30,8 +29,6 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
30
29
  data,
31
30
  // Length of fill data
32
31
  dataLength,
33
- // Raw data that has not been processed
34
- rawData,
35
32
  // Length of raw data
36
33
  rawDataLength,
37
34
  mode,
@@ -45,10 +42,11 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
45
42
  autoPlayInterval,
46
43
  scrollAnimationDuration,
47
44
  withAnimation,
45
+ fixedDirection,
48
46
  renderItem,
49
47
  onScrollEnd,
50
48
  onSnapToItem,
51
- onScrollBegin,
49
+ onScrollStart,
52
50
  onProgressChange,
53
51
  customAnimation,
54
52
  defaultIndex,
@@ -61,14 +59,13 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
61
59
  const totalSize = size * dataLength;
62
60
  const x = handlerOffset.value % totalSize;
63
61
 
64
- if (!loop)
65
- return handlerOffset.value;
62
+ if (!loop) return handlerOffset.value;
66
63
 
67
64
  return isNaN(x) ? 0 : x;
68
65
  }, [loop, size, dataLength]);
69
66
 
70
67
  usePropsErrorBoundary({ ...props, dataLength });
71
- useOnProgressChange({
68
+ const progressValue = useOnProgressChange({
72
69
  autoFillData,
73
70
  loop,
74
71
  size,
@@ -85,13 +82,14 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
85
82
  handlerOffset,
86
83
  withAnimation,
87
84
  defaultIndex,
88
- onScrollEnd: () => runOnJS(_onScrollEnd)(),
89
- onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),
85
+ fixedDirection,
90
86
  duration: scrollAnimationDuration,
87
+ onScrollEnd: () => runOnJS(_onScrollEnd)(),
88
+ onScrollStart: () => !!onScrollStart && runOnJS(onScrollStart)(),
91
89
  });
92
90
 
93
- const { next, prev, scrollTo, getSharedIndex, getCurrentIndex }
94
- = carouselController;
91
+ const { next, prev, scrollTo, getSharedIndex, getCurrentIndex } =
92
+ carouselController;
95
93
 
96
94
  const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({
97
95
  autoPlay,
@@ -110,11 +108,9 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
110
108
  autoFillData,
111
109
  });
112
110
 
113
- if (onSnapToItem)
114
- onSnapToItem(realIndex);
111
+ if (onSnapToItem) onSnapToItem(realIndex);
115
112
 
116
- if (onScrollEnd)
117
- onScrollEnd(realIndex);
113
+ if (onScrollEnd) onScrollEnd(realIndex);
118
114
  }, [
119
115
  loop,
120
116
  autoFillData,
@@ -124,10 +120,10 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
124
120
  onScrollEnd,
125
121
  ]);
126
122
 
127
- const scrollViewGestureOnScrollBegin = React.useCallback(() => {
123
+ const scrollViewGestureOnScrollStart = React.useCallback(() => {
128
124
  pauseAutoPlay();
129
- onScrollBegin?.();
130
- }, [onScrollBegin, pauseAutoPlay]);
125
+ onScrollStart?.();
126
+ }, [onScrollStart, pauseAutoPlay]);
131
127
 
132
128
  const scrollViewGestureOnScrollEnd = React.useCallback(() => {
133
129
  startAutoPlay();
@@ -149,58 +145,13 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
149
145
  prev,
150
146
  getCurrentIndex,
151
147
  scrollTo,
148
+ progressValue,
152
149
  }),
153
150
  [getCurrentIndex, next, prev, scrollTo],
154
151
  );
155
152
 
156
- const visibleRanges = useVisibleRanges({
157
- total: dataLength,
158
- viewSize: size,
159
- translation: handlerOffset,
160
- windowSize,
161
- });
162
-
163
153
  const layoutConfig = useLayoutConfig({ ...props, size });
164
154
 
165
- const renderLayout = React.useCallback(
166
- (item: any, i: number) => {
167
- const realIndex = computedRealIndexWithAutoFillData({
168
- index: i,
169
- dataLength: rawDataLength,
170
- loop,
171
- autoFillData,
172
- });
173
-
174
- return (
175
- <BaseLayout
176
- key={i}
177
- index={i}
178
- handlerOffset={offsetX}
179
- visibleRanges={visibleRanges}
180
- animationStyle={customAnimation || layoutConfig}
181
- >
182
- {({ animationValue }) =>
183
- renderItem({
184
- item,
185
- index: realIndex,
186
- animationValue,
187
- })
188
- }
189
- </BaseLayout>
190
- );
191
- },
192
- [
193
- loop,
194
- rawData,
195
- offsetX,
196
- visibleRanges,
197
- autoFillData,
198
- renderItem,
199
- layoutConfig,
200
- customAnimation,
201
- ],
202
- );
203
-
204
155
  return (
205
156
  <GestureHandlerRootView>
206
157
  <CTX.Provider value={{ props, common: commonVariables }}>
@@ -215,17 +166,28 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
215
166
  height: height || "100%",
216
167
  },
217
168
  style,
218
- vertical
219
- ? styles.itemsVertical
220
- : styles.itemsHorizontal,
169
+ vertical ? styles.itemsVertical : styles.itemsHorizontal,
221
170
  ]}
222
171
  testID={testID}
223
- onScrollBegin={scrollViewGestureOnScrollBegin}
172
+ onScrollStart={scrollViewGestureOnScrollStart}
224
173
  onScrollEnd={scrollViewGestureOnScrollEnd}
225
174
  onTouchBegin={scrollViewGestureOnTouchBegin}
226
175
  onTouchEnd={scrollViewGestureOnTouchEnd}
227
176
  >
228
- {data.map(renderLayout)}
177
+ <ItemRenderer
178
+ data={data}
179
+ dataLength={dataLength}
180
+ rawDataLength={rawDataLength}
181
+ loop={loop}
182
+ size={size}
183
+ windowSize={windowSize}
184
+ autoFillData={autoFillData}
185
+ offsetX={offsetX}
186
+ handlerOffset={handlerOffset}
187
+ layoutConfig={layoutConfig}
188
+ renderItem={renderItem}
189
+ customAnimation={customAnimation}
190
+ />
229
191
  </ScrollViewGesture>
230
192
  </CTX.Provider>
231
193
  </GestureHandlerRootView>
@@ -234,7 +196,7 @@ const Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(
234
196
  );
235
197
 
236
198
  export default Carousel as <T extends any>(
237
- props: React.PropsWithChildren<TCarouselProps<T>>
199
+ props: React.PropsWithChildren<TCarouselProps<T>>,
238
200
  ) => React.ReactElement;
239
201
 
240
202
  const styles = StyleSheet.create({