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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/lib/commonjs/Carousel.js +1 -221
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/LazyView.js +1 -25
- package/lib/commonjs/LazyView.js.map +1 -1
- package/lib/commonjs/ScrollViewGesture.js +1 -217
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/constants/index.js +1 -21
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useAutoPlay.js +1 -61
- package/lib/commonjs/hooks/useAutoPlay.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js +1 -194
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCommonVariables.js +1 -36
- package/lib/commonjs/hooks/useCommonVariables.js.map +1 -1
- package/lib/commonjs/hooks/useInitProps.js +1 -70
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/hooks/useLayoutConfig.js +1 -39
- package/lib/commonjs/hooks/useLayoutConfig.js.map +1 -1
- package/lib/commonjs/hooks/useOffsetX.js +1 -54
- package/lib/commonjs/hooks/useOffsetX.js.map +1 -1
- package/lib/commonjs/hooks/useOnProgressChange.js +1 -38
- package/lib/commonjs/hooks/useOnProgressChange.js.map +1 -1
- package/lib/commonjs/hooks/usePropsErrorBoundary.js +1 -37
- package/lib/commonjs/hooks/usePropsErrorBoundary.js.map +1 -1
- package/lib/commonjs/hooks/useVisibleRanges.js +1 -42
- package/lib/commonjs/hooks/useVisibleRanges.js.map +1 -1
- package/lib/commonjs/index.js +1 -13
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -100
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +1 -82
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/index.js +1 -20
- package/lib/commonjs/layouts/index.js.map +1 -1
- package/lib/commonjs/layouts/normal.js +1 -27
- package/lib/commonjs/layouts/normal.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +1 -36
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +1 -219
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/commonjs/store/index.js +1 -14
- package/lib/commonjs/store/index.js.map +1 -1
- package/lib/commonjs/types.js +1 -5
- package/lib/commonjs/utils/dealWithAnimation.js +2 -0
- package/lib/commonjs/utils/dealWithAnimation.js.map +1 -0
- package/lib/commonjs/utils/log.js +1 -14
- package/lib/commonjs/utils/log.js.map +1 -1
- package/lib/module/Carousel.js +14 -10
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +46 -29
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/hooks/useAutoPlay.js +5 -1
- package/lib/module/hooks/useAutoPlay.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +21 -7
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +2 -1
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/stack.js.map +1 -1
- package/lib/module/utils/dealWithAnimation.js +17 -0
- package/lib/module/utils/dealWithAnimation.js.map +1 -0
- package/lib/typescript/Carousel.d.ts +3 -4
- package/lib/typescript/ScrollViewGesture.d.ts +3 -1
- package/lib/typescript/hooks/useCarouselController.d.ts +2 -1
- package/lib/typescript/layouts/BaseLayout.d.ts +2 -2
- package/lib/typescript/layouts/stack.d.ts +1 -1
- package/lib/typescript/types.d.ts +14 -2
- package/lib/typescript/utils/dealWithAnimation.d.ts +2 -0
- package/package.json +12 -2
- package/src/Carousel.tsx +203 -188
- package/src/ScrollViewGesture.tsx +70 -33
- package/src/hooks/useAutoPlay.ts +4 -1
- package/src/hooks/useCarouselController.tsx +28 -12
- package/src/layouts/BaseLayout.tsx +3 -3
- package/src/layouts/stack.ts +1 -1
- package/src/types.ts +22 -4
- 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
|
);
|
package/src/layouts/stack.ts
CHANGED
|
@@ -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 '
|
|
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?:
|
|
87
|
-
|
|
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) =>
|
|
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
|
+
}
|