react-native-reanimated-carousel 0.4.0 → 0.4.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. package/README.md +15 -14
  2. package/lib/commonjs/Carousel.js +86 -46
  3. package/lib/commonjs/Carousel.js.map +1 -1
  4. package/lib/commonjs/{useLoop.js → useAutoPlay.js} +7 -6
  5. package/lib/commonjs/useAutoPlay.js.map +1 -0
  6. package/lib/commonjs/useCarouselController.js +20 -22
  7. package/lib/commonjs/useCarouselController.js.map +1 -1
  8. package/lib/commonjs/useLock.js +41 -0
  9. package/lib/commonjs/useLock.js.map +1 -0
  10. package/lib/module/Carousel.js +84 -42
  11. package/lib/module/Carousel.js.map +1 -1
  12. package/lib/module/{useLoop.js → useAutoPlay.js} +6 -5
  13. package/lib/module/useAutoPlay.js.map +1 -0
  14. package/lib/module/useCarouselController.js +21 -21
  15. package/lib/module/useCarouselController.js.map +1 -1
  16. package/lib/module/useLock.js +34 -0
  17. package/lib/module/useLock.js.map +1 -0
  18. package/lib/typescript/Carousel.d.ts +5 -1
  19. package/lib/typescript/{useLoop.d.ts → useAutoPlay.d.ts} +3 -1
  20. package/lib/typescript/useCarouselController.d.ts +4 -0
  21. package/lib/typescript/useLock.d.ts +9 -0
  22. package/package.json +1 -1
  23. package/src/Carousel.tsx +91 -60
  24. package/src/{useLoop.ts → useAutoPlay.ts} +12 -3
  25. package/src/useCarouselController.tsx +44 -21
  26. package/src/useLock.ts +31 -0
  27. package/lib/commonjs/fillNum.js +0 -30
  28. package/lib/commonjs/fillNum.js.map +0 -1
  29. package/lib/commonjs/useLoop.js.map +0 -1
  30. package/lib/module/fillNum.js +0 -23
  31. package/lib/module/fillNum.js.map +0 -1
  32. package/lib/module/useLoop.js.map +0 -1
  33. package/lib/typescript/fillNum.d.ts +0 -4
  34. package/src/fillNum.ts +0 -17
package/src/Carousel.tsx CHANGED
@@ -13,28 +13,16 @@ import Animated, {
13
13
  withTiming,
14
14
  } from 'react-native-reanimated';
15
15
  import { CarouselItem } from './CarouselItem';
16
- import { fillNum } from './fillNum';
17
16
  import type { TMode } from './layouts';
18
17
  import { ParallaxLayout } from './layouts/index';
19
18
  import { useCarouselController } from './useCarouselController';
20
19
  import { useComputedAnim } from './useComputedAnim';
21
- import { useLoop } from './useLoop';
20
+ import { useAutoPlay } from './useAutoPlay';
22
21
  import { useComputedIndex } from './useComputedIndex';
22
+ import { useLockController } from './useLock';
23
23
 
24
- export const _withTiming = (
25
- num: number,
26
- callback?: (isFinished: boolean) => void
27
- ) => {
28
- 'worklet';
29
- return withTiming(
30
- num,
31
- {
32
- duration: 250,
33
- },
34
- (isFinished) => {
35
- !!callback && runOnJS(callback)(isFinished);
36
- }
37
- );
24
+ const defaultTimingConfig: Animated.WithTimingConfig = {
25
+ duration: 250,
38
26
  };
39
27
 
40
28
  export interface ICarouselProps<T extends unknown> {
@@ -98,6 +86,10 @@ export interface ICarouselProps<T extends unknown> {
98
86
  * Callback fired when navigating to an item
99
87
  */
100
88
  onSnapToItem?: (index: number) => void;
89
+ /**
90
+ * Timing config of translation animated
91
+ */
92
+ timingConfig?: Animated.WithTimingConfig;
101
93
  }
102
94
 
103
95
  export interface ICarouselInstance {
@@ -133,25 +125,38 @@ function Carousel<T extends unknown = any>(
133
125
  parallaxScrollingScale,
134
126
  onSnapToItem,
135
127
  style,
128
+ timingConfig = defaultTimingConfig,
136
129
  } = props;
130
+ const lockController = useLockController();
137
131
  const handlerOffsetX = useSharedValue<number>(0);
138
132
  const data = React.useMemo<T[]>(() => {
133
+ if (!loop) return _data;
134
+
139
135
  if (_data.length === 1) {
140
136
  return [_data[0], _data[0], _data[0]];
141
137
  }
138
+
142
139
  if (_data.length === 2) {
143
140
  return [_data[0], _data[1], _data[0], _data[1]];
144
141
  }
142
+
145
143
  return _data;
146
- }, [_data]);
144
+ }, [_data, loop]);
147
145
 
148
146
  const computedAnimResult = useComputedAnim(width, data.length);
149
- const carouselController = useCarouselController({ width, handlerOffsetX });
150
- useLoop({
147
+ const carouselController = useCarouselController({
148
+ width,
149
+ handlerOffsetX,
150
+ lockController,
151
+ timingConfig,
152
+ disable: !data.length,
153
+ });
154
+ useAutoPlay({
151
155
  autoPlay,
152
156
  autoPlayInterval,
153
157
  autoPlayReverse,
154
158
  carouselController,
159
+ lockController,
155
160
  });
156
161
  const { index, computedIndex } = useComputedIndex({
157
162
  length: data.length,
@@ -166,12 +171,24 @@ function Carousel<T extends unknown = any>(
166
171
 
167
172
  useAnimatedReaction(
168
173
  () => index.value,
169
- (i) => onSnapToItem && runOnJS(onSnapToItem)(i),
170
- [onSnapToItem]
174
+ (i) => {
175
+ if (loop) {
176
+ switch (_data.length) {
177
+ case 1:
178
+ i = 0;
179
+ break;
180
+ case 2:
181
+ i = i % 2;
182
+ break;
183
+ }
184
+ onSnapToItem && runOnJS(onSnapToItem)(i);
185
+ }
186
+ },
187
+ [onSnapToItem, loop, _data]
171
188
  );
172
189
 
173
190
  const callComputedIndex = React.useCallback(
174
- (isFinished: boolean) => isFinished && computedIndex?.(),
191
+ () => computedIndex?.(),
175
192
  [computedIndex]
176
193
  );
177
194
 
@@ -191,77 +208,91 @@ function Carousel<T extends unknown = any>(
191
208
  useAnimatedGestureHandler<PanGestureHandlerGestureEvent>(
192
209
  {
193
210
  onStart: (_, ctx: any) => {
211
+ if (lockController.isLock()) return;
194
212
  ctx.startContentOffsetX = handlerOffsetX.value;
213
+ ctx.currentContentOffsetX = handlerOffsetX.value;
214
+ ctx.start = true;
195
215
  },
196
216
  onActive: (e, ctx: any) => {
217
+ if (lockController.isLock() || !ctx.start) return;
218
+ /**
219
+ * `onActive` and `onEnd` return different values of translationX!So that creates a bias!TAT
220
+ * */
221
+ ctx.translationX = e.translationX;
197
222
  if (loop) {
198
223
  handlerOffsetX.value =
199
- ctx.startContentOffsetX +
200
- Math.round(e.translationX);
224
+ ctx.currentContentOffsetX + e.translationX;
201
225
  return;
202
226
  }
203
227
  handlerOffsetX.value = Math.max(
204
- Math.min(
205
- ctx.startContentOffsetX +
206
- Math.round(e.translationX),
207
- 0
208
- ),
228
+ Math.min(ctx.currentContentOffsetX + e.translationX, 0),
209
229
  -(data.length - 1) * width
210
230
  );
211
231
  },
212
- onEnd: (e) => {
213
- const intTranslationX = Math.round(e.translationX);
214
- const sub = Math.abs(intTranslationX);
215
-
232
+ onEnd: (e, ctx: any) => {
233
+ if (lockController.isLock() || !ctx.start) return;
234
+ const translationX = ctx.translationX;
216
235
  function _withTimingCallback(num: number) {
217
- return _withTiming(num, callComputedIndex);
236
+ return withTiming(num, timingConfig, (isFinished) => {
237
+ if (isFinished) {
238
+ ctx.start = false;
239
+ lockController.unLock();
240
+ runOnJS(callComputedIndex)();
241
+ }
242
+ });
218
243
  }
219
244
 
220
- if (intTranslationX > 0) {
245
+ if (translationX > 0) {
246
+ /**
247
+ * If not loop no , longer scroll when sliding to the start.
248
+ * */
221
249
  if (!loop && handlerOffsetX.value >= 0) {
222
250
  return;
223
251
  }
224
-
225
- if (sub > width / 2) {
252
+ lockController.lock();
253
+ if (
254
+ Math.abs(translationX) + Math.abs(e.velocityX) >
255
+ width / 2
256
+ ) {
226
257
  handlerOffsetX.value = _withTimingCallback(
227
- fillNum(
228
- width,
229
- handlerOffsetX.value + (width - sub)
230
- )
258
+ handlerOffsetX.value + width - translationX
231
259
  );
232
260
  } else {
233
261
  handlerOffsetX.value = _withTimingCallback(
234
- fillNum(width, handlerOffsetX.value - sub)
262
+ handlerOffsetX.value - translationX
235
263
  );
236
264
  }
237
265
  return;
238
266
  }
239
267
 
240
- if (intTranslationX < 0) {
268
+ if (translationX < 0) {
269
+ /**
270
+ * If not loop , no longer scroll when sliding to the end.
271
+ * */
241
272
  if (
242
273
  !loop &&
243
274
  handlerOffsetX.value <= -(data.length - 1) * width
244
275
  ) {
245
276
  return;
246
277
  }
247
-
248
- if (sub > width / 2) {
278
+ lockController.lock();
279
+ if (
280
+ Math.abs(translationX) + Math.abs(e.velocityX) >
281
+ width / 2
282
+ ) {
249
283
  handlerOffsetX.value = _withTimingCallback(
250
- fillNum(
251
- width,
252
- handlerOffsetX.value - (width - sub)
253
- )
284
+ handlerOffsetX.value - width - translationX
254
285
  );
255
286
  } else {
256
287
  handlerOffsetX.value = _withTimingCallback(
257
- fillNum(width, handlerOffsetX.value + sub)
288
+ handlerOffsetX.value - translationX
258
289
  );
259
290
  }
260
291
  return;
261
292
  }
262
293
  },
263
294
  },
264
- [loop, data]
295
+ [loop, data, lockController]
265
296
  );
266
297
 
267
298
  React.useImperativeHandle(ref, () => {
@@ -275,29 +306,29 @@ function Carousel<T extends unknown = any>(
275
306
  const Layouts = React.useMemo<React.FC<{ index: number }>>(() => {
276
307
  switch (mode) {
277
308
  case 'parallax':
278
- return ({ index, children }) => (
309
+ return ({ index: i, children }) => (
279
310
  <ParallaxLayout
280
311
  parallaxScrollingOffset={parallaxScrollingOffset}
281
312
  parallaxScrollingScale={parallaxScrollingScale}
282
313
  computedAnimResult={computedAnimResult}
283
314
  width={width}
284
315
  handlerOffsetX={offsetX}
285
- index={index}
286
- key={index}
316
+ index={i}
317
+ key={i}
287
318
  loop={loop}
288
319
  >
289
320
  {children}
290
321
  </ParallaxLayout>
291
322
  );
292
323
  default:
293
- return ({ index, children }) => (
324
+ return ({ index: i, children }) => (
294
325
  <CarouselItem
295
326
  computedAnimResult={computedAnimResult}
296
327
  width={width}
297
328
  height={height}
298
329
  handlerOffsetX={offsetX}
299
- index={index}
300
- key={index}
330
+ index={i}
331
+ key={i}
301
332
  loop={loop}
302
333
  >
303
334
  {children}
@@ -329,10 +360,10 @@ function Carousel<T extends unknown = any>(
329
360
  style,
330
361
  ]}
331
362
  >
332
- {data.map((item, index) => {
363
+ {data.map((item, i) => {
333
364
  return (
334
- <Layouts index={index} key={index}>
335
- {renderItem(item, index)}
365
+ <Layouts index={i} key={i}>
366
+ {renderItem(item, i)}
336
367
  </Layouts>
337
368
  );
338
369
  })}
@@ -1,24 +1,27 @@
1
1
  import * as React from 'react';
2
2
  import type { ICarouselController } from './useCarouselController';
3
+ import type { ILockController } from './useLock';
3
4
 
4
- export function useLoop(opts: {
5
+ export function useAutoPlay(opts: {
5
6
  autoPlay?: boolean;
6
7
  autoPlayInterval?: number;
7
8
  autoPlayReverse?: boolean;
8
9
  carouselController: ICarouselController;
10
+ lockController: ILockController;
9
11
  }) {
10
12
  const {
11
13
  autoPlay = false,
12
14
  autoPlayReverse = false,
13
15
  autoPlayInterval = 1000,
14
16
  carouselController,
17
+ lockController,
15
18
  } = opts;
16
19
  const timer = React.useRef<NodeJS.Timer>();
17
20
  React.useEffect(() => {
18
21
  if (timer.current) {
19
22
  clearInterval(timer.current);
20
23
  }
21
- if (autoPlay) {
24
+ if (autoPlay && !lockController.isLock()) {
22
25
  timer.current = setInterval(() => {
23
26
  autoPlayReverse
24
27
  ? carouselController.prev()
@@ -28,5 +31,11 @@ export function useLoop(opts: {
28
31
  return () => {
29
32
  !!timer.current && clearInterval(timer.current);
30
33
  };
31
- }, [autoPlay, autoPlayReverse, autoPlayInterval, carouselController]);
34
+ }, [
35
+ autoPlay,
36
+ autoPlayReverse,
37
+ autoPlayInterval,
38
+ carouselController,
39
+ lockController,
40
+ ]);
32
41
  }
@@ -1,11 +1,14 @@
1
1
  import React from 'react';
2
- import { _withTiming } from './Carousel';
3
2
  import type Animated from 'react-native-reanimated';
4
- import { useSharedValue } from 'react-native-reanimated';
3
+ import { runOnJS, withTiming } from 'react-native-reanimated';
4
+ import type { ILockController } from './useLock';
5
5
 
6
6
  interface IOpts {
7
7
  width: number;
8
8
  handlerOffsetX: Animated.SharedValue<number>;
9
+ lockController: ILockController;
10
+ timingConfig: Animated.WithTimingConfig;
11
+ disable?: boolean;
9
12
  }
10
13
 
11
14
  export interface ICarouselController {
@@ -14,49 +17,69 @@ export interface ICarouselController {
14
17
  }
15
18
 
16
19
  export function useCarouselController(opts: IOpts): ICarouselController {
17
- const lock = useSharedValue<boolean>(false);
18
- const { width, handlerOffsetX } = opts;
20
+ const {
21
+ width,
22
+ handlerOffsetX,
23
+ timingConfig,
24
+ lockController,
25
+ disable = false,
26
+ } = opts;
19
27
 
20
28
  const closeLock = React.useCallback(
21
29
  (isFinished: boolean) => {
22
30
  if (isFinished) {
23
- lock.value = false;
31
+ lockController.unLock();
24
32
  }
25
33
  },
26
- [lock]
34
+ [lockController]
27
35
  );
28
- const openLock = React.useCallback(() => {
29
- lock.value = true;
30
- }, [lock]);
31
36
 
32
37
  const next = React.useCallback(
33
38
  (callback?: (isFinished: boolean) => void) => {
34
- if (lock.value) return;
35
- openLock();
36
- handlerOffsetX.value = _withTiming(
39
+ if (disable) return;
40
+ if (lockController.isLock()) return;
41
+ lockController.lock();
42
+ handlerOffsetX.value = withTiming(
37
43
  handlerOffsetX.value - width,
44
+ timingConfig,
38
45
  (isFinished: boolean) => {
39
- callback?.(isFinished);
40
- closeLock(isFinished);
46
+ !!callback && runOnJS(callback)(isFinished);
47
+ runOnJS(closeLock)(isFinished);
41
48
  }
42
49
  );
43
50
  },
44
- [width, openLock, closeLock, lock, handlerOffsetX]
51
+ [
52
+ width,
53
+ lockController,
54
+ timingConfig,
55
+ closeLock,
56
+ handlerOffsetX,
57
+ disable,
58
+ ]
45
59
  );
46
60
 
47
61
  const prev = React.useCallback(
48
62
  (callback?: (isFinished: boolean) => void) => {
49
- if (lock.value) return;
50
- openLock();
51
- handlerOffsetX.value = _withTiming(
63
+ if (disable) return;
64
+ if (lockController.isLock()) return;
65
+ lockController.lock();
66
+ handlerOffsetX.value = withTiming(
52
67
  handlerOffsetX.value + width,
68
+ timingConfig,
53
69
  (isFinished: boolean) => {
54
- callback?.(isFinished);
55
- closeLock(isFinished);
70
+ !!callback && runOnJS(callback)(isFinished);
71
+ runOnJS(closeLock)(isFinished);
56
72
  }
57
73
  );
58
74
  },
59
- [width, openLock, closeLock, lock, handlerOffsetX]
75
+ [
76
+ width,
77
+ lockController,
78
+ timingConfig,
79
+ closeLock,
80
+ handlerOffsetX,
81
+ disable,
82
+ ]
60
83
  );
61
84
 
62
85
  return {
package/src/useLock.ts ADDED
@@ -0,0 +1,31 @@
1
+ import { useSharedValue } from 'react-native-reanimated';
2
+ export interface ILockController {
3
+ lock(): void;
4
+ unLock(): void;
5
+ isLock(): boolean;
6
+ }
7
+
8
+ /**
9
+ * Cannot operate while animation is locking
10
+ */
11
+ export function useLockController(): ILockController {
12
+ // This value is true if the animation is executing
13
+ const _lock = useSharedValue<boolean>(false);
14
+ function lock() {
15
+ 'worklet';
16
+ _lock.value = true;
17
+ }
18
+ function unLock() {
19
+ 'worklet';
20
+ _lock.value = false;
21
+ }
22
+ function isLock() {
23
+ 'worklet';
24
+ return _lock.value;
25
+ }
26
+ return {
27
+ lock,
28
+ unLock,
29
+ isLock,
30
+ };
31
+ }
@@ -1,30 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.fillNum = fillNum;
7
-
8
- /**
9
- * This is used to supplement the accuracy of Javascript calculations
10
- */
11
- function fillNum(width, num) {
12
- 'worklet';
13
-
14
- const remainder = num % width;
15
-
16
- if (remainder !== 0) {
17
- const sub = width - Math.abs(remainder);
18
-
19
- if (num < 0) {
20
- return num - sub;
21
- }
22
-
23
- if (num > 0) {
24
- return num + sub;
25
- }
26
- }
27
-
28
- return num;
29
- }
30
- //# sourceMappingURL=fillNum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["fillNum.ts"],"names":["fillNum","width","num","remainder","sub","Math","abs"],"mappings":";;;;;;;AAAA;AACA;AACA;AACO,SAASA,OAAT,CAAiBC,KAAjB,EAAgCC,GAAhC,EAA6C;AAChD;;AACA,QAAMC,SAAS,GAAGD,GAAG,GAAGD,KAAxB;;AACA,MAAIE,SAAS,KAAK,CAAlB,EAAqB;AACjB,UAAMC,GAAG,GAAGH,KAAK,GAAGI,IAAI,CAACC,GAAL,CAASH,SAAT,CAApB;;AACA,QAAID,GAAG,GAAG,CAAV,EAAa;AACT,aAAOA,GAAG,GAAGE,GAAb;AACH;;AACD,QAAIF,GAAG,GAAG,CAAV,EAAa;AACT,aAAOA,GAAG,GAAGE,GAAb;AACH;AACJ;;AACD,SAAOF,GAAP;AACH","sourcesContent":["/**\n * This is used to supplement the accuracy of Javascript calculations\n */\nexport function fillNum(width: number, num: number) {\n 'worklet';\n const remainder = num % width;\n if (remainder !== 0) {\n const sub = width - Math.abs(remainder);\n if (num < 0) {\n return num - sub;\n }\n if (num > 0) {\n return num + sub;\n }\n }\n return num;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useLoop.ts"],"names":["useLoop","opts","autoPlay","autoPlayReverse","autoPlayInterval","carouselController","timer","React","useRef","useEffect","current","clearInterval","setInterval","prev","next"],"mappings":";;;;;;;AAAA;;;;;;AAGO,SAASA,OAAT,CAAiBC,IAAjB,EAKJ;AACC,QAAM;AACFC,IAAAA,QAAQ,GAAG,KADT;AAEFC,IAAAA,eAAe,GAAG,KAFhB;AAGFC,IAAAA,gBAAgB,GAAG,IAHjB;AAIFC,IAAAA;AAJE,MAKFJ,IALJ;AAMA,QAAMK,KAAK,GAAGC,KAAK,CAACC,MAAN,EAAd;AACAD,EAAAA,KAAK,CAACE,SAAN,CAAgB,MAAM;AAClB,QAAIH,KAAK,CAACI,OAAV,EAAmB;AACfC,MAAAA,aAAa,CAACL,KAAK,CAACI,OAAP,CAAb;AACH;;AACD,QAAIR,QAAJ,EAAc;AACVI,MAAAA,KAAK,CAACI,OAAN,GAAgBE,WAAW,CAAC,MAAM;AAC9BT,QAAAA,eAAe,GACTE,kBAAkB,CAACQ,IAAnB,EADS,GAETR,kBAAkB,CAACS,IAAnB,EAFN;AAGH,OAJ0B,EAIxBV,gBAJwB,CAA3B;AAKH;;AACD,WAAO,MAAM;AACT,OAAC,CAACE,KAAK,CAACI,OAAR,IAAmBC,aAAa,CAACL,KAAK,CAACI,OAAP,CAAhC;AACH,KAFD;AAGH,GAdD,EAcG,CAACR,QAAD,EAAWC,eAAX,EAA4BC,gBAA5B,EAA8CC,kBAA9C,CAdH;AAeH","sourcesContent":["import * as React from 'react';\nimport type { ICarouselController } from './useCarouselController';\n\nexport function useLoop(opts: {\n autoPlay?: boolean;\n autoPlayInterval?: number;\n autoPlayReverse?: boolean;\n carouselController: ICarouselController;\n}) {\n const {\n autoPlay = false,\n autoPlayReverse = false,\n autoPlayInterval = 1000,\n carouselController,\n } = opts;\n const timer = React.useRef<NodeJS.Timer>();\n React.useEffect(() => {\n if (timer.current) {\n clearInterval(timer.current);\n }\n if (autoPlay) {\n timer.current = setInterval(() => {\n autoPlayReverse\n ? carouselController.prev()\n : carouselController.next();\n }, autoPlayInterval);\n }\n return () => {\n !!timer.current && clearInterval(timer.current);\n };\n }, [autoPlay, autoPlayReverse, autoPlayInterval, carouselController]);\n}\n"]}
@@ -1,23 +0,0 @@
1
- /**
2
- * This is used to supplement the accuracy of Javascript calculations
3
- */
4
- export function fillNum(width, num) {
5
- 'worklet';
6
-
7
- const remainder = num % width;
8
-
9
- if (remainder !== 0) {
10
- const sub = width - Math.abs(remainder);
11
-
12
- if (num < 0) {
13
- return num - sub;
14
- }
15
-
16
- if (num > 0) {
17
- return num + sub;
18
- }
19
- }
20
-
21
- return num;
22
- }
23
- //# sourceMappingURL=fillNum.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["fillNum.ts"],"names":["fillNum","width","num","remainder","sub","Math","abs"],"mappings":"AAAA;AACA;AACA;AACA,OAAO,SAASA,OAAT,CAAiBC,KAAjB,EAAgCC,GAAhC,EAA6C;AAChD;;AACA,QAAMC,SAAS,GAAGD,GAAG,GAAGD,KAAxB;;AACA,MAAIE,SAAS,KAAK,CAAlB,EAAqB;AACjB,UAAMC,GAAG,GAAGH,KAAK,GAAGI,IAAI,CAACC,GAAL,CAASH,SAAT,CAApB;;AACA,QAAID,GAAG,GAAG,CAAV,EAAa;AACT,aAAOA,GAAG,GAAGE,GAAb;AACH;;AACD,QAAIF,GAAG,GAAG,CAAV,EAAa;AACT,aAAOA,GAAG,GAAGE,GAAb;AACH;AACJ;;AACD,SAAOF,GAAP;AACH","sourcesContent":["/**\n * This is used to supplement the accuracy of Javascript calculations\n */\nexport function fillNum(width: number, num: number) {\n 'worklet';\n const remainder = num % width;\n if (remainder !== 0) {\n const sub = width - Math.abs(remainder);\n if (num < 0) {\n return num - sub;\n }\n if (num > 0) {\n return num + sub;\n }\n }\n return num;\n}\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["useLoop.ts"],"names":["React","useLoop","opts","autoPlay","autoPlayReverse","autoPlayInterval","carouselController","timer","useRef","useEffect","current","clearInterval","setInterval","prev","next"],"mappings":"AAAA,OAAO,KAAKA,KAAZ,MAAuB,OAAvB;AAGA,OAAO,SAASC,OAAT,CAAiBC,IAAjB,EAKJ;AACC,QAAM;AACFC,IAAAA,QAAQ,GAAG,KADT;AAEFC,IAAAA,eAAe,GAAG,KAFhB;AAGFC,IAAAA,gBAAgB,GAAG,IAHjB;AAIFC,IAAAA;AAJE,MAKFJ,IALJ;AAMA,QAAMK,KAAK,GAAGP,KAAK,CAACQ,MAAN,EAAd;AACAR,EAAAA,KAAK,CAACS,SAAN,CAAgB,MAAM;AAClB,QAAIF,KAAK,CAACG,OAAV,EAAmB;AACfC,MAAAA,aAAa,CAACJ,KAAK,CAACG,OAAP,CAAb;AACH;;AACD,QAAIP,QAAJ,EAAc;AACVI,MAAAA,KAAK,CAACG,OAAN,GAAgBE,WAAW,CAAC,MAAM;AAC9BR,QAAAA,eAAe,GACTE,kBAAkB,CAACO,IAAnB,EADS,GAETP,kBAAkB,CAACQ,IAAnB,EAFN;AAGH,OAJ0B,EAIxBT,gBAJwB,CAA3B;AAKH;;AACD,WAAO,MAAM;AACT,OAAC,CAACE,KAAK,CAACG,OAAR,IAAmBC,aAAa,CAACJ,KAAK,CAACG,OAAP,CAAhC;AACH,KAFD;AAGH,GAdD,EAcG,CAACP,QAAD,EAAWC,eAAX,EAA4BC,gBAA5B,EAA8CC,kBAA9C,CAdH;AAeH","sourcesContent":["import * as React from 'react';\nimport type { ICarouselController } from './useCarouselController';\n\nexport function useLoop(opts: {\n autoPlay?: boolean;\n autoPlayInterval?: number;\n autoPlayReverse?: boolean;\n carouselController: ICarouselController;\n}) {\n const {\n autoPlay = false,\n autoPlayReverse = false,\n autoPlayInterval = 1000,\n carouselController,\n } = opts;\n const timer = React.useRef<NodeJS.Timer>();\n React.useEffect(() => {\n if (timer.current) {\n clearInterval(timer.current);\n }\n if (autoPlay) {\n timer.current = setInterval(() => {\n autoPlayReverse\n ? carouselController.prev()\n : carouselController.next();\n }, autoPlayInterval);\n }\n return () => {\n !!timer.current && clearInterval(timer.current);\n };\n }, [autoPlay, autoPlayReverse, autoPlayInterval, carouselController]);\n}\n"]}
@@ -1,4 +0,0 @@
1
- /**
2
- * This is used to supplement the accuracy of Javascript calculations
3
- */
4
- export declare function fillNum(width: number, num: number): number;
package/src/fillNum.ts DELETED
@@ -1,17 +0,0 @@
1
- /**
2
- * This is used to supplement the accuracy of Javascript calculations
3
- */
4
- export function fillNum(width: number, num: number) {
5
- 'worklet';
6
- const remainder = num % width;
7
- if (remainder !== 0) {
8
- const sub = width - Math.abs(remainder);
9
- if (num < 0) {
10
- return num - sub;
11
- }
12
- if (num > 0) {
13
- return num + sub;
14
- }
15
- }
16
- return num;
17
- }