@momo-kits/carousel 0.79.6 → 0.80.1-beta.3

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/animation.ts ADDED
@@ -0,0 +1,61 @@
1
+ import {ReactNode} from 'react';
2
+ import {Animated} from 'react-native';
3
+ import {CarouselProps} from './types';
4
+
5
+ export function getInputRangeFromIndexes(
6
+ range: string | any[],
7
+ index: number,
8
+ itemWidth: number,
9
+ ) {
10
+ const sizeRef = itemWidth;
11
+ const inputRange = [];
12
+
13
+ for (let i = 0; i < range.length; i++) {
14
+ inputRange.push((index - range[i]) * sizeRef);
15
+ }
16
+
17
+ return inputRange;
18
+ }
19
+
20
+ export function defaultScrollInterpolator(index: number, itemWidth: number) {
21
+ const range = [1, 0, -1];
22
+ const inputRange = getInputRangeFromIndexes(range, index, itemWidth);
23
+ const outputRange = [0, 1, 0];
24
+
25
+ return {inputRange, outputRange};
26
+ }
27
+
28
+ export function defaultAnimatedStyles(
29
+ animatedValue: Animated.Value,
30
+ carouselProps: Readonly<CarouselProps> & Readonly<{children?: ReactNode}>,
31
+ ) {
32
+ let animatedOpacity = {};
33
+ let animatedScale = {};
34
+
35
+ if (carouselProps.inactiveSlideOpacity < 1) {
36
+ animatedOpacity = {
37
+ opacity: animatedValue.interpolate({
38
+ inputRange: [0, 1],
39
+ outputRange: [carouselProps.inactiveSlideOpacity, 1],
40
+ }),
41
+ };
42
+ }
43
+
44
+ if (carouselProps.inactiveSlideScale < 1) {
45
+ animatedScale = {
46
+ transform: [
47
+ {
48
+ scaleY: animatedValue.interpolate({
49
+ inputRange: [0, 1],
50
+ outputRange: [carouselProps.inactiveSlideScale, 1],
51
+ }),
52
+ },
53
+ ],
54
+ };
55
+ }
56
+
57
+ return {
58
+ ...animatedOpacity,
59
+ ...animatedScale,
60
+ };
61
+ }