react-native-reanimated-carousel 3.0.4 → 3.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,596 @@
1
+ ## [3.0.5](https://github.com/dohooo/react-native-reanimated-carousel/compare/v3.0.4...v3.0.5) (2022-09-15)
2
+
3
+ ## [3.0.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v3.0.3...v3.0.4) (2022-08-12)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * scrollTo is not running properly ([f406258](https://github.com/dohooo/react-native-reanimated-carousel/commit/f406258585e203a880ea82992c4ac79237f16df5)), closes [#222](https://github.com/dohooo/react-native-reanimated-carousel/issues/222)
9
+
10
+ ## [3.0.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v3.0.1...v3.0.3) (2022-06-28)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * carousel crashes when swiping in the opposite direction ([b5fc081](https://github.com/dohooo/react-native-reanimated-carousel/commit/b5fc081fe0f2617ee63f31ac6dcabc6715d465e0)), closes [#215](https://github.com/dohooo/react-native-reanimated-carousel/issues/215)
16
+
17
+ ## [3.0.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v3.0.0...v3.0.1) (2022-06-20)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * error message for horizontal carousels ([5a6e9af](https://github.com/dohooo/react-native-reanimated-carousel/commit/5a6e9afc8263fda708d7c9b104d00d563cbaa3b0))
23
+ * fixed `pagingEnabled` prop error ([3c17836](https://github.com/dohooo/react-native-reanimated-carousel/commit/3c1783600768bacaecabe2c82698ee18e50782fe))
24
+ * solved web side issues ([34f1108](https://github.com/dohooo/react-native-reanimated-carousel/commit/34f11084e57ac9d5e47880b0422daf0716e1e99c))
25
+ * upgrade example scripts ([4293608](https://github.com/dohooo/react-native-reanimated-carousel/commit/42936086edb9d19da66303d5bc2f3f993c727df9))
26
+
27
+
28
+ ### Features
29
+
30
+ * add circular animation ([289a1e8](https://github.com/dohooo/react-native-reanimated-carousel/commit/289a1e8497defd8903bae88d3def245fa6b69b99))
31
+ * add fold animation ([1de879f](https://github.com/dohooo/react-native-reanimated-carousel/commit/1de879f91b659b98dba02232d26ec1116ef5efad))
32
+
33
+ # [3.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.6.0...v3.0.0) (2022-06-10)
34
+
35
+
36
+ ### Bug Fixes
37
+
38
+ * update reanimated version for fix "undefined is not a function" ([a326f8c](https://github.com/dohooo/react-native-reanimated-carousel/commit/a326f8c58e3572b9a8fcaf8885c2b43208420af2)), closes [#159](https://github.com/dohooo/react-native-reanimated-carousel/issues/159)
39
+
40
+ # [2.6.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.5.1...v2.6.0) (2022-06-04)
41
+
42
+
43
+ ### Bug Fixes
44
+
45
+ * global.__reanimatedWorkletInit is not a function ([591f0d8](https://github.com/dohooo/react-native-reanimated-carousel/commit/591f0d89744d4f7b97784139c86fa1ef85a70606)), closes [#159](https://github.com/dohooo/react-native-reanimated-carousel/issues/159) [#182](https://github.com/dohooo/react-native-reanimated-carousel/issues/182)
46
+
47
+ ## [2.5.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.5.0...v2.5.1) (2022-06-01)
48
+
49
+ # [2.5.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.4.0...v2.5.0) (2022-05-29)
50
+
51
+
52
+ ### Bug Fixes
53
+
54
+ * modify styles prop types ([c32a98c](https://github.com/dohooo/react-native-reanimated-carousel/commit/c32a98cb5667b3b97601186726869e73efcb924e)), closes [#195](https://github.com/dohooo/react-native-reanimated-carousel/issues/195)
55
+
56
+
57
+ ### Features
58
+
59
+ * add index argument, can jump to specific position. And remove goToIndex prop in ref ([138e606](https://github.com/dohooo/react-native-reanimated-carousel/commit/138e606dccf8c94c2de800076695f38654ab911e)), closes [#196](https://github.com/dohooo/react-native-reanimated-carousel/issues/196)
60
+ * always return the real index ([03216a5](https://github.com/dohooo/react-native-reanimated-carousel/commit/03216a5761bd04a9220233f1bfbdd6dcb6549b7f)), closes [#192](https://github.com/dohooo/react-native-reanimated-carousel/issues/192)
61
+
62
+ # [2.4.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.11...v2.4.0) (2022-05-18)
63
+
64
+
65
+ ### Bug Fixes
66
+
67
+ * index bug ([57a18ad](https://github.com/dohooo/react-native-reanimated-carousel/commit/57a18ad8f3382b737030b29a5bbc449fbcf08cb7)), closes [#185](https://github.com/dohooo/react-native-reanimated-carousel/issues/185)
68
+
69
+ ## [2.3.11](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.10...v2.3.11) (2022-05-15)
70
+
71
+
72
+ ### Bug Fixes
73
+
74
+ * focused index is not persisted when carousel component is re-rendered ([d82d39b](https://github.com/dohooo/react-native-reanimated-carousel/commit/d82d39bfa1abd9060bad6756b0feccd894d22cbe)), closes [#181](https://github.com/dohooo/react-native-reanimated-carousel/issues/181)
75
+
76
+ ## [2.3.10](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.9...v2.3.10) (2022-05-04)
77
+
78
+
79
+ ### Bug Fixes
80
+
81
+ * getCurrentIndex always return last snap index even after multiple data changes ([9b03a4d](https://github.com/dohooo/react-native-reanimated-carousel/commit/9b03a4d7f53bf22c0ee78dc91ec74f42b865357b)), closes [#178](https://github.com/dohooo/react-native-reanimated-carousel/issues/178)
82
+
83
+
84
+ ### Features
85
+
86
+ * add testID props for e2e test ([a66eecb](https://github.com/dohooo/react-native-reanimated-carousel/commit/a66eecbe1603edb577ced79c63941d4d25c60ecc)), closes [#177](https://github.com/dohooo/react-native-reanimated-carousel/issues/177)
87
+
88
+ ## [2.3.9](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.8...v2.3.9) (2022-05-03)
89
+
90
+
91
+ ### Bug Fixes
92
+
93
+ * update typescript config ([8fa86a2](https://github.com/dohooo/react-native-reanimated-carousel/commit/8fa86a269afccdde77a9a2abe7ea75d658f22c9c))
94
+
95
+ ## [2.3.8](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.7...v2.3.8) (2022-05-02)
96
+
97
+
98
+ ### Bug Fixes
99
+
100
+ * fixed styles bug ([918bf45](https://github.com/dohooo/react-native-reanimated-carousel/commit/918bf45f1315d75017e96b32ab48830e13965224))
101
+
102
+ ## [2.3.7](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.6...v2.3.7) (2022-05-02)
103
+
104
+
105
+ ### Bug Fixes
106
+
107
+ * fix styles prop bug ([439ac4d](https://github.com/dohooo/react-native-reanimated-carousel/commit/439ac4d622f720cba287aa264573517218a365d6))
108
+
109
+ ## [2.3.6](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.5...v2.3.6) (2022-05-02)
110
+
111
+
112
+ ### Bug Fixes
113
+
114
+ * current index doesn't reset when modify data length ([99f44bc](https://github.com/dohooo/react-native-reanimated-carousel/commit/99f44bc995cf45970b151528aa9478cc03e1ceef)), closes [#163](https://github.com/dohooo/react-native-reanimated-carousel/issues/163)
115
+ * duplicate style ([7e7e00f](https://github.com/dohooo/react-native-reanimated-carousel/commit/7e7e00f4ee18bf92749f9e2224d4e0c7e98647ba)), closes [#169](https://github.com/dohooo/react-native-reanimated-carousel/issues/169)
116
+ * refactoring logic of withAutoFillData, Add onProgressChange value boundary ([101456a](https://github.com/dohooo/react-native-reanimated-carousel/commit/101456a4e7a3f4719db844b302bd6d5f912206cb)), closes [#158](https://github.com/dohooo/react-native-reanimated-carousel/issues/158)
117
+
118
+
119
+ ### Features
120
+
121
+ * add autoFillData props, It controls whether the data is automatically populated ([309688c](https://github.com/dohooo/react-native-reanimated-carousel/commit/309688cb6c862f059e3915df9dce1c3f62e8e146)), closes [#170](https://github.com/dohooo/react-native-reanimated-carousel/issues/170)
122
+
123
+ ## [2.3.5](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.4...v2.3.5) (2022-04-27)
124
+
125
+ ## [2.3.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.3...v2.3.4) (2022-04-10)
126
+
127
+
128
+ ### Bug Fixes
129
+
130
+ * "defaultIndex" wasn't define internal values (UI bridge and refs) ([7f7a659](https://github.com/dohooo/react-native-reanimated-carousel/commit/7f7a659a6e9863ecbdc7241d990c0e67c16313d0))
131
+
132
+ ## [2.3.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.3-beta.1...v2.3.3) (2022-04-03)
133
+
134
+ ## [2.3.3-beta.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.3-beta.0...v2.3.3-beta.1) (2022-03-30)
135
+
136
+
137
+ ### Bug Fixes
138
+
139
+ * add *length and remove *data from deps ([fbfd372](https://github.com/dohooo/react-native-reanimated-carousel/commit/fbfd37293cd5931f8843ee3346debfffdf3c404d))
140
+ * https://github.com/dohooo/react-native-reanimated-carousel/issues/66 ([54e74d2](https://github.com/dohooo/react-native-reanimated-carousel/commit/54e74d20d7f6e6f73e8ba45f223578bc9b8bd9b3))
141
+ * update example dependence ([ac2c504](https://github.com/dohooo/react-native-reanimated-carousel/commit/ac2c504b09ee109bad8a8602b844800341e2881b))
142
+
143
+
144
+ ### Features
145
+
146
+ * add flow animation ([d5d39a8](https://github.com/dohooo/react-native-reanimated-carousel/commit/d5d39a80cecbd9c5436b1c1c5f4faf8082ba976a))
147
+
148
+ ## [2.3.3-beta.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.2...v2.3.3-beta.0) (2022-03-30)
149
+
150
+ ## [2.3.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.2-beta.1...v2.3.2) (2022-03-03)
151
+
152
+ ## [2.3.2-beta.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.2-beta.0...v2.3.2-beta.1) (2022-03-03)
153
+
154
+
155
+ ### Bug Fixes
156
+
157
+ * remove logic that touch the screent will stopped animation ([4328d9a](https://github.com/dohooo/react-native-reanimated-carousel/commit/4328d9a1068a28817d12f4fb2ba066e419fad9c8))
158
+
159
+ ## [2.3.2-beta.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.1...v2.3.2-beta.0) (2022-03-03)
160
+
161
+ ## [2.3.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.3.0...v2.3.1) (2022-02-28)
162
+
163
+
164
+ ### Bug Fixes
165
+
166
+ * fix memory leak ([73a5fe2](https://github.com/dohooo/react-native-reanimated-carousel/commit/73a5fe20a247ed1de84d23b64d7ba981410950ca)), closes [#137](https://github.com/dohooo/react-native-reanimated-carousel/issues/137)
167
+
168
+
169
+ ### Features
170
+
171
+ * added "parallaxAdjacentItemScale" property into parallax layout ([7e98433](https://github.com/dohooo/react-native-reanimated-carousel/commit/7e98433eb6e91fadf22f27426ba2c004a35db7aa))
172
+
173
+ # [2.3.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.5-beta.3...v2.3.0) (2022-02-19)
174
+
175
+
176
+ ### Features
177
+
178
+ * add enabled props ([e713e12](https://github.com/dohooo/react-native-reanimated-carousel/commit/e713e125bf44a45a9e48ae75dbc00f665368711f))
179
+ * deprecated enableSnap instead with snapEnabled ([43c84c2](https://github.com/dohooo/react-native-reanimated-carousel/commit/43c84c2cc8ac45247c3ea348d912673ff1ef5132))
180
+
181
+ ## [2.2.5-beta.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.5-beta.2...v2.2.5-beta.3) (2022-02-04)
182
+
183
+ ## [2.2.5-beta.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.5-beta.1...v2.2.5-beta.2) (2022-02-04)
184
+
185
+ ## [2.2.5-beta.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.5-beta.0...v2.2.5-beta.1) (2022-02-04)
186
+
187
+ ## [2.2.5-beta.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.4...v2.2.5-beta.0) (2022-02-01)
188
+
189
+
190
+ ### Bug Fixes
191
+
192
+ * fixed type of props ([bb1e99b](https://github.com/dohooo/react-native-reanimated-carousel/commit/bb1e99bd2983d0d4a79a4ce3a9911f3edcb3391a))
193
+
194
+
195
+ ### Features
196
+
197
+ * support to modify scroll animation. Add `withAnimation` props ([e3f34a4](https://github.com/dohooo/react-native-reanimated-carousel/commit/e3f34a4be91c69cd1239c69c1bed1f306042bd7a)), closes [#105](https://github.com/dohooo/react-native-reanimated-carousel/issues/105)
198
+
199
+ ## [2.2.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.3...v2.2.4) (2022-01-25)
200
+
201
+
202
+ ### Bug Fixes
203
+
204
+ * fixed types error ([d7af323](https://github.com/dohooo/react-native-reanimated-carousel/commit/d7af323052bb30c70b24de1ac24a8de78f80cdf1)), closes [#118](https://github.com/dohooo/react-native-reanimated-carousel/issues/118)
205
+
206
+ ## [2.2.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.2...v2.2.3) (2022-01-24)
207
+
208
+
209
+ ### Bug Fixes
210
+
211
+ * autoplay will paused when click ([eb21293](https://github.com/dohooo/react-native-reanimated-carousel/commit/eb21293d6c0544da9e62a418505945dc46a59cb6)), closes [#115](https://github.com/dohooo/react-native-reanimated-carousel/issues/115)
212
+
213
+ ## [2.2.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.2.1...v2.2.2) (2022-01-23)
214
+
215
+
216
+ ### Bug Fixes
217
+
218
+ * onProgressChange & onSnapToItem bug when only 2 image ([bdb2d74](https://github.com/dohooo/react-native-reanimated-carousel/commit/bdb2d74245dfdefe024ba11b462dbe29bd7e18d6)), closes [#74](https://github.com/dohooo/react-native-reanimated-carousel/issues/74)
219
+ * when autoPlay is false, manual sliding will still autoPlay ([6aa3cc4](https://github.com/dohooo/react-native-reanimated-carousel/commit/6aa3cc4a557efaa9e3262202f4a98ff960255b54)), closes [#111](https://github.com/dohooo/react-native-reanimated-carousel/issues/111)
220
+
221
+ ## [2.2.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.1.2...v2.2.1) (2022-01-16)
222
+
223
+
224
+ ### Bug Fixes
225
+
226
+ * fix comments ([753051f](https://github.com/dohooo/react-native-reanimated-carousel/commit/753051fddea78d0edc7ddffc657bc65a4c272dde))
227
+ * fix useCarouselController ([f5dc6dc](https://github.com/dohooo/react-native-reanimated-carousel/commit/f5dc6dc8976b2dddf387a7cd564d51756f04893b)), closes [#101](https://github.com/dohooo/react-native-reanimated-carousel/issues/101)
228
+
229
+ # [2.2.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.1.2...v2.2.0) (2022-01-16)
230
+
231
+
232
+ ### Bug Fixes
233
+
234
+ * fix useCarouselController ([f5dc6dc](https://github.com/dohooo/react-native-reanimated-carousel/commit/f5dc6dc8976b2dddf387a7cd564d51756f04893b)), closes [#101](https://github.com/dohooo/react-native-reanimated-carousel/issues/101)
235
+
236
+ ## [2.1.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.1.1...v2.1.2) (2022-01-11)
237
+
238
+
239
+ ### Bug Fixes
240
+
241
+ * fix wrong offset when out of bounds ([db27279](https://github.com/dohooo/react-native-reanimated-carousel/commit/db2727951916876205a315c4b2fdcee63e74fab0)), closes [#94](https://github.com/dohooo/react-native-reanimated-carousel/issues/94)
242
+ * remove ExtrapolateParameter of normal layout translate ([850e960](https://github.com/dohooo/react-native-reanimated-carousel/commit/850e96082ec44422d99c5a5a1767a6530b1405d9)), closes [#96](https://github.com/dohooo/react-native-reanimated-carousel/issues/96)
243
+
244
+ ## [2.1.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.1.0...v2.1.1) (2022-01-11)
245
+
246
+
247
+ ### Bug Fixes
248
+
249
+ * autoplay will scroll out of bounds ([2cfacff](https://github.com/dohooo/react-native-reanimated-carousel/commit/2cfacffb62f1e4934393cb5f42e55cbdddc2d8f2))
250
+
251
+ # [2.1.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.0.0...v2.1.0) (2022-01-08)
252
+
253
+
254
+ ### Features
255
+
256
+ * pass animation value to renderItem ([bf57233](https://github.com/dohooo/react-native-reanimated-carousel/commit/bf572335a19179aefd52d0bf43e61029ec2f945a)), closes [#89](https://github.com/dohooo/react-native-reanimated-carousel/issues/89)
257
+ * support to custom carousel animations by `customAnimation` `customConfig` props ([eb3082b](https://github.com/dohooo/react-native-reanimated-carousel/commit/eb3082b74d3f08f6205cce47a30435ffc8570145))
258
+
259
+
260
+ ### BREAKING CHANGES
261
+
262
+ * Remove the parameter of `renderItem` and change it to `info` object
263
+
264
+
265
+
266
+ ## [1.1.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v2.0.0...v2.1.0) (2022-01-04)
267
+
268
+
269
+ ### Bug Fixes
270
+
271
+ * fix bug with windowSize props ([8a048df](https://github.com/dohooo/react-native-reanimated-carousel/commit/8a048dfafbf46ba6d4776f82564dea43af026144)), closes [#71](https://github.com/dohooo/react-native-reanimated-carousel/issues/71)
272
+
273
+ # [2.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.2.0-beta.4...v2.0.0) (2022-01-07)
274
+
275
+
276
+ ### Bug Fixes
277
+
278
+ * fix bug from refactoring ([c77f4d8](https://github.com/dohooo/react-native-reanimated-carousel/commit/c77f4d8604e319528f2d15fd288734749615e077))
279
+
280
+ # [1.2.0-beta.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.2.0-beta.3...v1.2.0-beta.4) (2022-01-05)
281
+
282
+
283
+ ### Bug Fixes
284
+
285
+ * solve a bug caused by Parallax/Normal layout reconstruction ([651bf5e](https://github.com/dohooo/react-native-reanimated-carousel/commit/651bf5ee0572f512dddc01205dbb74d651cfa0ce))
286
+
287
+ # [1.2.0-beta.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2022-01-05)
288
+
289
+
290
+ ### Bug Fixes
291
+
292
+ * fix bug with windowSize props ([b9637ca](https://github.com/dohooo/react-native-reanimated-carousel/commit/b9637ca4f988851c6f0636e50c8079837eda42f6)), closes [#71](https://github.com/dohooo/react-native-reanimated-carousel/issues/71)
293
+ * onProgressChange/onSnapToItem props wrong calculation ([85de2f4](https://github.com/dohooo/react-native-reanimated-carousel/commit/85de2f41935e299ff7510e5b678e0f37fc29d13e)), closes [#74](https://github.com/dohooo/react-native-reanimated-carousel/issues/74)
294
+
295
+
296
+ ### Features
297
+
298
+ * support to RTL ([c2c3bcf](https://github.com/dohooo/react-native-reanimated-carousel/commit/c2c3bcfd2fe475b9934962d62e97bc39bf8fdf2d)), closes [#69](https://github.com/dohooo/react-native-reanimated-carousel/issues/69)
299
+
300
+
301
+
302
+ # [1.1.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2022-01-03)
303
+
304
+
305
+ ### Bug Fixes
306
+
307
+ * _ ([c8054f1](https://github.com/dohooo/react-native-reanimated-carousel/commit/c8054f17202e7ff33447cd70e83582f4914941ad))
308
+ * fix item blink when scroll active ([96c9b75](https://github.com/dohooo/react-native-reanimated-carousel/commit/96c9b751a7ee4cc0ba013801d098b05705c26bcf))
309
+ * fix with zindex ([f3b28cc](https://github.com/dohooo/react-native-reanimated-carousel/commit/f3b28cc8a83649a885307b82908e714bb2724ab4))
310
+ * item blink ([063f564](https://github.com/dohooo/react-native-reanimated-carousel/commit/063f5644779f37754608972507b10d0cfb87769a))
311
+ * item zIndex ([10e58a8](https://github.com/dohooo/react-native-reanimated-carousel/commit/10e58a876e8cb386a45d17ea8eb8bee79de0e94a))
312
+ * refactor stack layout ([dc975fe](https://github.com/dohooo/react-native-reanimated-carousel/commit/dc975fe8f25b03b59047fd21f596d626f806de2b))
313
+
314
+
315
+ ### Features
316
+
317
+ * add stack layout ([5a70a23](https://github.com/dohooo/react-native-reanimated-carousel/commit/5a70a230307e0b258e16230d6b21be2c4d8c7497))
318
+ * multiple stack styles are supported ([d4497a7](https://github.com/dohooo/react-native-reanimated-carousel/commit/d4497a785f6da4dae79e812dac1d5515303d0cd3))
319
+ * support pagingEnabled snapEnabled ([000658e](https://github.com/dohooo/react-native-reanimated-carousel/commit/000658ed4a97b58d4e2649b6ab816e62919beff9)), closes [#65](https://github.com/dohooo/react-native-reanimated-carousel/issues/65)
320
+
321
+
322
+
323
+ ## [1.0.12](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-28)
324
+
325
+
326
+ ### Bug Fixes
327
+
328
+ * scroll pass the last item ([34a5e57](https://github.com/dohooo/react-native-reanimated-carousel/commit/34a5e5796a35f62374761bf2144a86f69acc8e66)), closes [#63](https://github.com/dohooo/react-native-reanimated-carousel/issues/63)
329
+
330
+
331
+
332
+ ## [1.0.11](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-20)
333
+
334
+
335
+ ### Bug Fixes
336
+
337
+ * fixed useAnimatedReaction wrong import ([7b7a3fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/7b7a3fc4f49b5f3bfff664b2c07306334ac2e509))
338
+
339
+
340
+
341
+ ## [1.0.10](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-19)
342
+
343
+
344
+ ### Bug Fixes
345
+
346
+ * fix ScrollViewGesture callback ([40412fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/40412fcab6c1e6e013ccd8c409c2fb9bffcde926))
347
+ * fixed failure to set default values ([5d02779](https://github.com/dohooo/react-native-reanimated-carousel/commit/5d0277925a0daf00944e7900d86f3ee463f77719))
348
+ * fixed types ([9f3068b](https://github.com/dohooo/react-native-reanimated-carousel/commit/9f3068bbb9dadbdd046ad50cf4437b53f335e4a9))
349
+ * modify useCarouselController params ([c8f2c6a](https://github.com/dohooo/react-native-reanimated-carousel/commit/c8f2c6acb9b578fa38d365c669aaf2beb6694686))
350
+
351
+
352
+ ### Features
353
+
354
+ * add babel-loader in example,support to web ([1edc9c3](https://github.com/dohooo/react-native-reanimated-carousel/commit/1edc9c34a7a02e35fa6c18927d8b543367bb1c30))
355
+ * add examples ([666ba86](https://github.com/dohooo/react-native-reanimated-carousel/commit/666ba86729105bb825f95a9dbdc4290efbd3dffa))
356
+ * add navigation in example ([1687f1d](https://github.com/dohooo/react-native-reanimated-carousel/commit/1687f1db4c98e583f29326dc1b2a273adb19af4e))
357
+ * add ScrollViewGesture ([a903f12](https://github.com/dohooo/react-native-reanimated-carousel/commit/a903f12d73a18c2774318154544dda17c755f6ff))
358
+ * lazy loading ([ed75232](https://github.com/dohooo/react-native-reanimated-carousel/commit/ed75232eb25a475f994f327e94f9dd717b9cf251))
359
+ * springConfig props has be deprecated ([763c073](https://github.com/dohooo/react-native-reanimated-carousel/commit/763c07398f196391ebf478ebd9c45acd7c6890a3))
360
+ * vertical mode ([7645b75](https://github.com/dohooo/react-native-reanimated-carousel/commit/7645b753f9379cb86bba27764a99cd163a744570)), closes [#41](https://github.com/dohooo/react-native-reanimated-carousel/issues/41)
361
+
362
+
363
+ ### Performance Improvements
364
+
365
+ * add example ([1684038](https://github.com/dohooo/react-native-reanimated-carousel/commit/16840383712eda31b1a8481fa5498ed9b92504cd))
366
+ * add example ([8527ffb](https://github.com/dohooo/react-native-reanimated-carousel/commit/8527ffbd2b374f880a42d445a24c385c18885859))
367
+ * lazy loading ([39ba773](https://github.com/dohooo/react-native-reanimated-carousel/commit/39ba7735946326c10dd5ec8b6ffe6a8fcf9a8006))
368
+
369
+
370
+
371
+ ## [1.0.9](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-07)
372
+
373
+
374
+ ### Performance Improvements
375
+
376
+ * add props 'windowSize' ([4e066ee](https://github.com/dohooo/react-native-reanimated-carousel/commit/4e066eed5a3d3eb9cc4a9d1173831a44385bac65)), closes [#46](https://github.com/dohooo/react-native-reanimated-carousel/issues/46)
377
+ * reduce the calculation of animation values ([de32274](https://github.com/dohooo/react-native-reanimated-carousel/commit/de322745d900251614e25005fe39dd32fab4e9a7)), closes [#46](https://github.com/dohooo/react-native-reanimated-carousel/issues/46)
378
+
379
+
380
+
381
+ ## [1.0.8](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-06)
382
+
383
+
384
+ ### Bug Fixes
385
+
386
+ * fix items position ([6d36555](https://github.com/dohooo/react-native-reanimated-carousel/commit/6d365550b677513c3b56ed3a401dbf021a0d2856)), closes [#51](https://github.com/dohooo/react-native-reanimated-carousel/issues/51)
387
+
388
+
389
+
390
+ ## [1.0.7](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-12-05)
391
+
392
+
393
+ ### Bug Fixes
394
+
395
+ * a quick call to the page number switch method causes an offset error ([0c93b86](https://github.com/dohooo/react-native-reanimated-carousel/commit/0c93b867f4e17583b08683404a36590fc267c03c)), closes [#30](https://github.com/dohooo/react-native-reanimated-carousel/issues/30)
396
+ * defaultIndex does not work as expected ([42e4616](https://github.com/dohooo/react-native-reanimated-carousel/commit/42e46166144ceac6b15c6ad4e7d18923a722f91b)), closes [#33](https://github.com/dohooo/react-native-reanimated-carousel/issues/33)
397
+ * fix computed error with MAX/MIN ([e9a3007](https://github.com/dohooo/react-native-reanimated-carousel/commit/e9a30070dbae04a889015be05aff398079f35e84))
398
+ * image flickers within Carousel when state is updated ([094f3af](https://github.com/dohooo/react-native-reanimated-carousel/commit/094f3af65b517f59d2982d3dcfc64dab1404fcc5)), closes [#32](https://github.com/dohooo/react-native-reanimated-carousel/issues/32)
399
+ * modify useOffsetX viewCount default value ([dd30b9c](https://github.com/dohooo/react-native-reanimated-carousel/commit/dd30b9c0ec52917eeb1d0a144e46318a1bae7da8))
400
+ * sliding error with no loop ([955b5ed](https://github.com/dohooo/react-native-reanimated-carousel/commit/955b5ede0d975231feab55258823a9538752c0e2)), closes [#24](https://github.com/dohooo/react-native-reanimated-carousel/issues/24)
401
+
402
+
403
+
404
+ ## [1.0.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-18)
405
+
406
+
407
+ ### Bug Fixes
408
+
409
+ * **hooks/usepropserrorboundary.ts:** always be error when data props set null ([2450fe1](https://github.com/dohooo/react-native-reanimated-carousel/commit/2450fe120b22ec561a3bc7c4b687ccfee0bfc080)), closes [#34](https://github.com/dohooo/react-native-reanimated-carousel/issues/34)
410
+
411
+
412
+
413
+ ## [1.0.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-10)
414
+
415
+
416
+ ### Features
417
+
418
+ * add defaultIndex props ([e9191f9](https://github.com/dohooo/react-native-reanimated-carousel/commit/e9191f96dab5885ca14bc873b5feeb6fa80ac82a)), closes [#31](https://github.com/dohooo/react-native-reanimated-carousel/issues/31)
419
+
420
+
421
+
422
+ ## [1.0.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-03)
423
+
424
+
425
+ ### Features
426
+
427
+ * add onProgressChange props ([a3894ff](https://github.com/dohooo/react-native-reanimated-carousel/commit/a3894ffb64d2541e61683d06c53487dc54af1a47))
428
+
429
+
430
+
431
+ ## [1.0.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-11-01)
432
+
433
+
434
+ ### Bug Fixes
435
+
436
+ * fix bug with reanimated ([6744f74](https://github.com/dohooo/react-native-reanimated-carousel/commit/6744f747424d6ad51e61bca0702eec8e60d00441))
437
+
438
+
439
+
440
+ # [1.0.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-31)
441
+
442
+
443
+ ### Bug Fixes
444
+
445
+ * fix default timeConfig ([0f99500](https://github.com/dohooo/react-native-reanimated-carousel/commit/0f9950005604fa19ff73449a58b3944bd4f1fee2))
446
+ * solve sliding flicker problem ([96678e0](https://github.com/dohooo/react-native-reanimated-carousel/commit/96678e0d3c03ea6f6bc9a40534c1bb732475e102))
447
+ * solve sliding flicker problem ([e26c384](https://github.com/dohooo/react-native-reanimated-carousel/commit/e26c384f25b203a420f7bed2c356586cb1466f65))
448
+ * upgrade expo sdk 40 to 41. fix example error ([11b39b1](https://github.com/dohooo/react-native-reanimated-carousel/commit/11b39b16f682551ad1b2b67e497ea0709d7b7766))
449
+
450
+
451
+ ### Features
452
+
453
+ * improve sliding experience ([14b62ee](https://github.com/dohooo/react-native-reanimated-carousel/commit/14b62ee3ae63bfff693891c1bfc0fa39278e2ed3))
454
+
455
+
456
+ ### BREAKING CHANGES
457
+
458
+ * remove props "timingConfig", add "springConfig" with no support of duration
459
+
460
+
461
+
462
+ ## [0.5.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-27)
463
+
464
+
465
+ ### Bug Fixes
466
+
467
+ * onSnapToItem gives floating index ([13d6c64](https://github.com/dohooo/react-native-reanimated-carousel/commit/13d6c6485f4fa54bf944b10947f928b2cf88c7b7)), closes [#13](https://github.com/dohooo/react-native-reanimated-carousel/issues/13)
468
+
469
+
470
+
471
+ ## [0.5.3-beta.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-27)
472
+
473
+
474
+ ### Bug Fixes
475
+
476
+ * drag issues occur when auto-scrolling ([ebb0ce2](https://github.com/dohooo/react-native-reanimated-carousel/commit/ebb0ce20d35b134755b163ea9ffc0e85daffdb9c)), closes [#13](https://github.com/dohooo/react-native-reanimated-carousel/issues/13)
477
+
478
+
479
+
480
+ ## [0.5.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-19)
481
+
482
+
483
+
484
+ ## [0.5.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-09)
485
+
486
+
487
+ ### Features
488
+
489
+ * add onScrollBegin/onScrollEnd props ([3180696](https://github.com/dohooo/react-native-reanimated-carousel/commit/31806966ca644d086bfea7a872108b1006e50ecf))
490
+
491
+
492
+
493
+ # [0.5.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-10-08)
494
+
495
+
496
+ ### Bug Fixes
497
+
498
+ * fix onSnapToItem no call when auto playing ([4953b98](https://github.com/dohooo/react-native-reanimated-carousel/commit/4953b9805beb5a591ee0b261c81c7dd623337a75))
499
+ * onSnapToItem not called if loop={false} ([1ce57f4](https://github.com/dohooo/react-native-reanimated-carousel/commit/1ce57f4e0201c2d50a1ce754f08b6afb5661a6a1))
500
+
501
+
502
+ ### Features
503
+
504
+ * add goToIndex method ([b33bb78](https://github.com/dohooo/react-native-reanimated-carousel/commit/b33bb788e5849615b5c90b122633507ec0f2bfbf))
505
+
506
+
507
+
508
+ ## [0.4.4](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-30)
509
+
510
+
511
+ ### Bug Fixes
512
+
513
+ * fix animation bug ([d3b6831](https://github.com/dohooo/react-native-reanimated-carousel/commit/d3b683169cca9fba3083b52133758a7a39dcf25e))
514
+
515
+
516
+
517
+ ## [0.4.3](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-09)
518
+
519
+
520
+ ### Bug Fixes
521
+
522
+ * sliding causes problems with sliding errors when auto playing ([37f6565](https://github.com/dohooo/react-native-reanimated-carousel/commit/37f656539fed21f5a7d4148af02954b97f95a7f7))
523
+
524
+
525
+
526
+ ## [0.4.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-09)
527
+
528
+
529
+ ### Bug Fixes
530
+
531
+ * fixed scrolling on Android ([d253b3c](https://github.com/dohooo/react-native-reanimated-carousel/commit/d253b3cc30538a2702dceeb2be37c99fb2ee2d67))
532
+
533
+
534
+
535
+ ## [0.4.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
536
+
537
+
538
+ ### Bug Fixes
539
+
540
+ * handles boundary cases for raw data ([4386bfd](https://github.com/dohooo/react-native-reanimated-carousel/commit/4386bfd59553c2df53c3987c539e299fac52a491))
541
+
542
+
543
+
544
+ # [0.4.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
545
+
546
+
547
+ ### Features
548
+
549
+ * add onSnapToItem props,should get current item info ([6ae05fc](https://github.com/dohooo/react-native-reanimated-carousel/commit/6ae05fcaa382c4b406d135c66bebdaa614c07b67))
550
+
551
+
552
+
553
+ ## [0.3.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
554
+
555
+
556
+ ### Bug Fixes
557
+
558
+ * after data props update carousel not be can swipe ([dd00932](https://github.com/dohooo/react-native-reanimated-carousel/commit/dd00932b65df0e7efdc10e4f4e72cf8da5ca8456))
559
+
560
+
561
+
562
+ # [0.3.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-08)
563
+
564
+
565
+ ### Features
566
+
567
+ * add loop props,control wheter loop playback ([97cf2b9](https://github.com/dohooo/react-native-reanimated-carousel/commit/97cf2b99c9279fc65da323e35b3461bc1df64b15))
568
+
569
+
570
+
571
+ ## [0.2.2](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
572
+
573
+
574
+
575
+ ## [0.2.1](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
576
+
577
+
578
+ ### Bug Fixes
579
+
580
+ * fix calculation errors ([15b2119](https://github.com/dohooo/react-native-reanimated-carousel/commit/15b21192b510902e833900b5fc44affd78941614))
581
+
582
+
583
+
584
+ # [0.2.0](https://github.com/dohooo/react-native-reanimated-carousel/compare/v1.1.0...v1.2.0-beta.3) (2021-09-07)
585
+
586
+
587
+ ### Bug Fixes
588
+
589
+ * fix algorithm errors ([af61df8](https://github.com/dohooo/react-native-reanimated-carousel/commit/af61df8da51c56940449c4f1c50440f567e33c46))
590
+
591
+
592
+ ### Features
593
+
594
+ * export types ([2dcceb8](https://github.com/dohooo/react-native-reanimated-carousel/commit/2dcceb8001eff1b16c64399a4ca1b372ac9e8026))
595
+ * first commit of carousel component ([af964e3](https://github.com/dohooo/react-native-reanimated-carousel/commit/af964e331ae7b4363a407451344d9ffc1369b91f))
596
+
package/README.md CHANGED
@@ -15,7 +15,7 @@ English | [简体中文](./README.zh-CN.md)
15
15
  ## ReactNative community's best use of the carousel component! 🎉🎉🎉
16
16
 
17
17
  - **It completely solves this** [[problem]](https://github.com/meliorence/react-native-snap-carousel/issues/632) **for `react-native-snap-carousel`!**
18
- - **Simple**、**Infinitely scrolling very smooth**、**Fully implemented using Reanimated 2!**
18
+ - **Simple**, **Infinitely scrolling very smooth**, **Fully implemented using Reanimated 2!**
19
19
 
20
20
  > V2 has been released! Join it! [[v1 docs]](https://github.com/dohooo/react-native-reanimated-carousel/tree/v1.x.x)
21
21
 
@@ -1,2 +1,2 @@
1
- Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireWildcard(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _log=require("../utils/log");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function useCarouselController(options){var size=options.size,data=options.data,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex,duration=options.duration,autoFillData=options.autoFillData;var dataInfo=_react.default.useMemo(function(){return{length:data.length,disable:!data.length,originalLength:data.length};},[data]);var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=(0,_react.useRef)(defaultIndex);var sharedPreIndex=(0,_react.useRef)(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%dataInfo.length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?dataInfo.length-fixed:0));},[handlerOffsetX,dataInfo,size,loop]);function setSharedIndex(newSharedIndex){sharedIndex.current=newSharedIndex;}(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){var handlerOffsetXValue=handlerOffsetX.value;var toInt=(0,_log.round)(handlerOffsetXValue/size)%dataInfo.length;var isPositive=handlerOffsetXValue<=0;var i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);var newSharedIndexValue=(0,_computedWithAutoFillData.convertToSharedIndex)({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};};_f._closure={handlerOffsetX:handlerOffsetX,round:_log.round,size:size,dataInfo:dataInfo,convertToSharedIndex:_computedWithAutoFillData.convertToSharedIndex,loop:loop,autoFillData:autoFillData};_f.asString="function _f(){const{handlerOffsetX,round,size,dataInfo,convertToSharedIndex,loop,autoFillData}=jsThis._closure;{const handlerOffsetXValue=handlerOffsetX.value;const toInt=round(handlerOffsetXValue/size)%dataInfo.length;const isPositive=handlerOffsetXValue<=0;const i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);const newSharedIndexValue=convertToSharedIndex({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};}}";_f.__workletHash=14011541648783;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (83:8)";return _f;}(),function(){var _f=function _f(_ref){var i=_ref.i,newSharedIndexValue=_ref.newSharedIndexValue;index.value=i;(0,_reactNativeReanimated.runOnJS)(setSharedIndex)(newSharedIndexValue);};_f._closure={index:index,runOnJS:_reactNativeReanimated.runOnJS,setSharedIndex:setSharedIndex};_f.asString="function _f({i:i,newSharedIndexValue:newSharedIndexValue}){const{index,runOnJS,setSharedIndex}=jsThis._closure;{index.value=i;runOnJS(setSharedIndex)(newSharedIndexValue);}}";_f.__workletHash=16638491076412;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (103:8)";return _f;}(),[sharedPreIndex,sharedIndex,size,dataInfo,index,loop,autoFillData,handlerOffsetX]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!dataInfo.disable;},[dataInfo]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (138:29)";return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (136:8)";return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,dataInfo:dataInfo,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,dataInfo,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=1734401141936;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (160:8)";return _f;}(),[canSliding,loop,index,dataInfo,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(opts){var i=opts.i,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(i===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var direction=handlerOffsetX.value/Math.abs(handlerOffsetX.value);var offset=i*size*direction;var totalSize=dataInfo.length*size;var isCloseToNextLoop=false;if(loop){isCloseToNextLoop=Math.abs(handlerOffsetX.value%totalSize)/totalSize>=0.5;}var finalOffset=(Math.floor(Math.abs(handlerOffsetX.value/totalSize))+(isCloseToNextLoop?1:0))*totalSize*direction+offset;if(animated){index.value=i;handlerOffsetX.value=scrollWithTiming(finalOffset,onFinished);}else{handlerOffsetX.value=finalOffset;index.value=i;onFinished==null?void 0:onFinished();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,dataInfo.length,loop,scrollWithTiming]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var i=opts.index,count=opts.count,_opts$animated4=opts.animated,animated=_opts$animated4===void 0?false:_opts$animated4,onFinished=opts.onFinished;if(typeof i==='number'&&i>-1){to({i:i,animated:animated,onFinished:onFinished});return;}if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next,to]);return{next:next,prev:prev,scrollTo:scrollTo,getCurrentIndex:getCurrentIndex,getSharedIndex:function getSharedIndex(){return sharedIndex.current;}};}
1
+ Object.defineProperty(exports,"__esModule",{value:true});exports.useCarouselController=useCarouselController;var _react=_interopRequireWildcard(require("react"));var _constants=require("../constants");var _reactNativeReanimated=require("react-native-reanimated");var _dealWithAnimation=require("../utils/dealWithAnimation");var _computedWithAutoFillData=require("../utils/computedWithAutoFillData");var _log=require("../utils/log");function _getRequireWildcardCache(nodeInterop){if(typeof WeakMap!=="function")return null;var cacheBabelInterop=new WeakMap();var cacheNodeInterop=new WeakMap();return(_getRequireWildcardCache=function _getRequireWildcardCache(nodeInterop){return nodeInterop?cacheNodeInterop:cacheBabelInterop;})(nodeInterop);}function _interopRequireWildcard(obj,nodeInterop){if(!nodeInterop&&obj&&obj.__esModule){return obj;}if(obj===null||typeof obj!=="object"&&typeof obj!=="function"){return{default:obj};}var cache=_getRequireWildcardCache(nodeInterop);if(cache&&cache.has(obj)){return cache.get(obj);}var newObj={};var hasPropertyDescriptor=Object.defineProperty&&Object.getOwnPropertyDescriptor;for(var key in obj){if(key!=="default"&&Object.prototype.hasOwnProperty.call(obj,key)){var desc=hasPropertyDescriptor?Object.getOwnPropertyDescriptor(obj,key):null;if(desc&&(desc.get||desc.set)){Object.defineProperty(newObj,key,desc);}else{newObj[key]=obj[key];}}}newObj.default=obj;if(cache){cache.set(obj,newObj);}return newObj;}function useCarouselController(options){var size=options.size,data=options.data,loop=options.loop,handlerOffsetX=options.handlerOffsetX,withAnimation=options.withAnimation,_options$defaultIndex=options.defaultIndex,defaultIndex=_options$defaultIndex===void 0?0:_options$defaultIndex,duration=options.duration,autoFillData=options.autoFillData;var dataInfo=_react.default.useMemo(function(){return{length:data.length,disable:!data.length,originalLength:data.length};},[data]);var index=(0,_reactNativeReanimated.useSharedValue)(defaultIndex);var sharedIndex=(0,_react.useRef)(defaultIndex);var sharedPreIndex=(0,_react.useRef)(defaultIndex);var currentFixedPage=_react.default.useCallback(function(){if(loop){return-Math.round(handlerOffsetX.value/size);}var fixed=handlerOffsetX.value/size%dataInfo.length;return Math.round(handlerOffsetX.value<=0?Math.abs(fixed):Math.abs(fixed>0?dataInfo.length-fixed:0));},[handlerOffsetX,dataInfo,size,loop]);function setSharedIndex(newSharedIndex){sharedIndex.current=newSharedIndex;}(0,_reactNativeReanimated.useAnimatedReaction)(function(){var _f=function _f(){var handlerOffsetXValue=handlerOffsetX.value;var toInt=(0,_log.round)(handlerOffsetXValue/size)%dataInfo.length;var isPositive=handlerOffsetXValue<=0;var i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);var newSharedIndexValue=(0,_computedWithAutoFillData.convertToSharedIndex)({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};};_f._closure={handlerOffsetX:handlerOffsetX,round:_log.round,size:size,dataInfo:dataInfo,convertToSharedIndex:_computedWithAutoFillData.convertToSharedIndex,loop:loop,autoFillData:autoFillData};_f.asString="function _f(){const{handlerOffsetX,round,size,dataInfo,convertToSharedIndex,loop,autoFillData}=jsThis._closure;{const handlerOffsetXValue=handlerOffsetX.value;const toInt=round(handlerOffsetXValue/size)%dataInfo.length;const isPositive=handlerOffsetXValue<=0;const i=isPositive?Math.abs(toInt):Math.abs(toInt>0?dataInfo.length-toInt:0);const newSharedIndexValue=convertToSharedIndex({loop:loop,rawDataLength:dataInfo.originalLength,autoFillData:autoFillData,index:i});return{i:i,newSharedIndexValue:newSharedIndexValue};}}";_f.__workletHash=14011541648783;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (83:8)";return _f;}(),function(){var _f=function _f(_ref){var i=_ref.i,newSharedIndexValue=_ref.newSharedIndexValue;index.value=i;(0,_reactNativeReanimated.runOnJS)(setSharedIndex)(newSharedIndexValue);};_f._closure={index:index,runOnJS:_reactNativeReanimated.runOnJS,setSharedIndex:setSharedIndex};_f.asString="function _f({i:i,newSharedIndexValue:newSharedIndexValue}){const{index,runOnJS,setSharedIndex}=jsThis._closure;{index.value=i;runOnJS(setSharedIndex)(newSharedIndexValue);}}";_f.__workletHash=16638491076412;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (103:8)";return _f;}(),[sharedPreIndex,sharedIndex,size,dataInfo,index,loop,autoFillData,handlerOffsetX]);var getCurrentIndex=_react.default.useCallback(function(){return index.value;},[index]);var canSliding=_react.default.useCallback(function(){return!dataInfo.disable;},[dataInfo]);var onScrollEnd=_react.default.useCallback(function(){options.onScrollEnd==null?void 0:options.onScrollEnd();},[options]);var onScrollBegin=_react.default.useCallback(function(){options.onScrollBegin==null?void 0:options.onScrollBegin();},[options]);var scrollWithTiming=_react.default.useCallback(function(){var _f=function _f(toValue,onFinished){var callback=function(){var _f=function _f(isFinished){if(isFinished){(0,_reactNativeReanimated.runOnJS)(onScrollEnd)();onFinished&&(0,_reactNativeReanimated.runOnJS)(onFinished)();}};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,onFinished:onFinished};_f.asString="function _f(isFinished){const{runOnJS,onScrollEnd,onFinished}=jsThis._closure;{if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}}}";_f.__workletHash=7767198641261;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (138:29)";return _f;}();var defaultWithAnimation={type:'timing',config:{duration:duration,easing:_constants.Easing.easeOutQuart}};return(0,_dealWithAnimation.dealWithAnimation)(withAnimation!=null?withAnimation:defaultWithAnimation)(toValue,callback);};_f._closure={runOnJS:_reactNativeReanimated.runOnJS,onScrollEnd:onScrollEnd,duration:duration,Easing:{easeOutQuart:_constants.Easing.easeOutQuart},dealWithAnimation:_dealWithAnimation.dealWithAnimation,withAnimation:withAnimation};_f.asString="function _f(toValue,onFinished){const{runOnJS,onScrollEnd,duration,Easing,dealWithAnimation,withAnimation}=jsThis._closure;{var _withAnimation;const callback=function(isFinished){'worklet';if(isFinished){runOnJS(onScrollEnd)();onFinished&&runOnJS(onFinished)();}};const defaultWithAnimation={type:'timing',config:{duration:duration,easing:Easing.easeOutQuart}};return dealWithAnimation((_withAnimation=withAnimation)!==null&&_withAnimation!==void 0?_withAnimation:defaultWithAnimation)(toValue,callback);}}";_f.__workletHash=15006680124176;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (136:8)";return _f;}(),[duration,withAnimation,onScrollEnd]);var next=_react.default.useCallback(function(){var _f=function _f(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count=opts.count,count=_opts$count===void 0?1:_opts$count,_opts$animated=opts.animated,animated=_opts$animated===void 0?true:_opts$animated,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;onScrollBegin==null?void 0:onScrollBegin();var nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished==null?void 0:onFinished();}};_f._closure={canSliding:canSliding,loop:loop,index:index,dataInfo:dataInfo,onScrollBegin:onScrollBegin,currentFixedPage:currentFixedPage,handlerOffsetX:handlerOffsetX,scrollWithTiming:scrollWithTiming,size:size};_f.asString="function _f(opts={}){const{canSliding,loop,index,dataInfo,onScrollBegin,currentFixedPage,handlerOffsetX,scrollWithTiming,size}=jsThis._closure;{var _onScrollBegin;const{count=1,animated=true,onFinished:onFinished}=opts;if(!canSliding()||!loop&&index.value>=dataInfo.length-1)return;(_onScrollBegin=onScrollBegin)===null||_onScrollBegin===void 0?void 0:_onScrollBegin();const nextPage=currentFixedPage()+count;index.value=nextPage;if(animated){handlerOffsetX.value=scrollWithTiming(-nextPage*size,onFinished);}else{handlerOffsetX.value=-nextPage*size;onFinished===null||onFinished===void 0?void 0:onFinished();}}}";_f.__workletHash=1734401141936;_f.__location="/Users/zhaodonghao/code/github/react-native-reanimated-carousel/src/hooks/useCarouselController.tsx (160:8)";return _f;}(),[canSliding,loop,index,dataInfo,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var prev=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var _opts$count2=opts.count,count=_opts$count2===void 0?1:_opts$count2,_opts$animated2=opts.animated,animated=_opts$animated2===void 0?true:_opts$animated2,onFinished=opts.onFinished;if(!canSliding()||!loop&&index.value<=0)return;onScrollBegin==null?void 0:onScrollBegin();var prevPage=currentFixedPage()-count;index.value=prevPage;if(animated){handlerOffsetX.value=scrollWithTiming(-prevPage*size,onFinished);}else{handlerOffsetX.value=-prevPage*size;onFinished==null?void 0:onFinished();}},[canSliding,loop,index,onScrollBegin,handlerOffsetX,size,scrollWithTiming,currentFixedPage]);var to=_react.default.useCallback(function(opts){var i=opts.i,_opts$animated3=opts.animated,animated=_opts$animated3===void 0?false:_opts$animated3,onFinished=opts.onFinished;if(i===index.value)return;if(!canSliding())return;onScrollBegin==null?void 0:onScrollBegin();var isPositiveZero=Object.is(handlerOffsetX.value,+0);var isNegativeZero=Object.is(handlerOffsetX.value,-0);var direction=isPositiveZero?1:isNegativeZero?-1:Math.sign(handlerOffsetX.value);var offset=i*size*direction;var totalSize=dataInfo.length*size;var isCloseToNextLoop=false;if(loop){isCloseToNextLoop=Math.abs(handlerOffsetX.value%totalSize)/totalSize>=0.5;}var finalOffset=(Math.floor(Math.abs(handlerOffsetX.value/totalSize))+(isCloseToNextLoop?1:0))*totalSize*direction+offset;if(animated){index.value=i;handlerOffsetX.value=scrollWithTiming(finalOffset,onFinished);}else{handlerOffsetX.value=finalOffset;index.value=i;onFinished==null?void 0:onFinished();}},[index,canSliding,onScrollBegin,handlerOffsetX,size,dataInfo.length,loop,scrollWithTiming]);var scrollTo=_react.default.useCallback(function(){var opts=arguments.length>0&&arguments[0]!==undefined?arguments[0]:{};var i=opts.index,count=opts.count,_opts$animated4=opts.animated,animated=_opts$animated4===void 0?false:_opts$animated4,onFinished=opts.onFinished;if(typeof i==='number'&&i>-1){to({i:i,animated:animated,onFinished:onFinished});return;}if(!count){return;}var n=Math.round(count);if(n<0){prev({count:Math.abs(n),animated:animated,onFinished:onFinished});}else{next({count:n,animated:animated,onFinished:onFinished});}},[prev,next,to]);return{next:next,prev:prev,scrollTo:scrollTo,getCurrentIndex:getCurrentIndex,getSharedIndex:function getSharedIndex(){return sharedIndex.current;}};}
2
2
  //# sourceMappingURL=useCarouselController.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","React","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","convertToSharedIndex","runOnJS","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","direction","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"6GAAA,qDAEA,uCACA,8DAUA,6DACA,2EACA,iC,0/BAuBO,QAASA,CAAAA,qBAAT,CAA+BC,OAA/B,CAAoE,CACvE,GACIC,CAAAA,IADJ,CASID,OATJ,CACIC,IADJ,CAEIC,IAFJ,CASIF,OATJ,CAEIE,IAFJ,CAGIC,IAHJ,CASIH,OATJ,CAGIG,IAHJ,CAIIC,cAJJ,CASIJ,OATJ,CAIII,cAJJ,CAKIC,aALJ,CASIL,OATJ,CAKIK,aALJ,uBASIL,OATJ,CAMIM,YANJ,CAMIA,YANJ,gCAMmB,CANnB,uBAOIC,QAPJ,CASIP,OATJ,CAOIO,QAPJ,CAQIC,YARJ,CASIR,OATJ,CAQIQ,YARJ,CAWA,GAAMC,CAAAA,QAAQ,CAAGC,eAAMC,OAAN,CACb,iBAAO,CACHC,MAAM,CAAEV,IAAI,CAACU,MADV,CAEHC,OAAO,CAAE,CAACX,IAAI,CAACU,MAFZ,CAGHE,cAAc,CAAEZ,IAAI,CAACU,MAHlB,CAAP,EADa,CAMb,CAACV,IAAD,CANa,CAAjB,CASA,GAAMa,CAAAA,KAAK,CAAG,0CAAuBT,YAAvB,CAAd,CAEA,GAAMU,CAAAA,WAAW,CAAG,kBAAeV,YAAf,CAApB,CACA,GAAMW,CAAAA,cAAc,CAAG,kBAAeX,YAAf,CAAvB,CAEA,GAAMY,CAAAA,gBAAgB,CAAGR,eAAMS,WAAN,CAAkB,UAAM,CAC7C,GAAIhB,IAA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AAsBZ,QAAQ,CAARA,QAAtB,CAAgCb,UAAU,CAAVA,UAAhC,CAAD,CAAJ,CACH,CAFD,IAEO,CACHU,IAAI,CAAC,CAAEE,KAAK,CAAEa,CAAT,CAAYZ,QAAQ,CAARA,QAAZ,CAAsBb,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAnBY,CAoBb,CAACe,IAAD,CAAOL,IAAP,CAAaO,EAAb,CApBa,CAAjB,CAuBA,MAAO,CACHP,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHS,QAAQ,CAARA,QAHG,CAIH9B,eAAe,CAAfA,eAJG,CAKHgC,cAAc,CAAE,gCAAMpD,CAAAA,WAAW,CAACW,OAAlB,EALb,CAAP,CAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const direction =\n handlerOffsetX.value / Math.abs(handlerOffsetX.value);\n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffsetX.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffsetX.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(\n finalOffset,\n onFinished\n );\n } else {\n handlerOffsetX.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
1
+ {"version":3,"sources":["useCarouselController.tsx"],"names":["useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","React","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","round","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","convertToSharedIndex","runOnJS","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","Easing","easeOutQuart","dealWithAnimation","next","opts","count","animated","nextPage","prev","prevPage","to","isPositiveZero","Object","is","isNegativeZero","direction","sign","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"6GAAA,qDAEA,uCACA,8DAUA,6DACA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AAEE,KAAK,CAAEkB,CAAT,CAAYjB,QAAQ,CAARA,QAAZ,CAAsBb,UAAU,CAAVA,UAAtB,CAAD,CAAJ,CACH,CACJ,CAnBY,CAoBb,CAACe,IAAD,CAAOL,IAAP,CAAaO,EAAb,CApBa,CAAjB,CAuBA,MAAO,CACHP,IAAI,CAAJA,IADG,CAEHK,IAAI,CAAJA,IAFG,CAGHc,QAAQ,CAARA,QAHG,CAIHnC,eAAe,CAAfA,eAJG,CAKHqC,cAAc,CAAE,gCAAMzD,CAAAA,WAAW,CAACW,OAAlB,EALb,CAAP,CAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const isPositiveZero = Object.is(handlerOffsetX.value, +0);\n const isNegativeZero = Object.is(handlerOffsetX.value, -0);\n const direction = isPositiveZero\n ? 1\n : isNegativeZero\n ? -1\n : Math.sign(handlerOffsetX.value); \n \n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffsetX.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffsetX.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(\n finalOffset,\n onFinished\n );\n } else {\n handlerOffsetX.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
@@ -147,7 +147,9 @@ export function useCarouselController(options) {
147
147
  if (!canSliding()) return;
148
148
  onScrollBegin === null || onScrollBegin === void 0 ? void 0 : onScrollBegin(); // direction -> 1 | -1
149
149
 
150
- const direction = handlerOffsetX.value / Math.abs(handlerOffsetX.value); // target offset
150
+ const isPositiveZero = Object.is(handlerOffsetX.value, +0);
151
+ const isNegativeZero = Object.is(handlerOffsetX.value, -0);
152
+ const direction = isPositiveZero ? 1 : isNegativeZero ? -1 : Math.sign(handlerOffsetX.value); // target offset
151
153
 
152
154
  const offset = i * size * direction; // page width size * page count
153
155
 
@@ -1 +1 @@
1
- {"version":3,"sources":["useCarouselController.tsx"],"names":["React","useRef","Easing","runOnJS","useAnimatedReaction","useSharedValue","dealWithAnimation","convertToSharedIndex","round","useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","easeOutQuart","next","opts","count","animated","nextPage","prev","prevPage","to","direction","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,MAAhB,QAA8B,OAA9B;AAEA,SAASC,MAAT,QAAuB,cAAvB;AACA,SACIC,OADJ,EAEIC,mBAFJ,EAGIC,cAHJ,QAIO,yBAJP;AAUA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,oBAAT,QAAqC,mCAArC;AACA,SAASC,KAAT,QAAsB,cAAtB;AAuBA,OAAO,SAASC,qBAAT,CAA+BC,OAA/B,EAAoE;AACvE,QAAM;AACFC,IAAAA,IADE;AAEFC,IAAAA,IAFE;AAGFC,IAAAA,IAHE;AAIFC,IAAAA,cAJE;AAKFC,IAAAA,aALE;AAMFC,IAAAA,YAAY,GAAG,CANb;AAOFC,IAAAA,QAPE;AAQFC,IAAAA;AARE,MASFR,OATJ;AAWA,QAAMS,QAAQ,GAAGnB,KAAK,CAACoB,OAAN,CACb,OAAO;AACHC,IAAAA,MAAM,EAAET,IAAI,CAACS,MADV;AAEHC,IAAAA,OAAO,EAAE,CAACV,IAAI,CAACS,MAFZ;AAGHE,IAAAA,cAAc,EAAEX,IAAI,CAACS;AAHlB,GAAP,CADa,EAMb,CAACT,IAAD,CANa,CAAjB;AASA,QAAMY,KAAK,GAAGnB,cAAc,CAASW,YAAT,CAA5B,CArBuE,CAsBvE;;AACA,QAAMS,WAAW,GAAGxB,MAAM,CAASe,YAAT,CAA1B;AACA,QAAMU,cAAc,GAAGzB,MAAM,CAASe,YAAT,CAA7B;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IAAAA,eAJG;AAKH8B,IAAAA,cAAc,EAAE,MAAM/C,WAAW,CAACU;AAL/B,GAAP;AAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const direction =\n handlerOffsetX.value / Math.abs(handlerOffsetX.value);\n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffsetX.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffsetX.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(\n finalOffset,\n onFinished\n );\n } else {\n handlerOffsetX.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
1
+ {"version":3,"sources":["useCarouselController.tsx"],"names":["React","useRef","Easing","runOnJS","useAnimatedReaction","useSharedValue","dealWithAnimation","convertToSharedIndex","round","useCarouselController","options","size","data","loop","handlerOffsetX","withAnimation","defaultIndex","duration","autoFillData","dataInfo","useMemo","length","disable","originalLength","index","sharedIndex","sharedPreIndex","currentFixedPage","useCallback","Math","value","fixed","abs","setSharedIndex","newSharedIndex","current","handlerOffsetXValue","toInt","isPositive","i","newSharedIndexValue","rawDataLength","getCurrentIndex","canSliding","onScrollEnd","onScrollBegin","scrollWithTiming","toValue","onFinished","callback","isFinished","defaultWithAnimation","type","config","easing","easeOutQuart","next","opts","count","animated","nextPage","prev","prevPage","to","isPositiveZero","Object","is","isNegativeZero","direction","sign","offset","totalSize","isCloseToNextLoop","finalOffset","floor","scrollTo","n","getSharedIndex"],"mappings":"AAAA,OAAOA,KAAP,IAAgBC,MAAhB,QAA8B,OAA9B;AAEA,SAASC,MAAT,QAAuB,cAAvB;AACA,SACIC,OADJ,EAEIC,mBAFJ,EAGIC,cAHJ,QAIO,yBAJP;AAUA,SAASC,iBAAT,QAAkC,4BAAlC;AACA,SAASC,oBAAT,QAAqC,mCAArC;AACA,SAASC,KAAT,QAAsB,cAAtB;AAuBA,OAAO,SAASC,qBAAT,CAA+BC,OAA/B,EAAoE;AACvE,QAAM;AACFC,IAAAA,IADE;AAEFC,IAAAA,IAFE;AAGFC,IAAAA,IAHE;AAIFC,IAAAA,cAJE;AAKFC,IAAAA,aAL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yBA,CAAC,GAAG,CAAC,CAAlC,EAAqC;AACjCwB,MAAAA,EAAE,CAAC;AAAExB,QAAAA,CAAF;AAAKoB,QAAAA,QAAL;AAAeX,QAAAA;AAAf,OAAD,CAAF;AACA;AACH;;AAED,QAAI,CAACU,KAAL,EAAY;AACR;AACH;;AAED,UAAMkB,CAAC,GAAG/C,IAAI,CAACrB,KAAL,CAAWkD,KAAX,CAAV;;AAEA,QAAIkB,CAAC,GAAG,CAAR,EAAW;AACPf,MAAAA,IAAI,CAAC;AAAEH,QAAAA,KAAK,EAAE7B,IAAI,CAACG,GAAL,CAAS4C,CAAT,CAAT;AAAsBjB,QAAAA,QAAtB;AAAgCX,QAAAA;AAAhC,OAAD,CAAJ;AACH,KAFD,MAEO;AACHQ,MAAAA,IAAI,CAAC;AAAEE,QAAAA,KAAK,EAAEkB,CAAT;AAAYjB,QAAAA,QAAZ;AAAsBX,QAAAA;AAAtB,OAAD,CAAJ;AACH;AACJ,GAnBY,EAoBb,CAACa,IAAD,EAAOL,IAAP,EAAaO,EAAb,CApBa,CAAjB;AAuBA,SAAO;AACHP,IAAAA,IADG;AAEHK,IAAAA,IAFG;AAGHc,IAAAA,QAHG;AAIHjC,IAAAA,eAJG;AAKHmC,IAAAA,cAAc,EAAE,MAAMpD,WAAW,CAACU;AAL/B,GAAP;AAOH","sourcesContent":["import React, { useRef } from 'react';\nimport type Animated from 'react-native-reanimated';\nimport { Easing } from '../constants';\nimport {\n runOnJS,\n useAnimatedReaction,\n useSharedValue,\n} from 'react-native-reanimated';\nimport type {\n TCarouselActionOptions,\n TCarouselProps,\n WithTimingAnimation,\n} from '../types';\nimport { dealWithAnimation } from '../utils/dealWithAnimation';\nimport { convertToSharedIndex } from '../utils/computedWithAutoFillData';\nimport { round } from '../utils/log';\n\ninterface IOpts {\n loop: boolean;\n size: number;\n data: TCarouselProps['data'];\n autoFillData: TCarouselProps['autoFillData'];\n handlerOffsetX: Animated.SharedValue<number>;\n withAnimation?: TCarouselProps['withAnimation'];\n duration?: number;\n defaultIndex?: number;\n onScrollBegin?: () => void;\n onScrollEnd?: () => void;\n}\n\nexport interface ICarouselController {\n getSharedIndex: () => number;\n prev: (opts?: TCarouselActionOptions) => void;\n next: (opts?: TCarouselActionOptions) => void;\n getCurrentIndex: () => number;\n scrollTo: (opts?: TCarouselActionOptions) => void;\n}\n\nexport function useCarouselController(options: IOpts): ICarouselController {\n const {\n size,\n data,\n loop,\n handlerOffsetX,\n withAnimation,\n defaultIndex = 0,\n duration,\n autoFillData,\n } = options;\n\n const dataInfo = React.useMemo(\n () => ({\n length: data.length,\n disable: !data.length,\n originalLength: data.length,\n }),\n [data]\n );\n\n const index = useSharedValue<number>(defaultIndex);\n // The Index displayed to the user\n const sharedIndex = useRef<number>(defaultIndex);\n const sharedPreIndex = useRef<number>(defaultIndex);\n\n const currentFixedPage = React.useCallback(() => {\n if (loop) {\n return -Math.round(handlerOffsetX.value / size);\n }\n\n const fixed = (handlerOffsetX.value / size) % dataInfo.length;\n return Math.round(\n handlerOffsetX.value <= 0\n ? Math.abs(fixed)\n : Math.abs(fixed > 0 ? dataInfo.length - fixed : 0)\n );\n }, [handlerOffsetX, dataInfo, size, loop]);\n\n function setSharedIndex(newSharedIndex: number) {\n sharedIndex.current = newSharedIndex;\n }\n\n useAnimatedReaction(\n () => {\n const handlerOffsetXValue = handlerOffsetX.value;\n const toInt = round(handlerOffsetXValue / size) % dataInfo.length;\n const isPositive = handlerOffsetXValue <= 0;\n const i = isPositive\n ? Math.abs(toInt)\n : Math.abs(toInt > 0 ? dataInfo.length - toInt : 0);\n\n const newSharedIndexValue = convertToSharedIndex({\n loop,\n rawDataLength: dataInfo.originalLength,\n autoFillData: autoFillData!,\n index: i,\n });\n\n return {\n i,\n newSharedIndexValue,\n };\n },\n ({ i, newSharedIndexValue }) => {\n index.value = i;\n runOnJS(setSharedIndex)(newSharedIndexValue);\n },\n [\n sharedPreIndex,\n sharedIndex,\n size,\n dataInfo,\n index,\n loop,\n autoFillData,\n handlerOffsetX,\n ]\n );\n\n const getCurrentIndex = React.useCallback(() => {\n return index.value;\n }, [index]);\n\n const canSliding = React.useCallback(() => {\n return !dataInfo.disable;\n }, [dataInfo]);\n\n const onScrollEnd = React.useCallback(() => {\n options.onScrollEnd?.();\n }, [options]);\n\n const onScrollBegin = React.useCallback(() => {\n options.onScrollBegin?.();\n }, [options]);\n\n const scrollWithTiming = React.useCallback(\n (toValue: number, onFinished?: () => void) => {\n 'worklet';\n const callback = (isFinished: boolean) => {\n 'worklet';\n if (isFinished) {\n runOnJS(onScrollEnd)();\n onFinished && runOnJS(onFinished)();\n }\n };\n\n const defaultWithAnimation: WithTimingAnimation = {\n type: 'timing',\n config: { duration, easing: Easing.easeOutQuart },\n };\n\n return dealWithAnimation(withAnimation ?? defaultWithAnimation)(\n toValue,\n callback\n );\n },\n [duration, withAnimation, onScrollEnd]\n );\n\n const next = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n 'worklet';\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value >= dataInfo.length - 1))\n return;\n\n onScrollBegin?.();\n\n const nextPage = currentFixedPage() + count;\n index.value = nextPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -nextPage * size,\n onFinished\n ) as any;\n } else {\n handlerOffsetX.value = -nextPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n dataInfo,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const prev = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { count = 1, animated = true, onFinished } = opts;\n if (!canSliding() || (!loop && index.value <= 0)) return;\n\n onScrollBegin?.();\n\n const prevPage = currentFixedPage() - count;\n index.value = prevPage;\n\n if (animated) {\n handlerOffsetX.value = scrollWithTiming(\n -prevPage * size,\n onFinished\n );\n } else {\n handlerOffsetX.value = -prevPage * size;\n onFinished?.();\n }\n },\n [\n canSliding,\n loop,\n index,\n onScrollBegin,\n handlerOffsetX,\n size,\n scrollWithTiming,\n currentFixedPage,\n ]\n );\n\n const to = React.useCallback(\n (opts: { i: number; animated: boolean; onFinished?: () => void }) => {\n const { i, animated = false, onFinished } = opts;\n if (i === index.value) return;\n if (!canSliding()) return;\n\n onScrollBegin?.();\n // direction -> 1 | -1\n const isPositiveZero = Object.is(handlerOffsetX.value, +0);\n const isNegativeZero = Object.is(handlerOffsetX.value, -0);\n const direction = isPositiveZero\n ? 1\n : isNegativeZero\n ? -1\n : Math.sign(handlerOffsetX.value); \n \n // target offset\n const offset = i * size * direction;\n // page width size * page count\n const totalSize = dataInfo.length * size;\n\n let isCloseToNextLoop = false;\n\n if (loop) {\n isCloseToNextLoop =\n Math.abs(handlerOffsetX.value % totalSize) / totalSize >=\n 0.5;\n }\n\n const finalOffset =\n (Math.floor(Math.abs(handlerOffsetX.value / totalSize)) +\n (isCloseToNextLoop ? 1 : 0)) *\n totalSize *\n direction +\n offset;\n\n if (animated) {\n index.value = i;\n handlerOffsetX.value = scrollWithTiming(\n finalOffset,\n onFinished\n );\n } else {\n handlerOffsetX.value = finalOffset;\n index.value = i;\n onFinished?.();\n }\n },\n [\n index,\n canSliding,\n onScrollBegin,\n handlerOffsetX,\n size,\n dataInfo.length,\n loop,\n scrollWithTiming,\n ]\n );\n\n const scrollTo = React.useCallback(\n (opts: TCarouselActionOptions = {}) => {\n const { index: i, count, animated = false, onFinished } = opts;\n if (typeof i === 'number' && i > -1) {\n to({ i, animated, onFinished });\n return;\n }\n\n if (!count) {\n return;\n }\n\n const n = Math.round(count);\n\n if (n < 0) {\n prev({ count: Math.abs(n), animated, onFinished });\n } else {\n next({ count: n, animated, onFinished });\n }\n },\n [prev, next, to]\n );\n\n return {\n next,\n prev,\n scrollTo,\n getCurrentIndex,\n getSharedIndex: () => sharedIndex.current,\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-reanimated-carousel",
3
- "version": "3.0.4",
3
+ "version": "3.0.5",
4
4
  "description": "Simple carousel component.fully implemented using Reanimated 2.Infinitely scrolling, very smooth.",
5
5
  "main": "lib/commonjs/index",
6
6
  "react-native": "src/index.tsx",
package/src/.DS_Store ADDED
Binary file
@@ -231,8 +231,14 @@ export function useCarouselController(options: IOpts): ICarouselController {
231
231
 
232
232
  onScrollBegin?.();
233
233
  // direction -> 1 | -1
234
- const direction =
235
- handlerOffsetX.value / Math.abs(handlerOffsetX.value);
234
+ const isPositiveZero = Object.is(handlerOffsetX.value, +0);
235
+ const isNegativeZero = Object.is(handlerOffsetX.value, -0);
236
+ const direction = isPositiveZero
237
+ ? 1
238
+ : isNegativeZero
239
+ ? -1
240
+ : Math.sign(handlerOffsetX.value);
241
+
236
242
  // target offset
237
243
  const offset = i * size * direction;
238
244
  // page width size * page count