react-native-reanimated-carousel 2.2.2 → 2.2.5-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (78) hide show
  1. package/README.md +1 -1
  2. package/README.zh-CN.md +1 -1
  3. package/lib/commonjs/Carousel.js +1 -221
  4. package/lib/commonjs/Carousel.js.map +1 -1
  5. package/lib/commonjs/LazyView.js +1 -25
  6. package/lib/commonjs/LazyView.js.map +1 -1
  7. package/lib/commonjs/ScrollViewGesture.js +1 -217
  8. package/lib/commonjs/ScrollViewGesture.js.map +1 -1
  9. package/lib/commonjs/constants/index.js +1 -21
  10. package/lib/commonjs/constants/index.js.map +1 -1
  11. package/lib/commonjs/hooks/useAutoPlay.js +1 -61
  12. package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
  13. package/lib/commonjs/hooks/useCarouselController.js +1 -194
  14. package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
  15. package/lib/commonjs/hooks/useCommonVariables.js +1 -36
  16. package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
  17. package/lib/commonjs/hooks/useInitProps.js +1 -70
  18. package/lib/commonjs/hooks/useInitProps.js.map +1 -1
  19. package/lib/commonjs/hooks/useLayoutConfig.js +1 -39
  20. package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
  21. package/lib/commonjs/hooks/useOffsetX.js +1 -54
  22. package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
  23. package/lib/commonjs/hooks/useOnProgressChange.js +1 -38
  24. package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
  25. package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -37
  26. package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
  27. package/lib/commonjs/hooks/useVisibleRanges.js +1 -42
  28. package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
  29. package/lib/commonjs/index.js +1 -13
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/layouts/BaseLayout.js +1 -100
  32. package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
  33. package/lib/commonjs/layouts/ParallaxLayout.js +1 -82
  34. package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
  35. package/lib/commonjs/layouts/index.js +1 -20
  36. package/lib/commonjs/layouts/index.js.map +1 -1
  37. package/lib/commonjs/layouts/normal.js +1 -27
  38. package/lib/commonjs/layouts/normal.js.map +1 -1
  39. package/lib/commonjs/layouts/parallax.js +1 -36
  40. package/lib/commonjs/layouts/parallax.js.map +1 -1
  41. package/lib/commonjs/layouts/stack.js +1 -219
  42. package/lib/commonjs/layouts/stack.js.map +1 -1
  43. package/lib/commonjs/store/index.js +1 -14
  44. package/lib/commonjs/store/index.js.map +1 -1
  45. package/lib/commonjs/types.js +1 -5
  46. package/lib/commonjs/utils/dealWithAnimation.js +2 -0
  47. package/lib/commonjs/utils/dealWithAnimation.js.map +1 -0
  48. package/lib/commonjs/utils/log.js +1 -14
  49. package/lib/commonjs/utils/log.js.map +1 -1
  50. package/lib/module/Carousel.js +14 -10
  51. package/lib/module/Carousel.js.map +1 -1
  52. package/lib/module/ScrollViewGesture.js +46 -29
  53. package/lib/module/ScrollViewGesture.js.map +1 -1
  54. package/lib/module/hooks/useAutoPlay.js +5 -1
  55. package/lib/module/hooks/useAutoPlay.js.map +1 -1
  56. package/lib/module/hooks/useCarouselController.js +21 -7
  57. package/lib/module/hooks/useCarouselController.js.map +1 -1
  58. package/lib/module/layouts/BaseLayout.js +2 -1
  59. package/lib/module/layouts/BaseLayout.js.map +1 -1
  60. package/lib/module/layouts/stack.js.map +1 -1
  61. package/lib/module/utils/dealWithAnimation.js +17 -0
  62. package/lib/module/utils/dealWithAnimation.js.map +1 -0
  63. package/lib/typescript/Carousel.d.ts +3 -4
  64. package/lib/typescript/ScrollViewGesture.d.ts +3 -1
  65. package/lib/typescript/hooks/useCarouselController.d.ts +2 -1
  66. package/lib/typescript/layouts/BaseLayout.d.ts +2 -2
  67. package/lib/typescript/layouts/stack.d.ts +1 -1
  68. package/lib/typescript/types.d.ts +14 -2
  69. package/lib/typescript/utils/dealWithAnimation.d.ts +2 -0
  70. package/package.json +12 -2
  71. package/src/Carousel.tsx +203 -188
  72. package/src/ScrollViewGesture.tsx +70 -33
  73. package/src/hooks/useAutoPlay.ts +4 -1
  74. package/src/hooks/useCarouselController.tsx +28 -12
  75. package/src/layouts/BaseLayout.tsx +3 -3
  76. package/src/layouts/stack.ts +1 -1
  77. package/src/types.ts +22 -4
  78. package/src/utils/dealWithAnimation.ts +22 -0
@@ -1,6 +1,7 @@
1
1
  import React from 'react';
2
2
  import type { ViewStyle } from 'react-native';
3
3
  import Animated, {
4
+ AnimatedStyleProp,
4
5
  runOnJS,
5
6
  useAnimatedReaction,
6
7
  useAnimatedStyle,
@@ -12,9 +13,7 @@ import { LazyView } from '../LazyView';
12
13
  import { CTX } from '../store';
13
14
  import type { ILayoutConfig } from './stack';
14
15
 
15
- export type TAnimationStyle = (
16
- value: number
17
- ) => Animated.AnimatedStyleProp<ViewStyle>;
16
+ export type TAnimationStyle = (value: number) => AnimatedStyleProp<ViewStyle>;
18
17
 
19
18
  export const BaseLayout: React.FC<{
20
19
  index: number;
@@ -69,6 +68,7 @@ export const BaseLayout: React.FC<{
69
68
  const x = useOffsetX(offsetXConfig, visibleRanges);
70
69
  const animationValue = useDerivedValue(() => x.value / size, [x, size]);
71
70
  const animatedStyle = useAnimatedStyle(
71
+ // @ts-ignore
72
72
  () => animationStyle(x.value / size),
73
73
  [animationStyle]
74
74
  );
@@ -1,7 +1,7 @@
1
1
  import { useMemo } from 'react';
2
2
  import { Dimensions, TransformsStyle, ViewStyle } from 'react-native';
3
3
  import { Extrapolate, interpolate } from 'react-native-reanimated';
4
- import type { ComputedDirectionTypes, CustomConfig } from 'src/types';
4
+ import type { ComputedDirectionTypes, CustomConfig } from '../types';
5
5
 
6
6
  const screen = Dimensions.get('window');
7
7
 
package/src/types.ts CHANGED
@@ -1,5 +1,10 @@
1
1
  import type { ViewStyle } from 'react-native';
2
2
  import type { PanGestureHandlerProps } from 'react-native-gesture-handler';
3
+ import type {
4
+ AnimatedStyleProp,
5
+ WithSpringConfig,
6
+ WithTimingConfig,
7
+ } from 'react-native-reanimated';
3
8
  import type Animated from 'react-native-reanimated';
4
9
  import type { TParallaxModeProps } from './layouts/parallax';
5
10
  import type { TStackModeProps } from './layouts/stack';
@@ -41,6 +46,16 @@ export type CustomConfig = {
41
46
  viewCount?: number;
42
47
  };
43
48
 
49
+ export type WithAnimation =
50
+ | {
51
+ type: 'spring';
52
+ config: WithSpringConfig;
53
+ }
54
+ | {
55
+ type: 'timing';
56
+ config: WithTimingConfig;
57
+ };
58
+
44
59
  export type TCarouselProps<T = any> = {
45
60
  ref?: React.Ref<ICarouselInstance>;
46
61
  /**
@@ -83,9 +98,8 @@ export type TCarouselProps<T = any> = {
83
98
  /**
84
99
  * PanGestureHandler props
85
100
  */
86
- panGestureHandlerProps?: Omit<
87
- Partial<PanGestureHandlerProps>,
88
- 'onHandlerStateChange'
101
+ panGestureHandlerProps?: Partial<
102
+ Omit<PanGestureHandlerProps, 'onHandlerStateChange'>
89
103
  >;
90
104
  /**
91
105
  * Determines the maximum number of items will respond to pan gesture events,
@@ -105,6 +119,10 @@ export type TCarouselProps<T = any> = {
105
119
  * @default true
106
120
  */
107
121
  enableSnap?: boolean;
122
+ /**
123
+ * Specifies the scrolling animation effect.
124
+ */
125
+ withAnimation?: WithAnimation;
108
126
  /**
109
127
  * Custom carousel config.
110
128
  */
@@ -113,7 +131,7 @@ export type TCarouselProps<T = any> = {
113
131
  * Custom animations.
114
132
  * Must use `worklet`, Details: https://docs.swmansion.com/react-native-reanimated/docs/2.2.0/worklets/
115
133
  */
116
- customAnimation?: (value: number) => Animated.AnimatedStyleProp<ViewStyle>;
134
+ customAnimation?: (value: number) => AnimatedStyleProp<ViewStyle>;
117
135
  /**
118
136
  * Render carousel item.
119
137
  */
@@ -0,0 +1,22 @@
1
+ import type { WithAnimation } from '../types';
2
+ import { withSpring, withTiming } from 'react-native-reanimated';
3
+
4
+ export function dealWithAnimation(
5
+ withAnimation: WithAnimation
6
+ ): (value: number, cb: (isFinished: boolean) => void) => number {
7
+ 'worklet';
8
+ switch (withAnimation.type) {
9
+ case 'spring':
10
+ return (value, cb) => {
11
+ return withSpring(value, withAnimation.config, (isFinished) =>
12
+ cb(isFinished as boolean)
13
+ );
14
+ };
15
+ case 'timing':
16
+ return (value, cb) => {
17
+ return withTiming(value, withAnimation.config, (isFinished) =>
18
+ cb(isFinished as boolean)
19
+ );
20
+ };
21
+ }
22
+ }