react-native-reanimated-carousel 2.2.5-beta.2 → 2.3.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 +3 -0
- package/README.zh-CN.md +3 -0
- package/lib/commonjs/Carousel.js +1 -1
- package/lib/commonjs/Carousel.js.map +1 -1
- package/lib/commonjs/ScrollViewGesture.js +1 -1
- package/lib/commonjs/ScrollViewGesture.js.map +1 -1
- package/lib/commonjs/constants/index.js.map +1 -1
- package/lib/commonjs/hooks/useCarouselController.js.map +1 -1
- package/lib/commonjs/hooks/useCheckMounted.js +2 -0
- package/lib/commonjs/hooks/useCheckMounted.js.map +1 -0
- package/lib/commonjs/hooks/useInitProps.js +1 -1
- package/lib/commonjs/hooks/useInitProps.js.map +1 -1
- package/lib/commonjs/layouts/BaseLayout.js +1 -1
- package/lib/commonjs/layouts/BaseLayout.js.map +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js +1 -1
- package/lib/commonjs/layouts/ParallaxLayout.js.map +1 -1
- package/lib/commonjs/layouts/parallax.js +1 -1
- package/lib/commonjs/layouts/parallax.js.map +1 -1
- package/lib/commonjs/layouts/stack.js +1 -1
- package/lib/commonjs/layouts/stack.js.map +1 -1
- package/lib/module/Carousel.js +10 -7
- package/lib/module/Carousel.js.map +1 -1
- package/lib/module/ScrollViewGesture.js +8 -7
- package/lib/module/ScrollViewGesture.js.map +1 -1
- package/lib/module/constants/index.js.map +1 -1
- package/lib/module/hooks/useCarouselController.js +8 -4
- package/lib/module/hooks/useCarouselController.js.map +1 -1
- package/lib/module/hooks/useCheckMounted.js +12 -0
- package/lib/module/hooks/useCheckMounted.js.map +1 -0
- package/lib/module/hooks/useInitProps.js +6 -2
- package/lib/module/hooks/useInitProps.js.map +1 -1
- package/lib/module/layouts/BaseLayout.js +4 -2
- package/lib/module/layouts/BaseLayout.js.map +1 -1
- package/lib/module/layouts/ParallaxLayout.js +2 -1
- package/lib/module/layouts/ParallaxLayout.js.map +1 -1
- package/lib/module/layouts/parallax.js +5 -3
- package/lib/module/layouts/parallax.js.map +1 -1
- package/lib/module/layouts/stack.js +7 -3
- package/lib/module/layouts/stack.js.map +1 -1
- package/lib/module/utils/log.js +2 -2
- package/lib/module/utils/log.js.map +1 -1
- package/lib/typescript/constants/index.d.ts +2 -1
- package/lib/typescript/hooks/useCheckMounted.d.ts +2 -0
- package/lib/typescript/layouts/ParallaxLayout.d.ts +2 -3
- package/lib/typescript/layouts/parallax.d.ts +8 -3
- package/lib/typescript/types.d.ts +17 -4
- package/package.json +3 -3
- package/src/ScrollViewGesture.tsx +8 -7
- package/src/constants/index.ts +7 -2
- package/src/hooks/useCarouselController.tsx +2 -2
- package/src/hooks/useCheckMounted.ts +14 -0
- package/src/hooks/useInitProps.ts +4 -2
- package/src/layouts/BaseLayout.tsx +8 -5
- package/src/layouts/ParallaxLayout.tsx +13 -11
- package/src/layouts/parallax.ts +15 -7
- package/src/types.ts +24 -11
|
@@ -15,7 +15,7 @@ import Animated, {
|
|
|
15
15
|
} from 'react-native-reanimated';
|
|
16
16
|
import { Easing } from './constants';
|
|
17
17
|
import { CTX } from './store';
|
|
18
|
-
import type {
|
|
18
|
+
import type { WithTimingAnimation } from './types';
|
|
19
19
|
import { dealWithAnimation } from './utils/dealWithAnimation';
|
|
20
20
|
|
|
21
21
|
type GestureContext = {
|
|
@@ -41,11 +41,12 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
41
41
|
style,
|
|
42
42
|
data,
|
|
43
43
|
pagingEnabled,
|
|
44
|
-
|
|
44
|
+
snapEnabled,
|
|
45
45
|
panGestureHandlerProps,
|
|
46
46
|
loop: infinite,
|
|
47
47
|
scrollAnimationDuration,
|
|
48
48
|
withAnimation,
|
|
49
|
+
enabled,
|
|
49
50
|
},
|
|
50
51
|
} = React.useContext(CTX);
|
|
51
52
|
|
|
@@ -74,7 +75,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
74
75
|
}
|
|
75
76
|
};
|
|
76
77
|
|
|
77
|
-
const defaultWithAnimation:
|
|
78
|
+
const defaultWithAnimation: WithTimingAnimation = {
|
|
78
79
|
type: 'timing',
|
|
79
80
|
config: {
|
|
80
81
|
duration: scrollAnimationDuration,
|
|
@@ -96,7 +97,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
96
97
|
const origin = translation.value;
|
|
97
98
|
const velocity = scrollEndVelocity.value;
|
|
98
99
|
if (!pagingEnabled) {
|
|
99
|
-
if (
|
|
100
|
+
if (snapEnabled) {
|
|
100
101
|
const nextPage =
|
|
101
102
|
Math.round((origin + velocity * 0.4) / size) * size;
|
|
102
103
|
translation.value = _withSpring(nextPage, onFinished);
|
|
@@ -130,7 +131,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
130
131
|
size,
|
|
131
132
|
maxPage,
|
|
132
133
|
pagingEnabled,
|
|
133
|
-
|
|
134
|
+
snapEnabled,
|
|
134
135
|
]
|
|
135
136
|
);
|
|
136
137
|
|
|
@@ -243,7 +244,6 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
243
244
|
? translationX
|
|
244
245
|
: translationY;
|
|
245
246
|
|
|
246
|
-
// endWithSpring(() => onScrollEnd && runOnJS(onScrollEnd)());
|
|
247
247
|
endWithSpring(onScrollEnd);
|
|
248
248
|
|
|
249
249
|
if (!infinite) {
|
|
@@ -257,7 +257,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
257
257
|
infinite,
|
|
258
258
|
maxPage,
|
|
259
259
|
size,
|
|
260
|
-
|
|
260
|
+
snapEnabled,
|
|
261
261
|
onScrollBegin,
|
|
262
262
|
onScrollEnd,
|
|
263
263
|
]
|
|
@@ -275,6 +275,7 @@ const IScrollViewGesture: React.FC<Props> = (props) => {
|
|
|
275
275
|
>
|
|
276
276
|
<PanGestureHandler
|
|
277
277
|
{...panGestureHandlerProps}
|
|
278
|
+
enabled={enabled}
|
|
278
279
|
onGestureEvent={panGestureEventHandler}
|
|
279
280
|
>
|
|
280
281
|
{props.children}
|
package/src/constants/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Easing as _Easing } from 'react-native-reanimated';
|
|
1
|
+
import Animated, { Easing as _Easing } from 'react-native-reanimated';
|
|
2
2
|
|
|
3
3
|
export enum DATA_LENGTH {
|
|
4
4
|
SINGLE_ITEM = 1,
|
|
@@ -6,5 +6,10 @@ export enum DATA_LENGTH {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
export const Easing = {
|
|
9
|
-
easeOutQuart: _Easing.bezier(
|
|
9
|
+
easeOutQuart: _Easing.bezier(
|
|
10
|
+
0.25,
|
|
11
|
+
1,
|
|
12
|
+
0.5,
|
|
13
|
+
1
|
|
14
|
+
) as unknown as Animated.EasingFunction,
|
|
10
15
|
};
|
|
@@ -5,7 +5,7 @@ import { runOnJS, useSharedValue } from 'react-native-reanimated';
|
|
|
5
5
|
import type {
|
|
6
6
|
TCarouselActionOptions,
|
|
7
7
|
TCarouselProps,
|
|
8
|
-
|
|
8
|
+
WithTimingAnimation,
|
|
9
9
|
} from '../types';
|
|
10
10
|
import { dealWithAnimation } from '@/utils/dealWithAnimation';
|
|
11
11
|
|
|
@@ -132,7 +132,7 @@ export function useCarouselController(options: IOpts): ICarouselController {
|
|
|
132
132
|
}
|
|
133
133
|
};
|
|
134
134
|
|
|
135
|
-
const defaultWithAnimation:
|
|
135
|
+
const defaultWithAnimation: WithTimingAnimation = {
|
|
136
136
|
type: 'timing',
|
|
137
137
|
config: { duration, easing: Easing.easeOutQuart },
|
|
138
138
|
};
|
|
@@ -27,12 +27,13 @@ export function useInitProps<T>(
|
|
|
27
27
|
defaultIndex = 0,
|
|
28
28
|
data: rawData = [],
|
|
29
29
|
loop = true,
|
|
30
|
+
enabled = true,
|
|
30
31
|
autoPlayInterval: _autoPlayInterval = 1000,
|
|
31
32
|
scrollAnimationDuration = 500,
|
|
32
33
|
style = {},
|
|
33
34
|
panGestureHandlerProps = {},
|
|
34
35
|
pagingEnabled = true,
|
|
35
|
-
|
|
36
|
+
snapEnabled = props.enableSnap ?? true,
|
|
36
37
|
width: _width,
|
|
37
38
|
height: _height,
|
|
38
39
|
} = props;
|
|
@@ -68,12 +69,13 @@ export function useInitProps<T>(
|
|
|
68
69
|
data,
|
|
69
70
|
rawData,
|
|
70
71
|
loop,
|
|
72
|
+
enabled,
|
|
71
73
|
autoPlayInterval,
|
|
72
74
|
scrollAnimationDuration,
|
|
73
75
|
style,
|
|
74
76
|
panGestureHandlerProps,
|
|
75
77
|
pagingEnabled,
|
|
76
|
-
|
|
78
|
+
snapEnabled,
|
|
77
79
|
width,
|
|
78
80
|
height,
|
|
79
81
|
};
|
|
@@ -7,6 +7,7 @@ import Animated, {
|
|
|
7
7
|
useAnimatedStyle,
|
|
8
8
|
useDerivedValue,
|
|
9
9
|
} from 'react-native-reanimated';
|
|
10
|
+
import { useCheckMounted } from 'src/hooks/useCheckMounted';
|
|
10
11
|
import { IOpts, useOffsetX } from '../hooks/useOffsetX';
|
|
11
12
|
import type { IVisibleRanges } from '../hooks/useVisibleRanges';
|
|
12
13
|
import { LazyView } from '../LazyView';
|
|
@@ -24,6 +25,7 @@ export const BaseLayout: React.FC<{
|
|
|
24
25
|
animationValue: Animated.SharedValue<number>;
|
|
25
26
|
}) => React.ReactElement;
|
|
26
27
|
}> = (props) => {
|
|
28
|
+
const mounted = useCheckMounted();
|
|
27
29
|
const { handlerOffsetX, index, children, visibleRanges, animationStyle } =
|
|
28
30
|
props;
|
|
29
31
|
|
|
@@ -75,12 +77,13 @@ export const BaseLayout: React.FC<{
|
|
|
75
77
|
|
|
76
78
|
const updateView = React.useCallback(
|
|
77
79
|
(negativeRange: number[], positiveRange: number[]) => {
|
|
78
|
-
|
|
79
|
-
(
|
|
80
|
-
(index >=
|
|
81
|
-
|
|
80
|
+
mounted.current &&
|
|
81
|
+
setShouldUpdate(
|
|
82
|
+
(index >= negativeRange[0] && index <= negativeRange[1]) ||
|
|
83
|
+
(index >= positiveRange[0] && index <= positiveRange[1])
|
|
84
|
+
);
|
|
82
85
|
},
|
|
83
|
-
[index]
|
|
86
|
+
[index, mounted]
|
|
84
87
|
);
|
|
85
88
|
|
|
86
89
|
useAnimatedReaction(
|
|
@@ -10,22 +10,24 @@ import type { ComputedDirectionTypes } from 'src/types';
|
|
|
10
10
|
import { useOffsetX } from '../hooks/useOffsetX';
|
|
11
11
|
import type { IVisibleRanges } from '../hooks/useVisibleRanges';
|
|
12
12
|
import { LazyView } from '../LazyView';
|
|
13
|
+
import type { ILayoutConfig } from './parallax';
|
|
13
14
|
|
|
14
15
|
export const ParallaxLayout: React.FC<
|
|
15
|
-
ComputedDirectionTypes<
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
16
|
+
ComputedDirectionTypes<
|
|
17
|
+
{
|
|
18
|
+
loop?: boolean;
|
|
19
|
+
handlerOffsetX: Animated.SharedValue<number>;
|
|
20
|
+
index: number;
|
|
21
|
+
data: unknown[];
|
|
22
|
+
visibleRanges: IVisibleRanges;
|
|
23
|
+
} & ILayoutConfig
|
|
24
|
+
>
|
|
24
25
|
> = (props) => {
|
|
25
26
|
const {
|
|
26
27
|
handlerOffsetX,
|
|
27
28
|
parallaxScrollingOffset = 100,
|
|
28
29
|
parallaxScrollingScale = 0.8,
|
|
30
|
+
parallaxAdjacentItemScale = Math.pow(parallaxScrollingScale, 2),
|
|
29
31
|
index,
|
|
30
32
|
width,
|
|
31
33
|
height,
|
|
@@ -76,9 +78,9 @@ export const ParallaxLayout: React.FC<
|
|
|
76
78
|
value,
|
|
77
79
|
[-1, 0, 1],
|
|
78
80
|
[
|
|
79
|
-
|
|
81
|
+
parallaxAdjacentItemScale,
|
|
80
82
|
parallaxScrollingScale,
|
|
81
|
-
|
|
83
|
+
parallaxAdjacentItemScale,
|
|
82
84
|
],
|
|
83
85
|
Extrapolate.CLAMP
|
|
84
86
|
);
|
package/src/layouts/parallax.ts
CHANGED
|
@@ -6,17 +6,22 @@ type TBaseConfig = {
|
|
|
6
6
|
vertical: boolean;
|
|
7
7
|
};
|
|
8
8
|
|
|
9
|
-
interface ILayoutConfig {
|
|
9
|
+
export interface ILayoutConfig {
|
|
10
10
|
/**
|
|
11
|
-
*
|
|
11
|
+
* control prev/next item offset.
|
|
12
12
|
* @default 100
|
|
13
13
|
*/
|
|
14
14
|
parallaxScrollingOffset?: number;
|
|
15
15
|
/**
|
|
16
|
-
*
|
|
16
|
+
* control prev/current/next item offset.
|
|
17
17
|
* @default 0.8
|
|
18
18
|
*/
|
|
19
19
|
parallaxScrollingScale?: number;
|
|
20
|
+
/**
|
|
21
|
+
* control prev/next item offset.
|
|
22
|
+
* @default Math.pow(parallaxScrollingScale, 2)
|
|
23
|
+
*/
|
|
24
|
+
parallaxAdjacentItemScale?: number;
|
|
20
25
|
}
|
|
21
26
|
|
|
22
27
|
export type TParallaxModeProps = ComputedDirectionTypes<{
|
|
@@ -32,8 +37,11 @@ export function parallaxLayout(
|
|
|
32
37
|
modeConfig: ILayoutConfig = {}
|
|
33
38
|
) {
|
|
34
39
|
const { size, vertical } = baseConfig;
|
|
35
|
-
const {
|
|
36
|
-
|
|
40
|
+
const {
|
|
41
|
+
parallaxScrollingOffset = 100,
|
|
42
|
+
parallaxScrollingScale = 0.8,
|
|
43
|
+
parallaxAdjacentItemScale = Math.pow(parallaxScrollingScale, 2),
|
|
44
|
+
} = modeConfig;
|
|
37
45
|
|
|
38
46
|
return (value: number) => {
|
|
39
47
|
'worklet';
|
|
@@ -54,9 +62,9 @@ export function parallaxLayout(
|
|
|
54
62
|
value,
|
|
55
63
|
[-1, 0, 1],
|
|
56
64
|
[
|
|
57
|
-
|
|
65
|
+
parallaxAdjacentItemScale,
|
|
58
66
|
parallaxScrollingScale,
|
|
59
|
-
|
|
67
|
+
parallaxAdjacentItemScale,
|
|
60
68
|
],
|
|
61
69
|
Extrapolate.CLAMP
|
|
62
70
|
);
|
package/src/types.ts
CHANGED
|
@@ -46,15 +46,17 @@ export type CustomConfig = {
|
|
|
46
46
|
viewCount?: number;
|
|
47
47
|
};
|
|
48
48
|
|
|
49
|
-
export type
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
49
|
+
export type WithSpringAnimation = {
|
|
50
|
+
type: 'spring';
|
|
51
|
+
config: WithSpringConfig;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type WithTimingAnimation = {
|
|
55
|
+
type: 'timing';
|
|
56
|
+
config: WithTimingConfig;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type WithAnimation = WithSpringAnimation | WithTimingAnimation;
|
|
58
60
|
|
|
59
61
|
export type TCarouselProps<T = any> = {
|
|
60
62
|
ref?: React.Ref<ICarouselInstance>;
|
|
@@ -99,7 +101,7 @@ export type TCarouselProps<T = any> = {
|
|
|
99
101
|
* PanGestureHandler props
|
|
100
102
|
*/
|
|
101
103
|
panGestureHandlerProps?: Partial<
|
|
102
|
-
Omit<PanGestureHandlerProps, 'onHandlerStateChange'>
|
|
104
|
+
Omit<PanGestureHandlerProps, 'onHandlerStateChange' | 'enabled'>
|
|
103
105
|
>;
|
|
104
106
|
/**
|
|
105
107
|
* Determines the maximum number of items will respond to pan gesture events,
|
|
@@ -116,9 +118,20 @@ export type TCarouselProps<T = any> = {
|
|
|
116
118
|
/**
|
|
117
119
|
* If enabled, releasing the touch will scroll to the nearest item.
|
|
118
120
|
* valid when pagingEnabled=false
|
|
119
|
-
* @
|
|
121
|
+
* @deprecated please use snapEnabled instead
|
|
120
122
|
*/
|
|
121
123
|
enableSnap?: boolean;
|
|
124
|
+
/**
|
|
125
|
+
* If enabled, releasing the touch will scroll to the nearest item.
|
|
126
|
+
* valid when pagingEnabled=false
|
|
127
|
+
* @default true
|
|
128
|
+
*/
|
|
129
|
+
snapEnabled?: boolean;
|
|
130
|
+
/**
|
|
131
|
+
* If false, Carousel will not respond to any gestures.
|
|
132
|
+
* @default true
|
|
133
|
+
*/
|
|
134
|
+
enabled?: boolean;
|
|
122
135
|
/**
|
|
123
136
|
* Specifies the scrolling animation effect.
|
|
124
137
|
*/
|