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

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 (143) hide show
  1. package/README.md +21 -160
  2. package/lib/commonjs/components/Carousel.js +231 -0
  3. package/lib/commonjs/components/Carousel.js.map +1 -0
  4. package/lib/commonjs/components/LazyView.js +22 -0
  5. package/lib/commonjs/components/LazyView.js.map +1 -0
  6. package/lib/commonjs/components/ScrollViewGesture.js +297 -0
  7. package/lib/commonjs/components/ScrollViewGesture.js.map +1 -0
  8. package/lib/commonjs/constants/index.js +21 -1
  9. package/lib/commonjs/constants/index.js.map +1 -1
  10. package/lib/commonjs/hooks/useAutoPlay.js +56 -1
  11. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
  12. package/lib/commonjs/hooks/useCarouselController.js +244 -1
  13. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  14. package/lib/commonjs/hooks/useCheckMounted.js +23 -1
  15. package/lib/commonjs/hooks/useCheckMounted.js.map +1 -1
  16. package/lib/commonjs/hooks/useCommonVariables.js +76 -1
  17. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
  18. package/lib/commonjs/hooks/useInitProps.js +78 -1
  19. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  20. package/lib/commonjs/hooks/useLayoutConfig.js +39 -1
  21. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
  22. package/lib/commonjs/hooks/useOffsetX.js +48 -1
  23. package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
  24. package/lib/commonjs/hooks/useOnProgressChange.js +38 -1
  25. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
  26. package/lib/commonjs/hooks/usePropsErrorBoundary.js +36 -1
  27. package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
  28. package/lib/commonjs/hooks/useUpdateGestureConfig.js +20 -0
  29. package/lib/commonjs/hooks/useUpdateGestureConfig.js.map +1 -0
  30. package/lib/commonjs/hooks/useVisibleRanges.js +42 -1
  31. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
  32. package/lib/commonjs/index.js +13 -1
  33. package/lib/commonjs/index.js.map +1 -1
  34. package/lib/commonjs/layouts/BaseLayout.js +110 -1
  35. package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
  36. package/lib/commonjs/layouts/ParallaxLayout.js +83 -1
  37. package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
  38. package/lib/commonjs/layouts/index.js +20 -1
  39. package/lib/commonjs/layouts/index.js.map +1 -1
  40. package/lib/commonjs/layouts/normal.js +27 -1
  41. package/lib/commonjs/layouts/normal.js.map +1 -1
  42. package/lib/commonjs/layouts/parallax.js +38 -1
  43. package/lib/commonjs/layouts/parallax.js.map +1 -1
  44. package/lib/commonjs/layouts/stack.js +215 -1
  45. package/lib/commonjs/layouts/stack.js.map +1 -1
  46. package/lib/commonjs/store/index.js +14 -1
  47. package/lib/commonjs/store/index.js.map +1 -1
  48. package/lib/commonjs/types.js +5 -1
  49. package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js +52 -0
  50. package/lib/commonjs/utils/computeNewIndexWhenDataChanges.js.map +1 -0
  51. package/lib/commonjs/utils/computed-with-auto-fill-data.js +124 -0
  52. package/lib/commonjs/utils/computed-with-auto-fill-data.js.map +1 -0
  53. package/lib/commonjs/utils/deal-with-animation.js +21 -0
  54. package/lib/commonjs/utils/deal-with-animation.js.map +1 -0
  55. package/lib/commonjs/utils/handleroffset-direction.js +16 -0
  56. package/lib/commonjs/utils/handleroffset-direction.js.map +1 -0
  57. package/lib/commonjs/utils/index.test.js +74 -0
  58. package/lib/commonjs/utils/index.test.js.map +1 -0
  59. package/lib/commonjs/utils/log.js +22 -1
  60. package/lib/commonjs/utils/log.js.map +1 -1
  61. package/lib/module/{Carousel.js → components/Carousel.js} +11 -12
  62. package/lib/module/components/Carousel.js.map +1 -0
  63. package/lib/module/{ScrollViewGesture.js → components/ScrollViewGesture.js} +14 -6
  64. package/lib/module/components/ScrollViewGesture.js.map +1 -0
  65. package/lib/module/hooks/useCarouselController.js +3 -3
  66. package/lib/module/hooks/useCarouselController.js.map +1 -1
  67. package/lib/module/hooks/useCommonVariables.js +2 -2
  68. package/lib/module/hooks/useCommonVariables.js.map +1 -1
  69. package/lib/module/hooks/useInitProps.js +1 -3
  70. package/lib/module/hooks/useInitProps.js.map +1 -1
  71. package/lib/module/hooks/useOnProgressChange.js +1 -1
  72. package/lib/module/hooks/useOnProgressChange.js.map +1 -1
  73. package/lib/module/hooks/useUpdateGestureConfig.js +10 -0
  74. package/lib/module/hooks/useUpdateGestureConfig.js.map +1 -0
  75. package/lib/module/index.js +1 -2
  76. package/lib/module/index.js.map +1 -1
  77. package/lib/module/layouts/BaseLayout.js +1 -1
  78. package/lib/module/layouts/BaseLayout.js.map +1 -1
  79. package/lib/module/layouts/ParallaxLayout.js +1 -1
  80. package/lib/module/layouts/ParallaxLayout.js.map +1 -1
  81. package/lib/module/utils/{computedWithAutoFillData.js → computed-with-auto-fill-data.js} +1 -1
  82. package/lib/module/utils/computed-with-auto-fill-data.js.map +1 -0
  83. package/lib/module/utils/{dealWithAnimation.js → deal-with-animation.js} +1 -1
  84. package/lib/module/utils/deal-with-animation.js.map +1 -0
  85. package/lib/module/utils/{handlerOffsetDirection.js → handleroffset-direction.js} +1 -1
  86. package/lib/module/utils/handleroffset-direction.js.map +1 -0
  87. package/lib/typescript/{Carousel.d.ts → components/Carousel.d.ts} +1 -1
  88. package/lib/typescript/hooks/useUpdateGestureConfig.d.ts +4 -0
  89. package/lib/typescript/index.d.ts +2 -2
  90. package/lib/typescript/types.d.ts +103 -103
  91. package/package.json +18 -16
  92. package/src/{Carousel.tsx → components/Carousel.tsx} +13 -13
  93. package/src/{ScrollViewGesture.tsx → components/ScrollViewGesture.tsx} +30 -15
  94. package/src/hooks/useCarouselController.tsx +3 -3
  95. package/src/hooks/useCommonVariables.ts +2 -2
  96. package/src/hooks/useInitProps.ts +1 -3
  97. package/src/hooks/useOnProgressChange.ts +1 -1
  98. package/src/hooks/useUpdateGestureConfig.ts +13 -0
  99. package/src/index.tsx +2 -2
  100. package/src/layouts/BaseLayout.tsx +1 -1
  101. package/src/layouts/ParallaxLayout.tsx +1 -1
  102. package/src/types.ts +122 -124
  103. package/README.zh-CN.md +0 -202
  104. package/lib/commonjs/Carousel.js +0 -2
  105. package/lib/commonjs/Carousel.js.map +0 -1
  106. package/lib/commonjs/LazyView.js +0 -2
  107. package/lib/commonjs/LazyView.js.map +0 -1
  108. package/lib/commonjs/ScrollViewGesture.js +0 -2
  109. package/lib/commonjs/ScrollViewGesture.js.map +0 -1
  110. package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js +0 -2
  111. package/lib/commonjs/hooks/computeNewIndexWhenDataChanges.js.map +0 -1
  112. package/lib/commonjs/hooks/index.test.js +0 -2
  113. package/lib/commonjs/hooks/index.test.js.map +0 -1
  114. package/lib/commonjs/utils/computedWithAutoFillData.js +0 -2
  115. package/lib/commonjs/utils/computedWithAutoFillData.js.map +0 -1
  116. package/lib/commonjs/utils/dealWithAnimation.js +0 -2
  117. package/lib/commonjs/utils/dealWithAnimation.js.map +0 -1
  118. package/lib/commonjs/utils/handlerOffsetDirection.js +0 -2
  119. package/lib/commonjs/utils/handlerOffsetDirection.js.map +0 -1
  120. package/lib/module/Carousel.js.map +0 -1
  121. package/lib/module/ScrollViewGesture.js.map +0 -1
  122. package/lib/module/utils/computedWithAutoFillData.js.map +0 -1
  123. package/lib/module/utils/dealWithAnimation.js.map +0 -1
  124. package/lib/module/utils/handlerOffsetDirection.js.map +0 -1
  125. /package/lib/module/{LazyView.js → components/LazyView.js} +0 -0
  126. /package/lib/module/{LazyView.js.map → components/LazyView.js.map} +0 -0
  127. /package/lib/module/{hooks → utils}/computeNewIndexWhenDataChanges.js +0 -0
  128. /package/lib/module/{hooks → utils}/computeNewIndexWhenDataChanges.js.map +0 -0
  129. /package/lib/module/{hooks → utils}/index.test.js +0 -0
  130. /package/lib/module/{hooks → utils}/index.test.js.map +0 -0
  131. /package/lib/typescript/{LazyView.d.ts → components/LazyView.d.ts} +0 -0
  132. /package/lib/typescript/{ScrollViewGesture.d.ts → components/ScrollViewGesture.d.ts} +0 -0
  133. /package/lib/typescript/{hooks → utils}/computeNewIndexWhenDataChanges.d.ts +0 -0
  134. /package/lib/typescript/utils/{computedWithAutoFillData.d.ts → computed-with-auto-fill-data.d.ts} +0 -0
  135. /package/lib/typescript/utils/{dealWithAnimation.d.ts → deal-with-animation.d.ts} +0 -0
  136. /package/lib/typescript/utils/{handlerOffsetDirection.d.ts → handleroffset-direction.d.ts} +0 -0
  137. /package/lib/typescript/{hooks → utils}/index.test.d.ts +0 -0
  138. /package/src/{LazyView.tsx → components/LazyView.tsx} +0 -0
  139. /package/src/{hooks → utils}/computeNewIndexWhenDataChanges.ts +0 -0
  140. /package/src/utils/{computedWithAutoFillData.ts → computed-with-auto-fill-data.ts} +0 -0
  141. /package/src/utils/{dealWithAnimation.ts → deal-with-animation.ts} +0 -0
  142. /package/src/utils/{handlerOffsetDirection.ts → handleroffset-direction.ts} +0 -0
  143. /package/src/{hooks → utils}/index.test.ts +0 -0
package/src/types.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { StyleProp, ViewStyle } from "react-native";
2
- import type { PanGestureHandlerProps } from "react-native-gesture-handler";
2
+ import type { PanGesture } from "react-native-gesture-handler";
3
3
  import type {
4
4
  AnimatedStyleProp,
5
5
  SharedValue,
@@ -12,36 +12,36 @@ import type { TParallaxModeProps } from "./layouts/parallax";
12
12
  import type { TStackModeProps } from "./layouts/stack";
13
13
 
14
14
  export type IComputedDirectionTypes<T, VP = {}, HP = {}> =
15
- | (T &
16
- VP & {
17
- /**
18
- * Layout items vertically instead of horizontally
19
- */
20
- vertical: true
21
- /**
22
- * Layout items vertically instead of horizontally
23
- */
24
- /**
25
- * Specified carousel container width.
26
- */
27
- width?: number
28
- height: number
29
- })
30
- | (T &
31
- HP & {
32
- /**
33
- * Layout items vertically instead of horizontally
34
- */
35
- vertical?: false
36
- /**
37
- * Layout items vertically instead of horizontally
38
- */
39
- /**
40
- * Specified carousel container width.
41
- */
42
- width: number
43
- height?: number
44
- });
15
+ | (T &
16
+ VP & {
17
+ /**
18
+ * Layout items vertically instead of horizontally
19
+ */
20
+ vertical: true
21
+ /**
22
+ * Layout items vertically instead of horizontally
23
+ */
24
+ /**
25
+ * Specified carousel container width.
26
+ */
27
+ width?: number
28
+ height: number
29
+ })
30
+ | (T &
31
+ HP & {
32
+ /**
33
+ * Layout items vertically instead of horizontally
34
+ */
35
+ vertical?: false
36
+ /**
37
+ * Layout items vertically instead of horizontally
38
+ */
39
+ /**
40
+ * Specified carousel container width.
41
+ */
42
+ width: number
43
+ height?: number
44
+ });
45
45
 
46
46
  export interface CustomConfig {
47
47
  type?: "negative" | "positive"
@@ -63,132 +63,130 @@ export type WithAnimation = WithSpringAnimation | WithTimingAnimation;
63
63
  export type TCarouselProps<T = any> = {
64
64
  ref?: React.Ref<ICarouselInstance>
65
65
  /**
66
- * The default animated value of the carousel.
67
- */
66
+ * The default animated value of the carousel.
67
+ */
68
68
  defaultScrollOffsetValue?: SharedValue<number>
69
69
  /**
70
- * Carousel loop playback.
71
- * @default true
72
- */
70
+ * Carousel loop playback.
71
+ * @default true
72
+ */
73
73
  loop?: boolean
74
74
  /**
75
- * Carousel items data set.
76
- */
75
+ * Carousel items data set.
76
+ */
77
77
  data: T[]
78
78
  /**
79
- * Auto fill data array to allow loop playback when the loop props is true.
80
- * @default true
81
- * @example
82
- * [1] => [1, 1, 1]
83
- * [1, 2] => [1, 2, 1, 2]
84
- */
79
+ * Auto fill data array to allow loop playback when the loop props is true.
80
+ * @default true
81
+ * @example
82
+ * [1] => [1, 1, 1]
83
+ * [1, 2] => [1, 2, 1, 2]
84
+ */
85
85
  autoFillData?: boolean
86
86
  /**
87
- * Default index
88
- * @default 0
89
- */
87
+ * Default index
88
+ * @default 0
89
+ */
90
90
  defaultIndex?: number
91
91
  /**
92
- * Auto play
93
- */
92
+ * Auto play
93
+ */
94
94
  autoPlay?: boolean
95
95
  /**
96
- * Auto play
97
- * @description reverse playback
98
- */
96
+ * Auto play
97
+ * @description reverse playback
98
+ */
99
99
  autoPlayReverse?: boolean
100
100
  /**
101
- * Auto play
102
- * @description playback interval
103
- */
101
+ * Auto play
102
+ * @description playback interval
103
+ */
104
104
  autoPlayInterval?: number
105
105
  /**
106
- * Time a scroll animation takes to finish
107
- * @default 500 (ms)
108
- */
106
+ * Time a scroll animation takes to finish
107
+ * @default 500 (ms)
108
+ */
109
109
  scrollAnimationDuration?: number
110
110
  /**
111
- * Carousel container style
112
- */
111
+ * Carousel container style
112
+ */
113
113
  style?: StyleProp<ViewStyle>
114
114
  /**
115
- * PanGestureHandler props
116
- */
117
- panGestureHandlerProps?: Partial<
118
- Omit<PanGestureHandlerProps, "onHandlerStateChange" | "enabled">
119
- >
120
- /**
121
- * Determines the maximum number of items will respond to pan gesture events,
122
- * windowSize={11} will active visible item plus up to 5 items above and 5 below the viewpor,
123
- * Reducing this number will reduce the calculation of the animation value and may improve performance.
124
- * @default 0 all items will respond to pan gesture events.
125
- */
115
+ * PanGesture config
116
+ */
117
+ onConfigurePanGesture?: (panGesture: PanGesture) => void
118
+ /**
119
+ * Determines the maximum number of items will respond to pan gesture events,
120
+ * windowSize={11} will active visible item plus up to 5 items above and 5 below the viewpor,
121
+ * Reducing this number will reduce the calculation of the animation value and may improve performance.
122
+ * @default 0 all items will respond to pan gesture events.
123
+ */
126
124
  windowSize?: number
127
125
  /**
128
- * When true, the scroll view stops on multiples of the scroll view's size when scrolling.
129
- * @default true
130
- */
126
+ * When true, the scroll view stops on multiples of the scroll view's size when scrolling.
127
+ * @default true
128
+ */
131
129
  pagingEnabled?: boolean
132
130
  /**
133
- * If enabled, releasing the touch will scroll to the nearest item.
134
- * valid when pagingEnabled=false
135
- * @default true
136
- */
131
+ * If enabled, releasing the touch will scroll to the nearest item.
132
+ * valid when pagingEnabled=false
133
+ * @default true
134
+ */
137
135
  snapEnabled?: boolean
138
136
  /**
139
- * If enabled, items will scroll to the first placement when scrolling past the edge rather than closing to the last. (previous conditions: loop=false)
140
- * @default true
141
- */
137
+ * If enabled, items will scroll to the first placement when scrolling past the edge rather than closing to the last. (previous conditions: loop=false)
138
+ * @default true
139
+ */
142
140
  overscrollEnabled?: boolean
143
141
  /**
144
- * If false, Carousel will not respond to any gestures.
145
- * @default true
146
- */
142
+ * If false, Carousel will not respond to any gestures.
143
+ * @default true
144
+ */
147
145
  enabled?: boolean
148
146
  /**
149
- * Specifies the scrolling animation effect.
150
- */
147
+ * Specifies the scrolling animation effect.
148
+ */
151
149
  withAnimation?: WithAnimation
152
150
  /**
153
- * Used to locate this view in end-to-end tests.
154
- */
151
+ * Used to locate this view in end-to-end tests.
152
+ */
155
153
  testID?: string
156
154
  /**
157
- * Maximum offset value for once scroll.
158
- * props.vertical = true => maxScrollDistancePerSwipeY
159
- * props.vertical = false => maxScrollDistancePerSwipeX
160
- * */
155
+ * Maximum offset value for once scroll.
156
+ * props.vertical = true => maxScrollDistancePerSwipeY
157
+ * props.vertical = false => maxScrollDistancePerSwipeX
158
+ * */
161
159
  maxScrollDistancePerSwipe?: number
162
160
  /**
163
- * Custom carousel config.
164
- */
161
+ * Custom carousel config.
162
+ */
165
163
  customConfig?: () => CustomConfig
166
164
  /**
167
- * Custom animations.
168
- * Must use `worklet`, Details: https://docs.swmansion.com/react-native-reanimated/docs/2.2.0/worklets/
169
- */
165
+ * Custom animations.
166
+ * Must use `worklet`, Details: https://docs.swmansion.com/react-native-reanimated/docs/2.2.0/worklets/
167
+ */
170
168
  customAnimation?: (value: number) => AnimatedStyleProp<ViewStyle>
171
169
  /**
172
- * Render carousel item.
173
- */
170
+ * Render carousel item.
171
+ */
174
172
  renderItem: CarouselRenderItem<T>
175
173
  /**
176
- * Callback fired when navigating to an item.
177
- */
174
+ * Callback fired when navigating to an item.
175
+ */
178
176
  onSnapToItem?: (index: number) => void
179
177
  /**
180
- * On scroll begin
181
- */
178
+ * On scroll begin
179
+ */
182
180
  onScrollBegin?: () => void
183
181
  /**
184
- * On scroll end
185
- */
182
+ * On scroll end
183
+ */
186
184
  onScrollEnd?: (index: number) => void
187
185
  /**
188
- * On progress change
189
- * @param offsetProgress Total of offset distance (0 390 780 ...)
190
- * @param absoluteProgress Convert to index (0 1 2 ...)
191
- */
186
+ * On progress change
187
+ * @param offsetProgress Total of offset distance (0 390 780 ...)
188
+ * @param absoluteProgress Convert to index (0 1 2 ...)
189
+ */
192
190
  onProgressChange?: (
193
191
  offsetProgress: number,
194
192
  absoluteProgress: number
@@ -196,32 +194,32 @@ export type TCarouselProps<T = any> = {
196
194
 
197
195
  // ============================== deprecated props ==============================
198
196
  /**
199
- * If enabled, releasing the touch will scroll to the nearest item.
200
- * valid when pagingEnabled=false
201
- * @deprecated please use snapEnabled instead
202
- */
197
+ * If enabled, releasing the touch will scroll to the nearest item.
198
+ * valid when pagingEnabled=false
199
+ * @deprecated please use snapEnabled instead
200
+ */
203
201
  enableSnap?: boolean
204
202
  } & (TParallaxModeProps | TStackModeProps);
205
203
 
206
204
  export interface ICarouselInstance {
207
205
  /**
208
- * Scroll to previous item, it takes one optional argument (count),
209
- * which allows you to specify how many items to cross
210
- */
206
+ * Scroll to previous item, it takes one optional argument (count),
207
+ * which allows you to specify how many items to cross
208
+ */
211
209
  prev: (opts?: Omit<TCarouselActionOptions, "index">) => void
212
210
  /**
213
- * Scroll to next item, it takes one optional argument (count),
214
- * which allows you to specify how many items to cross
215
- */
211
+ * Scroll to next item, it takes one optional argument (count),
212
+ * which allows you to specify how many items to cross
213
+ */
216
214
  next: (opts?: Omit<TCarouselActionOptions, "index">) => void
217
215
  /**
218
- * Get current item index
219
- */
216
+ * Get current item index
217
+ */
220
218
  getCurrentIndex: () => number
221
219
  /**
222
- * Use value to scroll to a position where relative to the current position,
223
- * scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
224
- */
220
+ * Use value to scroll to a position where relative to the current position,
221
+ * scrollTo(-2) is equivalent to prev(2), scrollTo(2) is equivalent to next(2)
222
+ */
225
223
  scrollTo: (opts?: TCarouselActionOptions) => void
226
224
  }
227
225
 
package/README.zh-CN.md DELETED
@@ -1,202 +0,0 @@
1
- [English](./README.md) | 简体中文
2
-
3
- # react-native-reanimated-carousel
4
-
5
- <img src="assets/home-banner-zh.png" width="100%"/>
6
-
7
- ![Hacktober Badge](https://img.shields.io/badge/hacktoberfest-2022-blueviolet)
8
- ![platforms](https://img.shields.io/badge/platforms-Android%20%7C%20iOS%20%7C%20Web-brightgreen.svg?style=flat-square&colorB=191A17)
9
- [![npm](https://img.shields.io/npm/v/react-native-reanimated-carousel.svg?style=flat-square)](https://www.npmjs.com/package/react-native-reanimated-carousel)
10
- [![npm](https://img.shields.io/npm/dm/react-native-reanimated-carousel.svg?style=flat-square&colorB=007ec6)](https://www.npmjs.com/package/react-native-reanimated-carousel)
11
- [![npm](https://img.shields.io/npm/dw/react-native-reanimated-carousel.svg?style=flat-square&colorB=007ec6)](https://www.npmjs.com/package/react-native-reanimated-carousel)
12
- [![github issues](https://img.shields.io/github/issues/dohooo/react-native-reanimated-carousel.svg?style=flat-square)](https://github.com/dohooo/react-native-reanimated-carousel/issues)
13
- [![github closed issues](https://img.shields.io/github/issues-closed/dohooo/react-native-reanimated-carousel.svg?style=flat-square&colorB=44cc11)](https://github.com/dohooo/react-native-reanimated-carousel/issues?q=is%3Aissue+is%3Aclosed)
14
- [![discord chat](https://img.shields.io/badge/chat-discord-blue?style=flat&logo=discord)](https://discord.gg/KsXRuDs43y)
15
-
16
- ## ReactNative 社区最好用的轮播图组件! 🎉🎉🎉
17
-
18
- - **完全解决了`react-native-snap-carousel`的** [[问题]](https://github.com/meliorence/react-native-snap-carousel/issues/632)
19
- - **易用**、**无限滚动**、**完全使用 Reanimated2 实现**
20
-
21
- > v2 已经发布,希望大家喜欢!~ [[v1 文档]](https://github.com/dohooo/react-native-reanimated-carousel/tree/v1.x.x)
22
-
23
- > 支持 Web 端 [[示例]](https://dohooo.github.io/react-native-reanimated-carousel/)
24
-
25
- > 点击图片,查看代码 [[试一下]](https://snack.expo.dev/@zhaodonghao586/simple-carousel) 🍺
26
-
27
- | <img src="assets/normal-horizontal.gif"/> | <img src="assets/normal-vertical.gif"/> | <img src="assets/parallax-horizontal.gif"/> |
28
- | :------------------------------------------------------------------: | :-------------------------------------------------------------------: | :--------------------------------------------------------------------: |
29
- | <a href="./exampleExpo/src/pages/normal/index.tsx">normal-horizontal</a> | <a href="./exampleExpo/src/pages/normal/index.tsx">normal-vertical</a> | <a href="./exampleExpo/src/pages/parallax/index.tsx">parallax-horizontal</a> |
30
- | <img src="assets/parallax-vertical.gif"/> | <img src="assets/stack-horizontal-left.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
31
- | <a href="./exampleExpo/src/pages/parallax/index.tsx">parallax-vertical</a> | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-horizontal-left</a> | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-horizontal-right</a> |
32
- | <img src="assets/stack-vertical-left.gif"/> | <img src="assets/stack-vertical-right.gif"/> | <img src="assets/stack-horizontal-right.gif"/> |
33
- | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-vertical-left</a> | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-vertical-right</a> | <a href="./exampleExpo/src/pages/stack/index.tsx">stack-horizontal-right</a> |
34
- | <img src="assets/left-align.gif"/> |
35
- | <a href="./exampleExpo/src/pages/left-align/index.tsx">left-align</a> |
36
-
37
- > 现在你可以和我们一起来制作酷炫的动画了! 非常简单! [[详情]](./docs/custom-animation.zh-CN.md)
38
-
39
- | <img src="assets/advanced-parallax.gif"/> | <img src="assets/pause-advanced-parallax.gif"/> | <img src="assets/scale-fade-in-out.gif"/> |
40
- | :-----------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------------------: | :---------------------------------------------------------------------------: |
41
- | <a href="./exampleExpo/src/pages/advanced-parallax/index.tsx">advanced-parallax</a> | <a href="./exampleExpo/src/pause-advanced-parallax/index.tsx">pause-advanced-parallax</a> | <a href="./exampleExpo/src/pages/scale-fade-in-out/index.tsx">scale-fade-in-out</a> |
42
- | <img src="assets/rotate-scale-fade-in-out.gif"/> | <img src="assets/rotate-in-out.gif"/> | <img src="assets/anim-tab-bar.gif"/> |
43
- | <a href="./exampleExpo/src/pages/rotate-scale-fade-in-out/index.tsx">rotate-scale-fade-in-out</a> | <a href="./exampleExpo/src/pages/rotate-in-out/index.tsx">rotate-in-out</a> | <a href="./exampleExpo/src/pages/anim-tab-bar/index.tsx">anim-tab-bar</a> |
44
- | <img src="assets/marquee.gif"/> | <img src="assets/multiple.gif"/> | <img src="assets/circular.gif"/> |
45
- | <a href="./exampleExpo/src/pages/marquee/index.tsx">marquee</a> | <a href="./exampleExpo/src/pages/multiple/index.tsx">multiple</a> | <a href="./exampleExpo/src/pages/circular/index.tsx">circular</a> |
46
- | <img src="assets/fold.gif"/> | <img src="assets/tear.gif"/> | <img src="assets/press-swipe.gif"/> |
47
- | <a href="./exampleExpo/src/pages/fold/index.tsx">fold</a> | <a href="./exampleExpo/src/tear/index.tsx">tear</a> | <a href="./exampleExpo/src/pages/press-swipe/index.tsx">press-swipe</a> |
48
- | <img src="assets/cube-3d.gif"/> | <img src="assets/blur-parallax.gif"/> | <img src="assets/curve.gif"/> |
49
- | <a href="./exampleExpo/src/pages/cube-3d/index.tsx">cube-3d</a> | <a href="./exampleExpo/src/pages/blur-parallax/index.tsx">blur-parallax</a> | <a href="./exampleExpo/src/pages/curve/index.tsx">curve</a> |
50
- | <img src="assets/parallax-layers.gif"/> | <img src="assets/stack-cards.gif"/> | <img src="assets/flow.gif"/> |
51
- | <a href="./exampleExpo/src/pages/parallax-layers/index.tsx">parallax-layers</a> | <a href="./exampleExpo/src/pages/stack-cards/index.tsx">stack-cards</a> | <a href="./exampleExpo/src/pages/flow/index.tsx">flow</a> |
52
- | <img src="assets/blur-rotate.gif"/> | | |
53
- | <a href="./exampleExpo/src/pages/blur-rotate/index.tsx">blur-rotate</a> | | |
54
-
55
- ## 目录
56
-
57
- 1. [安装](#安装)
58
- 1. [使用](#使用)
59
- 1. [Props](./docs/props.zh-CN.md)
60
- 1. [提示](#提示)
61
- 1. [原因](#原因)
62
- 1. [示例](#示例)
63
-
64
- ---
65
-
66
- ## 安装
67
-
68
- 在项目根目录打开终端并且执行:
69
-
70
- ```sh
71
- yarn add react-native-reanimated-carousel
72
- ```
73
-
74
- 如果你使用 npm:
75
-
76
- ```sh
77
- npm install react-native-reanimated-carousel
78
- ```
79
-
80
- 并且我们需要安装 [`react-native-gesture-handler`](https://github.com/kmagiera/react-native-gesture-handler) 、[`react-native-reanimated`](https://github.com/kmagiera/react-native-reanimated),安装步骤可参考各自文档。
81
- | | react-native-reanimated | react-native-gesture-handler |
82
- | -------------------------------------- | ----------------------- | ---------------------------- |
83
- | react-native-reanimated-carousel v1、v2 | >=2.0 & <2.7.0 | <2.9.0 |
84
- | react-native-reanimated-carousel v3 | >=2.7.0 & < 3.x | <2.9.0 |
85
- | react-native-reanimated-carousel v4 | >=3.x | >=2.9.0 |
86
-
87
-
88
- ## 使用
89
-
90
- ```tsx
91
- import * as React from "react";
92
- import { Dimensions, Text, View } from "react-native";
93
- import Carousel from "react-native-reanimated-carousel";
94
-
95
- function Index() {
96
- const width = Dimensions.get("window").width;
97
- return (
98
- <View style={{ flex: 1 }}>
99
- <Carousel
100
- loop
101
- width={width}
102
- height={width / 2}
103
- autoPlay={true}
104
- data={[...new Array(6).keys()]}
105
- scrollAnimationDuration={1000}
106
- onSnapToItem={index => console.log("current index:", index)}
107
- renderItem={({ index }) => (
108
- <View
109
- style={{
110
- flex: 1,
111
- borderWidth: 1,
112
- justifyContent: "center",
113
- }}
114
- >
115
- <Text style={{ textAlign: "center", fontSize: 30 }}>
116
- {index}
117
- </Text>
118
- </View>
119
- )}
120
- />
121
- </View>
122
- );
123
- }
124
-
125
- export default Index;
126
- ```
127
-
128
- ## 提示
129
-
130
- - 优化
131
- - 当渲染大量元素时,可使用`windowSize`属性,来控制当前元素的两侧渲染数量,默认为全量渲染。经测试不加此属性,渲染 200 个空 view 时会出现掉帧情况,设置此属性后渲染 1000 个空 view 依旧流畅。(具体数量与测试的手机型号相关)
132
- - 在`ScrollView/FlatList`中使用
133
-
134
- - **[#143](https://github.com/dohooo/react-native-reanimated-carousel/issues/143) - Carousel suppresses ScrollView/FlatList scroll gesture handler:** 当轮播图被放置在 ScrollView/FlatList 中时,轮播图的部分将无法控制列表滚动,解决办法是我们只允许手势系统识别某一方向,而不是所有方向,在下方例子中我们为了让列表可以向下滑动,所以我们使用[activeOffsetX](https://docs.swmansion.com/react-native-gesture-handler/docs/1.10.3/api/gesture-handlers/pan-gh/#activeoffsetx)属性来控制轮播图只识别横向手势:
135
-
136
- ```tsx
137
- <Carousel
138
- {...}
139
- panGestureHandlerProps={{
140
- activeOffsetX: [-10, 10],
141
- }}
142
- />
143
- ```
144
-
145
- - RTL
146
- - 所有 layout 均完美支持 RTL 模式,并且无需再做任何配置。但在 RTL 模式下使用自动播放时,默认不会自动转换方向,需要结合 autoPlayReverse 来手动控制方向。
147
- - EXPO
148
- - 如果你使用 EXPO 托管工作流,请确定你的 EXPO SDK 版本大于 41,因为旧的版本并不支持`Reanimated(v2)`。
149
- - 工作原理
150
- - [关于RNRC](./docs/about.zh-CN.md)
151
- - 如何运行`exampleExpo`的测试
152
- ```shell
153
- $ yarn prepare
154
- $ yarn link --global
155
- $ cd ./exampleExpo
156
- $ yarn link react-native-reanimated-carousel --global
157
- $ yarn test
158
- ```
159
-
160
- ## 原因
161
-
162
- <details>
163
- <summary>常见的无限滚动轮播图,在快速滑动时会出现卡住的情况,这是因为实现方式而导致的问题。所以这个组件用了完全不同的方式来实现,并获得了最佳的性能也解决了这个问题,这就是创建这个库的原因。</summary>
164
- <p align="center">
165
- 使用react-native-snap-carousel快速滑动,当到连接处时可以看清楚的看到卡顿。(gif 4.6mb)
166
- </p>
167
- <p align="center">
168
- <img src="assets/react-native-snap-carousel.gif" width="50%"/>
169
- </p>
170
-
171
- <p align="center">
172
- 使用react-native-reanimated-carousel对比,每秒滚动十张依然顺畅链接,无限滚动。这里使用了gif无法很清晰的看出。
173
- </p>
174
- <p align="center">
175
- <img src="assets/normal-fast.gif" width="50%"/>
176
- </p>
177
- </details>
178
-
179
- ## 示例
180
-
181
- > `:pretty` 使用更好看的图片
182
-
183
- ```shell
184
- yarn ios
185
- yarn ios:pretty
186
-
187
- yarn android
188
- yarn android:pretty
189
-
190
- yarn web
191
- yarn web:pretty
192
- ```
193
-
194
- ## 赞助商
195
-
196
- <p align="center">
197
- <img src='https://github.com/dohooo/sponsors/blob/master/sponsors.png?raw=true'/>
198
- </p>
199
-
200
- ## 许可
201
-
202
- MIT
@@ -1,2 +0,0 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.default=void 0;var _react=_interopRequireDefault(require("react"));var _reactNative=require("react-native");var _reactNativeGestureHandler=require("react-native-gesture-handler");var _reactNativeReanimated=require("react-native-reanimated");var _useAutoPlay2=require("./hooks/useAutoPlay");var _useCarouselController=require("./hooks/useCarouselController");var _useCommonVariables=require("./hooks/useCommonVariables");var _useInitProps=require("./hooks/useInitProps");var _useLayoutConfig=require("./hooks/useLayoutConfig");var _useOnProgressChange=require("./hooks/useOnProgressChange");var _usePropsErrorBoundary=require("./hooks/usePropsErrorBoundary");var _useVisibleRanges=require("./hooks/useVisibleRanges");var _BaseLayout=require("./layouts/BaseLayout");var _ScrollViewGesture=require("./ScrollViewGesture");var _store=require("./store");var _computedWithAutoFillData=require("./utils/computedWithAutoFillData");var _jsxRuntime=require("react/jsx-runtime");var _this=this,_jsxFileName="/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/Carousel.tsx";var _worklet_10125235996566_init_data={code:"function anonymous() {\n const {\n size,\n dataLength,\n handlerOffset,\n loop\n } = this._closure;\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n if (!loop) return handlerOffset.value;\n return isNaN(x) ? 0 : x;\n}",location:"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/Carousel.tsx",sourceMap:"{\"version\":3,\"names\":[\"anonymous\",\"size\",\"dataLength\",\"handlerOffset\",\"loop\",\"_closure\",\"totalSize\",\"x\",\"value\",\"isNaN\"],\"sources\":[\"/home/runner/work/react-native-reanimated-carousel/react-native-reanimated-carousel/src/Carousel.tsx\"],\"mappings\":\"AA2DoC,SAAAA,SAAMA,CAAA;EAAA;IAAAC,IAAA;IAAAC,UAAA;IAAAC,aAAA;IAAAC;EAAA,SAAAC,QAAA;EACpC,MAAMC,SAAS,GAAGL,IAAI,GAAGC,UAAU;EACnC,MAAMK,CAAC,GAAGJ,aAAa,CAACK,KAAK,GAAGF,SAAS;EAEzC,IAAI,CAACF,IAAI,EACP,OAAOD,aAAa,CAACK,KAAK;EAE5B,OAAOC,KAAK,CAACF,CAAC,CAAC,GAAG,CAAC,GAAGA,CAAC;AACzB\"}"};var Carousel=_react.default.forwardRef(function(_props,ref){var props=(0,_useInitProps.useInitProps)(_props);var testID=props.testID,loop=props.loop,autoFillData=props.autoFillData,data=props.data,dataLength=props.dataLength,rawData=props.rawData,rawDataLength=props.rawDataLength,mode=props.mode,style=props.style,width=props.width,height=props.height,vertical=props.vertical,autoPlay=props.autoPlay,windowSize=props.windowSize,autoPlayReverse=props.autoPlayReverse,autoPlayInterval=props.autoPlayInterval,scrollAnimationDuration=props.scrollAnimationDuration,withAnimation=props.withAnimation,renderItem=props.renderItem,onScrollEnd=props.onScrollEnd,onSnapToItem=props.onSnapToItem,_onScrollBegin=props.onScrollBegin,onProgressChange=props.onProgressChange,customAnimation=props.customAnimation,defaultIndex=props.defaultIndex;var commonVariables=(0,_useCommonVariables.useCommonVariables)(props);var size=commonVariables.size,handlerOffset=commonVariables.handlerOffset;var offsetX=(0,_reactNativeReanimated.useDerivedValue)(function(){var _e=[new global.Error(),-5,-27];var _f=function _f(){var totalSize=size*dataLength;var x=handlerOffset.value%totalSize;if(!loop)return handlerOffset.value;return isNaN(x)?0:x;};_f._closure={size:size,dataLength:dataLength,handlerOffset:handlerOffset,loop:loop};_f.__initData=_worklet_10125235996566_init_data;_f.__workletHash=10125235996566;_f.__stackDetails=_e;_f.__version="3.3.0";return _f;}(),[loop,size,dataLength]);(0,_usePropsErrorBoundary.usePropsErrorBoundary)(Object.assign({},props,{dataLength:dataLength}));(0,_useOnProgressChange.useOnProgressChange)({autoFillData:autoFillData,loop:loop,size:size,offsetX:offsetX,rawDataLength:rawDataLength,onProgressChange:onProgressChange});var carouselController=(0,_useCarouselController.useCarouselController)({loop:loop,size:size,dataLength:dataLength,autoFillData:autoFillData,handlerOffset:handlerOffset,withAnimation:withAnimation,defaultIndex:defaultIndex,onScrollEnd:function onScrollEnd(){return(0,_reactNativeReanimated.runOnJS)(_onScrollEnd)();},onScrollBegin:function onScrollBegin(){return!!_onScrollBegin&&(0,_reactNativeReanimated.runOnJS)(_onScrollBegin)();},duration:scrollAnimationDuration});var next=carouselController.next,prev=carouselController.prev,scrollTo=carouselController.scrollTo,getSharedIndex=carouselController.getSharedIndex,getCurrentIndex=carouselController.getCurrentIndex;var _useAutoPlay=(0,_useAutoPlay2.useAutoPlay)({autoPlay:autoPlay,autoPlayInterval:autoPlayInterval,autoPlayReverse:autoPlayReverse,carouselController:carouselController}),startAutoPlay=_useAutoPlay.start,pauseAutoPlay=_useAutoPlay.pause;var _onScrollEnd=_react.default.useCallback(function(){var _sharedIndex=Math.round(getSharedIndex());var realIndex=(0,_computedWithAutoFillData.computedRealIndexWithAutoFillData)({index:_sharedIndex,dataLength:rawDataLength,loop:loop,autoFillData:autoFillData});if(onSnapToItem)onSnapToItem(realIndex);if(onScrollEnd)onScrollEnd(realIndex);},[loop,autoFillData,rawDataLength,getSharedIndex,onSnapToItem,onScrollEnd]);var scrollViewGestureOnScrollBegin=_react.default.useCallback(function(){pauseAutoPlay();_onScrollBegin==null?void 0:_onScrollBegin();},[_onScrollBegin,pauseAutoPlay]);var scrollViewGestureOnScrollEnd=_react.default.useCallback(function(){startAutoPlay();_onScrollEnd();},[_onScrollEnd,startAutoPlay]);var scrollViewGestureOnTouchBegin=_react.default.useCallback(pauseAutoPlay,[pauseAutoPlay]);var scrollViewGestureOnTouchEnd=_react.default.useCallback(startAutoPlay,[startAutoPlay]);_react.default.useImperativeHandle(ref,function(){return{next:next,prev:prev,getCurrentIndex:getCurrentIndex,scrollTo:scrollTo};},[getCurrentIndex,next,prev,scrollTo]);var visibleRanges=(0,_useVisibleRanges.useVisibleRanges)({total:dataLength,viewSize:size,translation:handlerOffset,windowSize:windowSize});var layoutConfig=(0,_useLayoutConfig.useLayoutConfig)(Object.assign({},props,{size:size}));var renderLayout=_react.default.useCallback(function(item,i){var realIndex=(0,_computedWithAutoFillData.computedRealIndexWithAutoFillData)({index:i,dataLength:rawDataLength,loop:loop,autoFillData:autoFillData});return(0,_jsxRuntime.jsx)(_BaseLayout.BaseLayout,{index:i,handlerOffset:offsetX,visibleRanges:visibleRanges,animationStyle:customAnimation||layoutConfig,children:function children(_ref){var animationValue=_ref.animationValue;return renderItem({item:item,index:realIndex,animationValue:animationValue});}},i);},[loop,rawData,offsetX,visibleRanges,autoFillData,renderItem,layoutConfig,customAnimation]);return(0,_jsxRuntime.jsx)(_reactNativeGestureHandler.GestureHandlerRootView,{children:(0,_jsxRuntime.jsx)(_store.CTX.Provider,{value:{props:props,common:commonVariables},children:(0,_jsxRuntime.jsx)(_ScrollViewGesture.ScrollViewGesture,{size:size,translation:handlerOffset,style:[styles.container,{width:width||"100%",height:height||"100%"},style,vertical?styles.itemsVertical:styles.itemsHorizontal],testID:testID,onScrollBegin:scrollViewGestureOnScrollBegin,onScrollEnd:scrollViewGestureOnScrollEnd,onTouchBegin:scrollViewGestureOnTouchBegin,onTouchEnd:scrollViewGestureOnTouchEnd,children:data.map(renderLayout)},mode)})});});var _default=Carousel;exports.default=_default;var styles=_reactNative.StyleSheet.create({container:{overflow:"hidden"},itemsHorizontal:{flexDirection:"row"},itemsVertical:{flexDirection:"column"}});
2
- //# sourceMappingURL=Carousel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["Carousel.tsx"],"names":["Carousel","React","forwardRef","_props","ref","props","testID","loop","autoFillData","data","dataLength","rawData","rawDataLength","mode","style","width","height","vertical","autoPlay","windowSize","autoPlayReverse","autoPlayInterval","scrollAnimationDuration","withAnimation","renderItem","onScrollEnd","onSnapToItem","onScrollBegin","onProgressChange","customAnimation","defaultIndex","commonVariables","size","handlerOffset","offsetX","totalSize","x","value","isNaN","carouselController","_onScrollEnd","duration","next","prev","scrollTo","getSharedIndex","getCurrentIndex","startAutoPlay","start","pauseAutoPlay","pause","useCallback","_sharedIndex","Math","round","realIndex","index","scrollViewGestureOnScrollBegin","scrollViewGestureOnScrollEnd","scrollViewGestureOnTouchBegin","scrollViewGestureOnTouchEnd","useImperativeHandle","visibleRanges","total","viewSize","translation","layoutConfig","renderLayout","item","i","animationValue","common","styles","container","itemsVertical","itemsHorizontal","map","StyleSheet","create","overflow","flexDirection"],"mappings":"mKACA,oDACA,yCACA,uEACA,8DAEA,iDACA,oEACA,8DACA,kDACA,wDACA,gEACA,oEACA,0DACA,gDACA,sDACA,8BAEA,0E,gqCAEA,GAAMA,CAAAA,QAAQ,CAAGC,eAAMC,UAAN,CACf,SAACC,MAAD,CAASC,GAAT,CAAiB,CACf,GAAMC,CAAAA,KAAK,CAAG,+BAAaF,MAAb,CAAd,CAEA,GACEG,CAAAA,MADF,CA8BID,KA9BJ,CACEC,MADF,CAEEC,IAFF,CA8BIF,KA9BJ,CAEEE,IAFF,CAGEC,YAHF,CA8BIH,KA9BJ,CAGEG,YAHF,CAKEC,IALF,CA8BIJ,KA9BJ,CAKEI,IALF,CAOEC,UAPF,CA8BIL,KA9BJ,CAOEK,UAPF,CASEC,OATF,CA8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,CA3BmB,CAArB,CAuCA,MACE,oBAAC,iDAAD,WACE,oBAAC,UAAD,CAAK,QAAL,EAAc,KAAK,CAAE,CAAExB,KAAK,CAALA,KAAF,CAASkE,MAAM,CAAExC,eAAjB,CAArB,UACE,oBAAC,oCAAD,EAEE,IAAI,CAAEC,IAFR,CAGE,WAAW,CAAEC,aAHf,CAIE,KAAK,CAAE,CACLuC,MAAM,CAACC,SADF,CAEL,CACE1D,KAAK,CAAEA,KAAK,EAAI,MADlB,CAEEC,MAAM,CAAEA,MAAM,EAAI,MAFpB,CAFK,CAMLF,KANK,CAOLG,QAAQ,CACJuD,MAAM,CAACE,aADH,CAEJF,MAAM,CAACG,eATN,CAJT,CAeE,MAAM,CAAErE,MAfV,CAgBE,aAAa,CAAEmD,8BAhBjB,CAiBE,WAAW,CAAEC,4BAjBf,CAkBE,YAAY,CAAEC,6BAlBhB,CAmBE,UAAU,CAAEC,2BAnBd,UAqBGnD,IAAI,CAACmE,GAAL,CAAST,YAAT,CArBH,EACOtD,IADP,CADF,EADF,EADF,CA6BD,CApNc,CAAjB,C,aAuNeb,Q,0BAIf,GAAMwE,CAAAA,MAAM,CAAGK,wBAAWC,MAAX,CAAkB,CAC/BL,SAAS,CAAE,CACTM,QAAQ,CAAE,QADD,CADoB,CAI/BJ,eAAe,CAAE,CACfK,aAAa,CAAE,KADA,CAJc,CAO/BN,aAAa,CAAE,CACbM,aAAa,CAAE,QADF,CAPgB,CAAlB,CAAf","sourcesContent":["/* eslint-disable @typescript-eslint/no-use-before-define */\nimport React from \"react\";\nimport { StyleSheet } from \"react-native\";\nimport { GestureHandlerRootView } from \"react-native-gesture-handler\";\nimport { runOnJS, useDerivedValue } from \"react-native-reanimated\";\n\nimport { useAutoPlay } from \"./hooks/useAutoPlay\";\nimport { useCarouselController } from \"./hooks/useCarouselController\";\nimport { useCommonVariables } from \"./hooks/useCommonVariables\";\nimport { useInitProps } from \"./hooks/useInitProps\";\nimport { useLayoutConfig } from \"./hooks/useLayoutConfig\";\nimport { useOnProgressChange } from \"./hooks/useOnProgressChange\";\nimport { usePropsErrorBoundary } from \"./hooks/usePropsErrorBoundary\";\nimport { useVisibleRanges } from \"./hooks/useVisibleRanges\";\nimport { BaseLayout } from \"./layouts/BaseLayout\";\nimport { ScrollViewGesture } from \"./ScrollViewGesture\";\nimport { CTX } from \"./store\";\nimport type { ICarouselInstance, TCarouselProps } from \"./types\";\nimport { computedRealIndexWithAutoFillData } from \"./utils/computedWithAutoFillData\";\n\nconst Carousel = React.forwardRef<ICarouselInstance, TCarouselProps<any>>(\n (_props, ref) => {\n const props = useInitProps(_props);\n\n const {\n testID,\n loop,\n autoFillData,\n // Fill data with autoFillData\n data,\n // Length of fill data\n dataLength,\n // Raw data that has not been processed\n rawData,\n // Length of raw data\n rawDataLength,\n mode,\n style,\n width,\n height,\n vertical,\n autoPlay,\n windowSize,\n autoPlayReverse,\n autoPlayInterval,\n scrollAnimationDuration,\n withAnimation,\n renderItem,\n onScrollEnd,\n onSnapToItem,\n onScrollBegin,\n onProgressChange,\n customAnimation,\n defaultIndex,\n } = props;\n\n const commonVariables = useCommonVariables(props);\n const { size, handlerOffset } = commonVariables;\n\n const offsetX = useDerivedValue(() => {\n const totalSize = size * dataLength;\n const x = handlerOffset.value % totalSize;\n\n if (!loop)\n return handlerOffset.value;\n\n return isNaN(x) ? 0 : x;\n }, [loop, size, dataLength]);\n\n usePropsErrorBoundary({ ...props, dataLength });\n useOnProgressChange({\n autoFillData,\n loop,\n size,\n offsetX,\n rawDataLength,\n onProgressChange,\n });\n\n const carouselController = useCarouselController({\n loop,\n size,\n dataLength,\n autoFillData,\n handlerOffset,\n withAnimation,\n defaultIndex,\n onScrollEnd: () => runOnJS(_onScrollEnd)(),\n onScrollBegin: () => !!onScrollBegin && runOnJS(onScrollBegin)(),\n duration: scrollAnimationDuration,\n });\n\n const { next, prev, scrollTo, getSharedIndex, getCurrentIndex }\n = carouselController;\n\n const { start: startAutoPlay, pause: pauseAutoPlay } = useAutoPlay({\n autoPlay,\n autoPlayInterval,\n autoPlayReverse,\n carouselController,\n });\n\n const _onScrollEnd = React.useCallback(() => {\n const _sharedIndex = Math.round(getSharedIndex());\n\n const realIndex = computedRealIndexWithAutoFillData({\n index: _sharedIndex,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n if (onSnapToItem)\n onSnapToItem(realIndex);\n\n if (onScrollEnd)\n onScrollEnd(realIndex);\n }, [\n loop,\n autoFillData,\n rawDataLength,\n getSharedIndex,\n onSnapToItem,\n onScrollEnd,\n ]);\n\n const scrollViewGestureOnScrollBegin = React.useCallback(() => {\n pauseAutoPlay();\n onScrollBegin?.();\n }, [onScrollBegin, pauseAutoPlay]);\n\n const scrollViewGestureOnScrollEnd = React.useCallback(() => {\n startAutoPlay();\n _onScrollEnd();\n }, [_onScrollEnd, startAutoPlay]);\n\n const scrollViewGestureOnTouchBegin = React.useCallback(pauseAutoPlay, [\n pauseAutoPlay,\n ]);\n\n const scrollViewGestureOnTouchEnd = React.useCallback(startAutoPlay, [\n startAutoPlay,\n ]);\n\n React.useImperativeHandle(\n ref,\n () => ({\n next,\n prev,\n getCurrentIndex,\n scrollTo,\n }),\n [getCurrentIndex, next, prev, scrollTo],\n );\n\n const visibleRanges = useVisibleRanges({\n total: dataLength,\n viewSize: size,\n translation: handlerOffset,\n windowSize,\n });\n\n const layoutConfig = useLayoutConfig({ ...props, size });\n\n const renderLayout = React.useCallback(\n (item: any, i: number) => {\n const realIndex = computedRealIndexWithAutoFillData({\n index: i,\n dataLength: rawDataLength,\n loop,\n autoFillData,\n });\n\n return (\n <BaseLayout\n key={i}\n index={i}\n handlerOffset={offsetX}\n visibleRanges={visibleRanges}\n animationStyle={customAnimation || layoutConfig}\n >\n {({ animationValue }) =>\n renderItem({\n item,\n index: realIndex,\n animationValue,\n })\n }\n </BaseLayout>\n );\n },\n [\n loop,\n rawData,\n offsetX,\n visibleRanges,\n autoFillData,\n renderItem,\n layoutConfig,\n customAnimation,\n ],\n );\n\n return (\n <GestureHandlerRootView>\n <CTX.Provider value={{ props, common: commonVariables }}>\n <ScrollViewGesture\n key={mode}\n size={size}\n translation={handlerOffset}\n style={[\n styles.container,\n {\n width: width || \"100%\",\n height: height || \"100%\",\n },\n style,\n vertical\n ? styles.itemsVertical\n : styles.itemsHorizontal,\n ]}\n testID={testID}\n onScrollBegin={scrollViewGestureOnScrollBegin}\n onScrollEnd={scrollViewGestureOnScrollEnd}\n onTouchBegin={scrollViewGestureOnTouchBegin}\n onTouchEnd={scrollViewGestureOnTouchEnd}\n >\n {data.map(renderLayout)}\n </ScrollViewGesture>\n </CTX.Provider>\n </GestureHandlerRootView>\n );\n },\n);\n\nexport default Carousel as <T extends any>(\n props: React.PropsWithChildren<TCarouselProps<T>>\n) => React.ReactElement;\n\nconst styles = StyleSheet.create({\n container: {\n overflow: \"hidden\",\n },\n itemsHorizontal: {\n flexDirection: \"row\",\n },\n itemsVertical: {\n flexDirection: \"column\",\n },\n});\n"]}
@@ -1,2 +0,0 @@
1
- var _interopRequireDefault=require("@babel/runtime/helpers/interopRequireDefault");Object.defineProperty(exports,"__esModule",{value:true});exports.LazyView=void 0;var _react=_interopRequireDefault(require("react"));var _jsxRuntime=require("react/jsx-runtime");var LazyView=function LazyView(props){var shouldUpdate=props.shouldUpdate,children=props.children;if(!shouldUpdate)return(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{});return(0,_jsxRuntime.jsx)(_jsxRuntime.Fragment,{children:children});};exports.LazyView=LazyView;
2
- //# sourceMappingURL=LazyView.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["LazyView.tsx"],"names":["LazyView","props","shouldUpdate","children"],"mappings":"oKACA,oD,6CAMO,GAAMA,CAAAA,QAA4C,CAAG,QAA/CA,CAAAA,QAA+C,CAACC,KAAD,CAAW,CACrE,GAAQC,CAAAA,YAAR,CAAmCD,KAAnC,CAAQC,YAAR,CAAsBC,QAAtB,CAAmCF,KAAnC,CAAsBE,QAAtB,CAEA,GAAI,CAACD,YAAL,CACE,MAAO,4CAAP,CAEF,MAAO,mDAAGC,QAAH,EAAP,CACD,CAPM,C","sourcesContent":["import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\n\ninterface Props {\n shouldUpdate: boolean\n}\n\nexport const LazyView: React.FC<PropsWithChildren<Props>> = (props) => {\n const { shouldUpdate, children } = props;\n\n if (!shouldUpdate)\n return <></>;\n\n return <>{children}</>;\n};\n"]}