@momo-kits/carousel 0.150.3-beta.20 → 0.151.1-beta.2

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 (4) hide show
  1. package/animation.ts +17 -148
  2. package/index.tsx +700 -1330
  3. package/package.json +20 -20
  4. package/types.ts +18 -64
package/animation.ts CHANGED
@@ -1,46 +1,37 @@
1
- import { Animated } from 'react-native';
2
- import { CarouselProps } from './types';
1
+ import {ReactNode} from 'react';
2
+ import {Animated} from 'react-native';
3
+ import {CarouselProps} from './types';
3
4
 
4
- function getInputRangeFromIndexes(
5
- range: number[],
5
+ export function getInputRangeFromIndexes(
6
+ range: string | any[],
6
7
  index: number,
7
- carouselProps: CarouselProps,
8
+ itemWidth: number,
8
9
  ) {
9
- const sizeRef = carouselProps.vertical
10
- ? carouselProps.itemHeight
11
- : carouselProps.itemWidth;
12
-
13
- // Ensure sizeRef is valid to prevent NaN in inputRange
14
- const validSizeRef = sizeRef && isFinite(sizeRef) && sizeRef > 0 ? sizeRef : 1;
15
-
10
+ const sizeRef = itemWidth;
16
11
  const inputRange = [];
17
12
 
18
13
  for (let i = 0; i < range.length; i++) {
19
- inputRange.push((index - range[i]) * validSizeRef);
14
+ inputRange.push((index - range[i]) * sizeRef);
20
15
  }
21
16
 
22
17
  return inputRange;
23
18
  }
24
19
 
25
- export function defaultScrollInterpolator(
26
- index: number,
27
- carouselProps: CarouselProps,
28
- ) {
29
- const range = [3, 2, 1, 0, -1, -2, -3];
30
- const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
31
- const outputRange = [0, 0, 0, 1, 0, 0, 0];
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];
32
24
 
33
- return { inputRange, outputRange };
25
+ return {inputRange, outputRange};
34
26
  }
35
27
 
36
28
  export function defaultAnimatedStyles(
37
- index: number,
38
- animatedValue: Animated.AnimatedInterpolation<number>,
39
- carouselProps: CarouselProps,
29
+ animatedValue: Animated.Value,
30
+ carouselProps: Readonly<CarouselProps> & Readonly<{children?: ReactNode}>,
40
31
  ) {
41
32
  let animatedOpacity = {};
42
33
  let animatedScale = {};
43
- const { inactiveSlideOpacity = 1, inactiveSlideScale = 1 } = carouselProps;
34
+ const {inactiveSlideOpacity = 1, inactiveSlideScale = 1} = carouselProps;
44
35
 
45
36
  if (inactiveSlideOpacity < 1) {
46
37
  animatedOpacity = {
@@ -55,7 +46,7 @@ export function defaultAnimatedStyles(
55
46
  animatedScale = {
56
47
  transform: [
57
48
  {
58
- scale: animatedValue.interpolate({
49
+ scaleY: animatedValue.interpolate({
59
50
  inputRange: [0, 1],
60
51
  outputRange: [inactiveSlideScale, 1],
61
52
  }),
@@ -69,125 +60,3 @@ export function defaultAnimatedStyles(
69
60
  ...animatedScale,
70
61
  };
71
62
  }
72
-
73
- export function shiftAnimatedStyles(
74
- index: number,
75
- animatedValue: Animated.AnimatedInterpolation<number>,
76
- carouselProps: CarouselProps,
77
- ) {
78
- const { inactiveSlideShift = 0 } = carouselProps;
79
-
80
- let animatedShift = {};
81
-
82
- if (inactiveSlideShift !== 0) {
83
- animatedShift = {
84
- transform: [
85
- {
86
- translateX: animatedValue.interpolate({
87
- inputRange: [0, 1],
88
- outputRange: [inactiveSlideShift, 0],
89
- }),
90
- },
91
- ],
92
- };
93
- }
94
-
95
- return {
96
- ...defaultAnimatedStyles(index, animatedValue, carouselProps),
97
- ...animatedShift,
98
- };
99
- }
100
-
101
- export function stackScrollInterpolator(
102
- index: number,
103
- carouselProps: CarouselProps,
104
- ) {
105
- const range = [3, 2, 1, 0, -1, -2, -3];
106
- const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
107
- const outputRange = [0, 0, 0, 1, 0, 0, 0];
108
-
109
- return { inputRange, outputRange };
110
- }
111
-
112
- export function stackAnimatedStyles(
113
- index: number,
114
- animatedValue: Animated.AnimatedInterpolation<number>,
115
- carouselProps: CarouselProps,
116
- cardOffset?: number,
117
- ) {
118
- const translateProp = carouselProps.vertical ? 'translateY' : 'translateX';
119
- const offsetValue = cardOffset || 18;
120
-
121
- return {
122
- opacity: animatedValue,
123
- transform: [
124
- {
125
- scale: animatedValue.interpolate({
126
- inputRange: [0, 1],
127
- outputRange: [0.8, 1],
128
- }),
129
- },
130
- {
131
- [translateProp]: animatedValue.interpolate({
132
- inputRange: [0, 1],
133
- outputRange: [offsetValue, 0],
134
- }),
135
- },
136
- ],
137
- zIndex: carouselProps.data ? carouselProps.data.length - index : index,
138
- };
139
- }
140
-
141
- export function tinderScrollInterpolator(
142
- index: number,
143
- carouselProps: CarouselProps,
144
- ) {
145
- const range = [3, 2, 1, 0, -1, -2, -3];
146
- const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
147
- const outputRange = [0, 0, 0, 1, 1, 1, 1];
148
-
149
- return { inputRange, outputRange };
150
- }
151
-
152
- export function tinderAnimatedStyles(
153
- index: number,
154
- animatedValue: Animated.AnimatedInterpolation<number>,
155
- carouselProps: CarouselProps,
156
- cardOffset?: number,
157
- ) {
158
- const sizeRef = carouselProps.vertical
159
- ? carouselProps.itemHeight
160
- : carouselProps.itemWidth;
161
- const translateProp = carouselProps.vertical ? 'translateY' : 'translateX';
162
- const rotateProp = carouselProps.vertical ? 'rotateX' : 'rotateY';
163
- const validSizeRef = sizeRef && isFinite(sizeRef) && sizeRef > 0 ? sizeRef : 100;
164
- const offsetValue = cardOffset || validSizeRef;
165
-
166
- return {
167
- opacity: animatedValue.interpolate({
168
- inputRange: [0, 1],
169
- outputRange: [1, 0],
170
- }),
171
- transform: [
172
- {
173
- scale: animatedValue.interpolate({
174
- inputRange: [0, 0.5, 1],
175
- outputRange: [1, 0.95, 0.9],
176
- }),
177
- },
178
- {
179
- [translateProp]: animatedValue.interpolate({
180
- inputRange: [0, 1],
181
- outputRange: [0, -offsetValue],
182
- }),
183
- },
184
- {
185
- [rotateProp]: animatedValue.interpolate({
186
- inputRange: [0, 1],
187
- outputRange: ['0deg', '30deg'],
188
- }),
189
- },
190
- ],
191
- zIndex: carouselProps.data ? carouselProps.data.length - index : index,
192
- };
193
- }