@momo-kits/carousel 0.0.65-alpha.2 → 0.0.65-alpha.20

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/index.js CHANGED
@@ -1,7 +1,5 @@
1
- //import Carousel from './Carousel';
2
1
  import Carousel from './CarouselV2';
3
2
  import Pagination from './pagination/Pagination';
3
+ import NumberPagination from './pagination/NumberPagination';
4
4
 
5
- export {
6
- Carousel, Pagination
7
- };
5
+ export {Carousel, Pagination, NumberPagination};
package/package.json CHANGED
@@ -1,16 +1,17 @@
1
1
  {
2
- "name": "@momo-kits/carousel",
3
- "version": "0.0.65-alpha.2",
4
- "private": false,
5
- "main": "index.js",
6
- "dependencies": {
7
- "prop-types": "^15.7.2",
8
- "react": "16.9.0"
9
- },
10
- "peerDependencies": {
11
- "react": "16.9.0",
12
- "react-native": ">=0.55"
13
- },
14
- "devDependencies": {},
15
- "license": "MoMo"
16
- }
2
+ "name": "@momo-kits/carousel",
3
+ "version": "0.0.65-alpha.20",
4
+ "private": false,
5
+ "main": "index.js",
6
+ "dependencies": {
7
+ "prop-types": "^15.7.2",
8
+ "react": "16.9.0"
9
+ },
10
+ "peerDependencies": {
11
+ "react": "16.9.0",
12
+ "react-native": ">=0.55",
13
+ "@momo-kits/core-v2": ">=0.0.4-beta"
14
+ },
15
+ "devDependencies": {},
16
+ "license": "MoMo"
17
+ }
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { Colors, Radius, Spacing, Text } from '@momo-kits/core-v2';
3
+ import { View, StyleSheet } from 'react-native';
4
+ import PropTypes from 'prop-types';
5
+
6
+ const NumberPagination = (props) => {
7
+ const { dataLength, activeIndex, style } = props;
8
+
9
+ return (
10
+ <View style={style}>
11
+ <View style={styles.container}>
12
+ <Text.Label1 style={styles.number}>{`${
13
+ activeIndex + 1
14
+ }/${dataLength}`}</Text.Label1>
15
+ </View>
16
+ </View>
17
+ );
18
+ };
19
+
20
+ const styles = StyleSheet.create({
21
+ container: {
22
+ backgroundColor: Colors.black_08,
23
+ alignSelf: 'baseline',
24
+ paddingHorizontal: Spacing.S,
25
+ borderRadius: Radius.M,
26
+ },
27
+ number: {
28
+ color: Colors.black_01,
29
+ },
30
+ });
31
+
32
+ NumberPagination.defaultProps = {
33
+ dataLength: 0,
34
+ activeIndex: 0,
35
+ };
36
+
37
+ NumberPagination.propsType = {
38
+ dataLength: PropTypes.number,
39
+ activeIndex: PropTypes.number,
40
+ style: PropTypes.oneOfType([PropTypes.array, PropTypes.object]),
41
+ };
42
+
43
+ export default NumberPagination;
@@ -1,10 +1,9 @@
1
1
  import React, { PureComponent } from 'react';
2
- import {
3
- I18nManager, Platform, View
4
- } from 'react-native';
2
+ import { I18nManager, Platform, View } from 'react-native';
5
3
  import PropTypes from 'prop-types';
6
4
  import PaginationDot from './PaginationDot';
7
5
  import styles from './styles';
6
+ import { Colors, Radius, Spacing } from '@momo-kits/core-v2';
8
7
 
9
8
  const IS_IOS = Platform.OS === 'ios';
10
9
  const IS_RTL = I18nManager.isRTL;
@@ -14,34 +13,37 @@ export default class Pagination extends PureComponent {
14
13
  super(props);
15
14
 
16
15
  // Warnings
17
- if ((props.dotColor && !props.inactiveDotColor) || (!props.dotColor && props.inactiveDotColor)) {
16
+ if (
17
+ (props.dotColor && !props.inactiveDotColor) ||
18
+ (!props.dotColor && props.inactiveDotColor)
19
+ ) {
18
20
  console.warn(
19
- 'react-native-snap-carousel | Pagination: '
20
- + 'You need to specify both `dotColor` and `inactiveDotColor`'
21
+ 'react-native-snap-carousel | Pagination: ' +
22
+ 'You need to specify both `dotColor` and `inactiveDotColor`',
21
23
  );
22
24
  }
23
- if ((props.dotElement && !props.inactiveDotElement) || (!props.dotElement && props.inactiveDotElement)) {
25
+ if (
26
+ (props.dotElement && !props.inactiveDotElement) ||
27
+ (!props.dotElement && props.inactiveDotElement)
28
+ ) {
24
29
  console.warn(
25
- 'react-native-snap-carousel | Pagination: '
26
- + 'You need to specify both `dotElement` and `inactiveDotElement`'
30
+ 'react-native-snap-carousel | Pagination: ' +
31
+ 'You need to specify both `dotElement` and `inactiveDotElement`',
27
32
  );
28
33
  }
29
34
  if (props.tappableDots && !props.carouselRef) {
30
35
  console.warn(
31
- 'react-native-snap-carousel | Pagination: '
32
- + 'You must specify prop `carouselRef` when setting `tappableDots` to `true`'
36
+ 'react-native-snap-carousel | Pagination: ' +
37
+ 'You must specify prop `carouselRef` when setting `tappableDots` to `true`',
33
38
  );
34
39
  }
35
40
  }
36
41
 
37
- _needsRTLAdaptations() {
38
- const { vertical } = this.props;
39
- return IS_RTL && !IS_IOS && !vertical;
40
- }
41
-
42
42
  get _activeDotIndex() {
43
43
  const { activeDotIndex, dotsLength } = this.props;
44
- return this._needsRTLAdaptations() ? dotsLength - activeDotIndex - 1 : activeDotIndex;
44
+ return this._needsRTLAdaptations()
45
+ ? dotsLength - activeDotIndex - 1
46
+ : activeDotIndex;
45
47
  }
46
48
 
47
49
  get dots() {
@@ -59,7 +61,8 @@ export default class Pagination extends PureComponent {
59
61
  inactiveDotScale,
60
62
  inactiveDotStyle,
61
63
  renderDots,
62
- tappableDots
64
+ tappableDots,
65
+ type,
63
66
  } = this.props;
64
67
 
65
68
  if (renderDots) {
@@ -78,6 +81,7 @@ export default class Pagination extends PureComponent {
78
81
  inactiveOpacity={inactiveDotOpacity}
79
82
  inactiveScale={inactiveDotScale}
80
83
  inactiveStyle={inactiveDotStyle}
84
+ type={type}
81
85
  />
82
86
  );
83
87
 
@@ -85,22 +89,33 @@ export default class Pagination extends PureComponent {
85
89
 
86
90
  for (let i = 0; i < dotsLength; i += 1) {
87
91
  const isActive = i === this._activeDotIndex;
88
- dots.push(React.cloneElement(
89
- (isActive ? dotElement : inactiveDotElement) || DefaultDot,
90
- {
91
- key: `pagination-dot-${i}`,
92
- active: i === this._activeDotIndex,
93
- index: i
94
- }
95
- ));
92
+ dots.push(
93
+ React.cloneElement(
94
+ (isActive ? dotElement : inactiveDotElement) || DefaultDot,
95
+ {
96
+ key: `pagination-dot-${i}`,
97
+ active: i === this._activeDotIndex,
98
+ index: i,
99
+ },
100
+ ),
101
+ );
96
102
  }
97
103
 
98
104
  return dots;
99
105
  }
100
106
 
107
+ _needsRTLAdaptations() {
108
+ const { vertical } = this.props;
109
+ return IS_RTL && !IS_IOS && !vertical;
110
+ }
111
+
101
112
  render() {
102
113
  const {
103
- dotsLength, containerStyle, vertical, accessibilityLabel
114
+ dotsLength,
115
+ containerStyle,
116
+ vertical,
117
+ accessibilityLabel,
118
+ type,
104
119
  } = this.props;
105
120
 
106
121
  if (!dotsLength || dotsLength < 2) {
@@ -112,9 +127,11 @@ export default class Pagination extends PureComponent {
112
127
  {
113
128
  flexDirection: vertical
114
129
  ? 'column'
115
- : (this._needsRTLAdaptations() ? 'row-reverse' : 'row')
130
+ : this._needsRTLAdaptations()
131
+ ? 'row-reverse'
132
+ : 'row',
116
133
  },
117
- containerStyle || {}
134
+ containerStyle || {},
118
135
  ];
119
136
 
120
137
  return (
@@ -122,9 +139,20 @@ export default class Pagination extends PureComponent {
122
139
  pointerEvents="box-none"
123
140
  style={style}
124
141
  accessible={!!accessibilityLabel}
125
- accessibilityLabel={accessibilityLabel}
126
- >
127
- { this.dots }
142
+ accessibilityLabel={accessibilityLabel}>
143
+ <View
144
+ style={[
145
+ {
146
+ flexDirection: 'row',
147
+ padding: Spacing.XS,
148
+ borderRadius: Radius.S,
149
+ },
150
+ type === 'light'
151
+ ? {}
152
+ : { backgroundColor: Colors.opacity_02_white_20 },
153
+ ]}>
154
+ {this.dots}
155
+ </View>
128
156
  </View>
129
157
  );
130
158
  }
@@ -147,12 +175,14 @@ Pagination.propTypes = {
147
175
  vertical: PropTypes.bool,
148
176
  accessibilityLabel: PropTypes.string,
149
177
  containerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
150
- dotContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
178
+ dotContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
179
+ type: PropTypes.oneOf(['light', 'dark']),
151
180
  };
152
181
 
153
182
  Pagination.defaultProps = {
154
183
  inactiveDotOpacity: 0.5,
155
184
  inactiveDotScale: 0.5,
156
185
  tappableDots: false,
157
- vertical: false
186
+ vertical: false,
187
+ type: 'light',
158
188
  };
@@ -1,9 +1,8 @@
1
1
  import React, { PureComponent } from 'react';
2
- import {
3
- Animated, Easing, TouchableOpacity
4
- } from 'react-native';
2
+ import { Animated, Easing, TouchableOpacity } from 'react-native';
5
3
  import PropTypes from 'prop-types';
6
4
  import styles from './styles';
5
+ import { Colors } from '@momo-kits/core-v2';
7
6
 
8
7
  export default class PaginationDot extends PureComponent {
9
8
  constructor(props) {
@@ -11,10 +10,15 @@ export default class PaginationDot extends PureComponent {
11
10
  this.state = {
12
11
  animColor: new Animated.Value(0),
13
12
  animOpacity: new Animated.Value(0),
14
- animTransform: new Animated.Value(0)
13
+ animTransform: new Animated.Value(0),
15
14
  };
16
15
  }
17
16
 
17
+ get _shouldAnimateColor() {
18
+ const { color, inactiveColor } = this.props;
19
+ return color && inactiveColor;
20
+ }
21
+
18
22
  componentDidMount() {
19
23
  const { active } = this.props;
20
24
  if (active) {
@@ -36,36 +40,33 @@ export default class PaginationDot extends PureComponent {
36
40
  toValue,
37
41
  duration: 250,
38
42
  isInteraction: false,
39
- useNativeDriver: false
43
+ useNativeDriver: false,
40
44
  };
41
45
 
42
46
  const animations = [
43
47
  Animated.timing(animOpacity, {
44
48
  easing: Easing.linear,
45
- ...commonProperties
49
+ ...commonProperties,
46
50
  }),
47
51
  Animated.spring(animTransform, {
48
- friction: 4,
52
+ // friction: 4,
49
53
  tension: 50,
50
- ...commonProperties
51
- })
54
+ ...commonProperties,
55
+ }),
52
56
  ];
53
57
 
54
58
  if (this._shouldAnimateColor) {
55
- animations.push(Animated.timing(animColor, {
56
- easing: Easing.linear,
57
- ...commonProperties
58
- }));
59
+ animations.push(
60
+ Animated.timing(animColor, {
61
+ easing: Easing.linear,
62
+ ...commonProperties,
63
+ }),
64
+ );
59
65
  }
60
66
 
61
67
  Animated.parallel(animations).start();
62
68
  }
63
69
 
64
- get _shouldAnimateColor() {
65
- const { color, inactiveColor } = this.props;
66
- return color && inactiveColor;
67
- }
68
-
69
70
  render() {
70
71
  const { animColor, animOpacity, animTransform } = this.state;
71
72
  const {
@@ -77,53 +78,59 @@ export default class PaginationDot extends PureComponent {
77
78
  inactiveColor,
78
79
  inactiveStyle,
79
80
  inactiveOpacity,
80
- inactiveScale,
81
81
  index,
82
82
  style,
83
- tappable
83
+ tappable,
84
+ type,
84
85
  } = this.props;
85
86
 
86
87
  const animatedStyle = {
87
88
  opacity: animOpacity.interpolate({
88
89
  inputRange: [0, 1],
89
- outputRange: [inactiveOpacity, 1]
90
+ outputRange: [inactiveOpacity, 1],
90
91
  }),
91
- transform: [{
92
- scale: animTransform.interpolate({
93
- inputRange: [0, 1],
94
- outputRange: [inactiveScale, 1]
95
- })
96
- }]
97
- };
98
- const animatedColor = this._shouldAnimateColor ? {
99
- backgroundColor: animColor.interpolate({
92
+ width: animTransform.interpolate({
100
93
  inputRange: [0, 1],
101
- outputRange: [inactiveColor, color]
102
- })
103
- } : {};
94
+ outputRange: [4, 12],
95
+ }),
96
+ };
97
+ const animatedColor = this._shouldAnimateColor
98
+ ? {
99
+ backgroundColor: animColor.interpolate({
100
+ inputRange: [0, 1],
101
+ outputRange: [inactiveColor, color],
102
+ }),
103
+ }
104
+ : {};
104
105
 
105
106
  const dotContainerStyle = [
106
107
  styles.sliderPaginationDotContainer,
107
- containerStyle || {}
108
+ containerStyle || {},
108
109
  ];
109
110
 
110
111
  const dotStyle = [
111
112
  styles.sliderPaginationDot,
112
113
  style || {},
113
114
  (!active && inactiveStyle) || {},
115
+ !active && { backgroundColor: Colors.black_10 },
114
116
  animatedStyle,
115
- animatedColor
117
+ type === 'light'
118
+ ? animatedColor
119
+ : { backgroundColor: Colors.black_01 },
116
120
  ];
117
121
 
118
- const onPress = tappable ? () => carouselRef && carouselRef._snapToItem(carouselRef._getPositionIndex(index)) : undefined;
122
+ const onPress = tappable
123
+ ? () =>
124
+ carouselRef &&
125
+ carouselRef._snapToItem(carouselRef._getPositionIndex(index))
126
+ : undefined;
119
127
 
120
128
  return (
121
129
  <TouchableOpacity
122
130
  accessible={false}
123
131
  style={dotContainerStyle}
124
132
  activeOpacity={tappable ? activeOpacity : 1}
125
- onPress={onPress}
126
- >
133
+ onPress={onPress}>
127
134
  <Animated.View style={dotStyle} />
128
135
  </TouchableOpacity>
129
136
  );
@@ -131,7 +138,6 @@ export default class PaginationDot extends PureComponent {
131
138
  }
132
139
  PaginationDot.propTypes = {
133
140
  inactiveOpacity: PropTypes.number.isRequired,
134
- inactiveScale: PropTypes.number.isRequired,
135
141
  active: PropTypes.bool,
136
142
  activeOpacity: PropTypes.number,
137
143
  carouselRef: PropTypes.object,
@@ -1,24 +1,24 @@
1
1
  import { StyleSheet } from 'react-native';
2
+ import { Colors, Spacing } from '@momo-kits/core-v2';
2
3
 
3
- const DEFAULT_DOT_SIZE = 7;
4
- const DEFAULT_DOT_COLOR = 'rgba(0, 0, 0, 0.75)';
4
+ const DEFAULT_DOT_SIZE = 4;
5
+ const DEFAULT_DOT_COLOR = Colors.pink_03;
5
6
 
6
7
  export default StyleSheet.create({
7
8
  sliderPagination: {
8
9
  alignItems: 'center',
9
10
  justifyContent: 'center',
10
11
  paddingHorizontal: 20,
11
- // paddingVertical: 30
12
12
  },
13
13
  sliderPaginationDotContainer: {
14
14
  alignItems: 'center',
15
15
  justifyContent: 'center',
16
- marginHorizontal: 8
16
+ marginHorizontal: Spacing.XS,
17
17
  },
18
18
  sliderPaginationDot: {
19
19
  width: DEFAULT_DOT_SIZE,
20
20
  height: DEFAULT_DOT_SIZE,
21
21
  borderRadius: DEFAULT_DOT_SIZE / 2,
22
- backgroundColor: DEFAULT_DOT_COLOR
23
- }
22
+ backgroundColor: DEFAULT_DOT_COLOR,
23
+ },
24
24
  });
@@ -1,5 +1,4 @@
1
- import {Platform, Animated} from 'react-native';
2
-
1
+ import { Platform, Animated } from 'react-native';
3
2
  const IS_ANDROID = Platform.OS === 'android';
4
3
 
5
4
  // Get scroll interpolator's input range from an array of slide indexes
@@ -12,105 +11,116 @@ const IS_ANDROID = Platform.OS === 'android';
12
11
  // index * sizeRef, // active
13
12
  // (index + 1) * sizeRef // active - 1
14
13
  // ]
15
- export function getInputRangeFromIndexes(range, index, carouselProps) {
16
- const sizeRef = carouselProps.vertical
17
- ? carouselProps.itemHeight
18
- : carouselProps.itemWidth;
19
- const inputRange = [];
14
+ export function getInputRangeFromIndexes (
15
+ range,
16
+ index,
17
+ carouselProps
18
+ ) {
19
+ const sizeRef = carouselProps.vertical ?
20
+ carouselProps.itemHeight :
21
+ carouselProps.itemWidth;
22
+ const inputRange = [];
20
23
 
21
- for (let i = 0; i < range.length; i++) {
22
- inputRange.push((index - range[i]) * sizeRef);
23
- }
24
+ for (let i = 0; i < range.length; i++) {
25
+ inputRange.push((index - range[i]) * sizeRef);
26
+ }
24
27
 
25
- return inputRange;
28
+ return inputRange;
26
29
  }
27
30
 
28
31
  // Default behavior
29
32
  // Scale and/or opacity effect
30
33
  // Based on props 'inactiveSlideOpacity' and 'inactiveSlideScale'
31
- export function defaultScrollInterpolator(index, carouselProps) {
32
- const range = [1, 0, -1];
33
- const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
34
- const outputRange = [0, 1, 0];
34
+ export function defaultScrollInterpolator (
35
+ index,
36
+ carouselProps
37
+ ) {
38
+ const range = [1, 0, -1];
39
+ const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
40
+ const outputRange = [0, 1, 0];
35
41
 
36
- return {
37
- inputRange,
38
- outputRange,
39
- };
42
+ return { inputRange, outputRange };
40
43
  }
41
-
42
- export function defaultAnimatedStyles(_index, animatedValue, carouselProps) {
43
- let animatedOpacity = {};
44
- let animatedScale = {};
45
-
46
- if (carouselProps.inactiveSlideOpacity < 1) {
47
- animatedOpacity = {
48
- opacity: animatedValue.interpolate({
49
- inputRange: [0, 1],
50
- outputRange: [carouselProps.inactiveSlideOpacity, 1],
51
- }),
52
- };
53
- }
54
-
55
- if (carouselProps.inactiveSlideScale < 1) {
56
- animatedScale = {
57
- transform: [
58
- {
59
- scale: animatedValue.interpolate({
60
- inputRange: [0, 1],
61
- outputRange: [carouselProps.inactiveSlideScale, 1],
62
- }),
63
- },
64
- ],
44
+ export function defaultAnimatedStyles (
45
+ _index,
46
+ animatedValue,
47
+ carouselProps
48
+ ) {
49
+ let animatedOpacity = {};
50
+ let animatedScale = {};
51
+
52
+ if (carouselProps.inactiveSlideOpacity < 1) {
53
+ animatedOpacity = {
54
+ opacity: animatedValue.interpolate({
55
+ inputRange: [0, 1],
56
+ outputRange: [carouselProps.inactiveSlideOpacity, 1]
57
+ })
58
+ };
59
+ }
60
+
61
+ if (carouselProps.inactiveSlideScale < 1) {
62
+ animatedScale = {
63
+ transform: [
64
+ {
65
+ scale: animatedValue.interpolate({
66
+ inputRange: [0, 1],
67
+ outputRange: [carouselProps.inactiveSlideScale, 1]
68
+ })
69
+ }
70
+ ]
71
+ };
72
+ }
73
+
74
+ return {
75
+ ...animatedOpacity,
76
+ ...animatedScale
65
77
  };
66
- }
67
-
68
- return {
69
- ...animatedOpacity,
70
- ...animatedScale,
71
- };
72
78
  }
73
79
 
74
80
  // Shift animation
75
81
  // Same as the default one, but the active slide is also shifted up or down
76
82
  // Based on prop 'inactiveSlideShift'
77
- export function shiftAnimatedStyles(_index, animatedValue, carouselProps) {
78
- let animatedOpacity = {};
79
- let animatedScale = {};
80
- let animatedTranslate = {};
81
-
82
- if (carouselProps.inactiveSlideOpacity < 1) {
83
- animatedOpacity = {
84
- opacity: animatedValue.interpolate({
85
- inputRange: [0, 1],
86
- outputRange: [carouselProps.inactiveSlideOpacity, 1],
87
- }),
88
- };
89
- }
90
-
91
- if (carouselProps.inactiveSlideScale < 1) {
92
- animatedScale = {
93
- scale: animatedValue.interpolate({
94
- inputRange: [0, 1],
95
- outputRange: [carouselProps.inactiveSlideScale, 1],
96
- }),
97
- };
98
- }
99
-
100
- if (carouselProps.inactiveSlideShift !== 0) {
101
- const translateProp = carouselProps.vertical ? 'translateX' : 'translateY';
102
- animatedTranslate = {
103
- [translateProp]: animatedValue.interpolate({
104
- inputRange: [0, 1],
105
- outputRange: [carouselProps.inactiveSlideShift, 0],
106
- }),
83
+ export function shiftAnimatedStyles (
84
+ _index,
85
+ animatedValue,
86
+ carouselProps
87
+ ) {
88
+ let animatedOpacity = {};
89
+ let animatedScale = {};
90
+ let animatedTranslate = {};
91
+
92
+ if (carouselProps.inactiveSlideOpacity < 1) {
93
+ animatedOpacity = {
94
+ opacity: animatedValue.interpolate({
95
+ inputRange: [0, 1],
96
+ outputRange: [carouselProps.inactiveSlideOpacity, 1]
97
+ })
98
+ };
99
+ }
100
+
101
+ if (carouselProps.inactiveSlideScale < 1) {
102
+ animatedScale = {
103
+ scale: animatedValue.interpolate({
104
+ inputRange: [0, 1],
105
+ outputRange: [carouselProps.inactiveSlideScale, 1]
106
+ })
107
+ };
108
+ }
109
+
110
+ if (carouselProps.inactiveSlideShift !== 0) {
111
+ const translateProp = carouselProps.vertical ? 'translateX' : 'translateY';
112
+ animatedTranslate = {
113
+ [translateProp]: animatedValue.interpolate({
114
+ inputRange: [0, 1],
115
+ outputRange: [carouselProps.inactiveSlideShift, 0]
116
+ })
117
+ };
118
+ }
119
+
120
+ return {
121
+ ...animatedOpacity,
122
+ transform: [{ ...animatedScale }, { ...animatedTranslate }]
107
123
  };
108
- }
109
-
110
- return {
111
- ...animatedOpacity,
112
- transform: [{...animatedScale}, {...animatedTranslate}],
113
- };
114
124
  }
115
125
 
116
126
  // Stack animation
@@ -118,75 +128,107 @@ export function shiftAnimatedStyles(_index, animatedValue, carouselProps) {
118
128
  // WARNING: The effect had to be visually inverted on Android because this OS doesn't honor the `zIndex`property
119
129
  // This means that the item with the higher zIndex (and therefore the tap receiver) remains the one AFTER the currently active item
120
130
  // The `elevation` property compensates for that only visually, which is not good enough
121
- export function stackScrollInterpolator(index, carouselProps) {
122
- const range = [3, 2, 1, 0, -1];
123
- const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
124
- const outputRange = range;
131
+ export function stackScrollInterpolator (
132
+ index,
133
+ carouselProps
134
+ ) {
135
+ const range = IS_ANDROID ? [1, 0, -1, -2, -3] : [3, 2, 1, 0, -1];
136
+ const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
137
+ const outputRange = range;
125
138
 
126
- return {
127
- inputRange,
128
- outputRange,
129
- };
139
+ return { inputRange, outputRange };
130
140
  }
131
-
132
- export function stackAnimatedStyles(
133
- index,
134
- animatedValue,
135
- carouselProps,
136
- cardOffset,
141
+ export function stackAnimatedStyles (
142
+ index,
143
+ animatedValue,
144
+ carouselProps,
145
+ cardOffset
137
146
  ) {
138
- const sizeRef = carouselProps.vertical
139
- ? carouselProps.itemHeight
140
- : carouselProps.itemWidth;
141
- const translateProp = carouselProps.vertical ? 'translateY' : 'translateX';
147
+ const sizeRef = carouselProps.vertical ?
148
+ carouselProps.itemHeight :
149
+ carouselProps.itemWidth;
150
+ const translateProp = carouselProps.vertical ? 'translateY' : 'translateX';
142
151
 
143
- const card1Scale = 0.9;
144
- const card2Scale = 0.8;
152
+ const card1Scale = 0.9;
153
+ const card2Scale = 0.8;
145
154
 
146
- const newCardOffset = cardOffset ?? 18;
155
+ const newCardOffset = cardOffset ?? 18;
147
156
 
148
- const getTranslateFromScale = (cardIndex, scale) => {
149
- const centerFactor = (1 / scale) * cardIndex;
150
- const centeredPosition = -Math.round(sizeRef * centerFactor);
151
- const edgeAlignment = Math.round((sizeRef - sizeRef * scale) / 2);
152
- const offset = Math.round((newCardOffset * Math.abs(cardIndex)) / scale);
157
+ const getTranslateFromScale = (cardIndex, scale) => {
158
+ const centerFactor = (1 / scale) * cardIndex;
159
+ const centeredPosition = -Math.round(sizeRef * centerFactor);
160
+ const edgeAlignment = Math.round((sizeRef - sizeRef * scale) / 2);
161
+ const offset = Math.round((newCardOffset * Math.abs(cardIndex)) / scale);
153
162
 
154
- return centeredPosition + edgeAlignment + offset;
155
- };
163
+ return IS_ANDROID ?
164
+ centeredPosition - edgeAlignment - offset :
165
+ centeredPosition + edgeAlignment + offset;
166
+ };
156
167
 
157
- const opacityOutputRange =
168
+ const opacityOutputRange =
158
169
  carouselProps.inactiveSlideOpacity === 1 ? [1, 1, 1, 0] : [1, 0.75, 0.5, 0];
159
170
 
160
- return {
161
- zIndex: carouselProps.data.length - index,
162
- opacity: animatedValue.interpolate({
163
- inputRange: [0, 1, 2, 3],
164
- outputRange: opacityOutputRange,
165
- extrapolate: 'clamp',
166
- }),
167
- transform: [
168
- {
169
- scale: animatedValue.interpolate({
170
- inputRange: [-1, 0, 1, 2],
171
- outputRange: [card1Scale, 1, card1Scale, card2Scale],
172
- extrapolate: 'clamp',
173
- }),
174
- },
175
- {
176
- [translateProp]: animatedValue.interpolate({
177
- inputRange: [-1, 0, 1, 2, 3],
178
- outputRange: [
179
- -sizeRef * 0.5,
180
- 0,
181
- getTranslateFromScale(1, card1Scale),
182
- getTranslateFromScale(2, card2Scale),
183
- getTranslateFromScale(3, card2Scale),
184
- ],
185
- extrapolate: 'clamp',
186
- }),
187
- },
188
- ],
189
- };
171
+ return IS_ANDROID ?
172
+ {
173
+ // elevation.data.length - index, // fix zIndex bug visually, but not from a logic point of view
174
+ opacity: animatedValue.interpolate({
175
+ inputRange: [-3, -2, -1, 0],
176
+ outputRange: opacityOutputRange.reverse(),
177
+ extrapolate: 'clamp'
178
+ }),
179
+ transform: [
180
+ {
181
+ scale: animatedValue.interpolate({
182
+ inputRange: [-2, -1, 0, 1],
183
+ outputRange: [card2Scale, card1Scale, 1, card1Scale],
184
+ extrapolate: 'clamp'
185
+ })
186
+ },
187
+ {
188
+ [translateProp]: animatedValue.interpolate({
189
+ inputRange: [-3, -2, -1, 0, 1],
190
+ outputRange: [
191
+ getTranslateFromScale(-3, card2Scale),
192
+ getTranslateFromScale(-2, card2Scale),
193
+ getTranslateFromScale(-1, card1Scale),
194
+ 0,
195
+ sizeRef * 0.5
196
+ ],
197
+ extrapolate: 'clamp'
198
+ })
199
+ }
200
+ ]
201
+ } :
202
+ {
203
+ zIndex: carouselProps.data.length - index,
204
+ opacity: animatedValue.interpolate({
205
+ inputRange: [0, 1, 2, 3],
206
+ outputRange: opacityOutputRange,
207
+ extrapolate: 'clamp'
208
+ }),
209
+ transform: [
210
+ {
211
+ scale: animatedValue.interpolate({
212
+ inputRange: [-1, 0, 1, 2],
213
+ outputRange: [card1Scale, 1, card1Scale, card2Scale],
214
+ extrapolate: 'clamp'
215
+ })
216
+ },
217
+ {
218
+ [translateProp]: animatedValue.interpolate({
219
+ inputRange: [-1, 0, 1, 2, 3],
220
+ outputRange: [
221
+ -sizeRef * 0.5,
222
+ 0,
223
+ getTranslateFromScale(1, card1Scale),
224
+ getTranslateFromScale(2, card2Scale),
225
+ getTranslateFromScale(3, card2Scale)
226
+ ],
227
+ extrapolate: 'clamp'
228
+ })
229
+ }
230
+ ]
231
+ };
190
232
  }
191
233
 
192
234
  // Tinder animation
@@ -194,147 +236,146 @@ export function stackAnimatedStyles(
194
236
  // WARNING: The effect had to be visually inverted on Android because this OS doesn't honor the `zIndex`property
195
237
  // This means that the item with the higher zIndex (and therefore the tap receiver) remains the one AFTER the currently active item
196
238
  // The `elevation` property compensates for that only visually, which is not good enough
197
- export function tinderScrollInterpolator(index, carouselProps) {
198
- const range = IS_ANDROID ? [1, 0, -1, -2, -3] : [3, 2, 1, 0, -1];
199
- const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
200
- const outputRange = range;
239
+ export function tinderScrollInterpolator (
240
+ index,
241
+ carouselProps
242
+ ) {
243
+ const range = IS_ANDROID ? [1, 0, -1, -2, -3] : [3, 2, 1, 0, -1];
244
+ const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
245
+ const outputRange = range;
201
246
 
202
- return {
203
- inputRange,
204
- outputRange,
205
- };
247
+ return { inputRange, outputRange };
206
248
  }
207
-
208
- export function tinderAnimatedStyles(
209
- index,
210
- animatedValue,
211
- carouselProps,
212
- cardOffset,
249
+ export function tinderAnimatedStyles (
250
+ index,
251
+ animatedValue,
252
+ carouselProps,
253
+ cardOffset
213
254
  ) {
214
- const sizeRef = carouselProps.vertical
215
- ? carouselProps.itemHeight
216
- : carouselProps.itemWidth;
217
- const mainTranslateProp = carouselProps.vertical
218
- ? 'translateY'
219
- : 'translateX';
220
- const secondaryTranslateProp = carouselProps.vertical
221
- ? 'translateX'
222
- : 'translateY';
223
-
224
- const card1Scale = 0.96;
225
- const card2Scale = 0.92;
226
- const card3Scale = 0.88;
227
-
228
- const peekingCardsOpacity = IS_ANDROID ? 0.92 : 1;
229
-
230
- const newCardOffset = cardOffset ?? 9;
231
-
232
- const getMainTranslateFromScale = (cardIndex, scale) => {
233
- const centerFactor = (1 / scale) * cardIndex;
234
- return -Math.round(sizeRef * centerFactor);
235
- };
255
+ const sizeRef = carouselProps.vertical ?
256
+ carouselProps.itemHeight :
257
+ carouselProps.itemWidth;
258
+ const mainTranslateProp = carouselProps.vertical ?
259
+ 'translateY' :
260
+ 'translateX';
261
+ const secondaryTranslateProp = carouselProps.vertical ?
262
+ 'translateX' :
263
+ 'translateY';
264
+
265
+ const card1Scale = 0.96;
266
+ const card2Scale = 0.92;
267
+ const card3Scale = 0.88;
268
+
269
+ const peekingCardsOpacity = IS_ANDROID ? 0.92 : 1;
270
+
271
+ const newCardOffset = cardOffset ?? 9;
272
+
273
+ const getMainTranslateFromScale = (cardIndex, scale) => {
274
+ const centerFactor = (1 / scale) * cardIndex;
275
+ return -Math.round(sizeRef * centerFactor);
276
+ };
236
277
 
237
- const getSecondaryTranslateFromScale = (cardIndex, scale) => {
238
- return Math.round((newCardOffset * Math.abs(cardIndex)) / scale);
239
- };
278
+ const getSecondaryTranslateFromScale = (cardIndex, scale) => {
279
+ return Math.round((newCardOffset * Math.abs(cardIndex)) / scale);
280
+ };
240
281
 
241
- return IS_ANDROID
242
- ? {
282
+ return IS_ANDROID ?
283
+ {
243
284
  // elevation.data.length - index, // fix zIndex bug visually, but not from a logic point of view
244
- opacity: animatedValue.interpolate({
245
- inputRange: [-3, -2, -1, 0, 1],
246
- outputRange: [0, peekingCardsOpacity, peekingCardsOpacity, 1, 0],
247
- extrapolate: 'clamp',
248
- }),
249
- transform: [
250
- {
251
- scale: animatedValue.interpolate({
252
- inputRange: [-3, -2, -1, 0],
253
- outputRange: [card3Scale, card2Scale, card1Scale, 1],
254
- extrapolate: 'clamp',
255
- }),
256
- },
257
- {
258
- rotate: animatedValue.interpolate({
259
- inputRange: [0, 1],
260
- outputRange: ['0deg', '22deg'],
261
- extrapolate: 'clamp',
262
- }),
263
- },
264
- {
265
- [mainTranslateProp]: animatedValue.interpolate({
266
- inputRange: [-3, -2, -1, 0, 1],
267
- outputRange: [
268
- getMainTranslateFromScale(-3, card3Scale),
269
- getMainTranslateFromScale(-2, card2Scale),
270
- getMainTranslateFromScale(-1, card1Scale),
271
- 0,
272
- sizeRef * 1.1,
273
- ],
274
- extrapolate: 'clamp',
275
- }),
276
- },
277
- {
278
- [secondaryTranslateProp]: animatedValue.interpolate({
279
- inputRange: [-3, -2, -1, 0],
280
- outputRange: [
281
- getSecondaryTranslateFromScale(-3, card3Scale),
282
- getSecondaryTranslateFromScale(-2, card2Scale),
283
- getSecondaryTranslateFromScale(-1, card1Scale),
284
- 0,
285
- ],
286
- extrapolate: 'clamp',
285
+ opacity: animatedValue.interpolate({
286
+ inputRange: [-3, -2, -1, 0, 1],
287
+ outputRange: [0, peekingCardsOpacity, peekingCardsOpacity, 1, 0],
288
+ extrapolate: 'clamp'
287
289
  }),
288
- },
289
- ],
290
- }
291
- : {
292
- zIndex: carouselProps.data.length - index,
293
- opacity: animatedValue.interpolate({
294
- inputRange: [-1, 0, 1, 2, 3],
295
- outputRange: [0, 1, peekingCardsOpacity, peekingCardsOpacity, 0],
296
- extrapolate: 'clamp',
297
- }),
298
- transform: [
299
- {
300
- scale: animatedValue.interpolate({
301
- inputRange: [0, 1, 2, 3],
302
- outputRange: [1, card1Scale, card2Scale, card3Scale],
303
- extrapolate: 'clamp',
304
- }),
305
- },
306
- {
307
- rotate: animatedValue.interpolate({
308
- inputRange: [-1, 0],
309
- outputRange: ['-22deg', '0deg'],
310
- extrapolate: 'clamp',
311
- }),
312
- },
313
- {
314
- [mainTranslateProp]: animatedValue.interpolate({
315
- inputRange: [-1, 0, 1, 2, 3],
316
- outputRange: [
317
- -sizeRef * 1.1,
318
- 0,
319
- getMainTranslateFromScale(1, card1Scale),
320
- getMainTranslateFromScale(2, card2Scale),
321
- getMainTranslateFromScale(3, card3Scale),
322
- ],
323
- extrapolate: 'clamp',
324
- }),
325
- },
326
- {
327
- [secondaryTranslateProp]: animatedValue.interpolate({
328
- inputRange: [0, 1, 2, 3],
329
- outputRange: [
330
- 0,
331
- getSecondaryTranslateFromScale(1, card1Scale),
332
- getSecondaryTranslateFromScale(2, card2Scale),
333
- getSecondaryTranslateFromScale(3, card3Scale),
334
- ],
335
- extrapolate: 'clamp',
290
+ transform: [
291
+ {
292
+ scale: animatedValue.interpolate({
293
+ inputRange: [-3, -2, -1, 0],
294
+ outputRange: [card3Scale, card2Scale, card1Scale, 1],
295
+ extrapolate: 'clamp'
296
+ })
297
+ },
298
+ {
299
+ rotate: animatedValue.interpolate({
300
+ inputRange: [0, 1],
301
+ outputRange: ['0deg', '22deg'],
302
+ extrapolate: 'clamp'
303
+ })
304
+ },
305
+ {
306
+ [mainTranslateProp]: animatedValue.interpolate({
307
+ inputRange: [-3, -2, -1, 0, 1],
308
+ outputRange: [
309
+ getMainTranslateFromScale(-3, card3Scale),
310
+ getMainTranslateFromScale(-2, card2Scale),
311
+ getMainTranslateFromScale(-1, card1Scale),
312
+ 0,
313
+ sizeRef * 1.1
314
+ ],
315
+ extrapolate: 'clamp'
316
+ })
317
+ },
318
+ {
319
+ [secondaryTranslateProp]: animatedValue.interpolate({
320
+ inputRange: [-3, -2, -1, 0],
321
+ outputRange: [
322
+ getSecondaryTranslateFromScale(-3, card3Scale),
323
+ getSecondaryTranslateFromScale(-2, card2Scale),
324
+ getSecondaryTranslateFromScale(-1, card1Scale),
325
+ 0
326
+ ],
327
+ extrapolate: 'clamp'
328
+ })
329
+ }
330
+ ]
331
+ } :
332
+ {
333
+ zIndex: carouselProps.data.length - index,
334
+ opacity: animatedValue.interpolate({
335
+ inputRange: [-1, 0, 1, 2, 3],
336
+ outputRange: [0, 1, peekingCardsOpacity, peekingCardsOpacity, 0],
337
+ extrapolate: 'clamp'
336
338
  }),
337
- },
338
- ],
339
- };
339
+ transform: [
340
+ {
341
+ scale: animatedValue.interpolate({
342
+ inputRange: [0, 1, 2, 3],
343
+ outputRange: [1, card1Scale, card2Scale, card3Scale],
344
+ extrapolate: 'clamp'
345
+ })
346
+ },
347
+ {
348
+ rotate: animatedValue.interpolate({
349
+ inputRange: [-1, 0],
350
+ outputRange: ['-22deg', '0deg'],
351
+ extrapolate: 'clamp'
352
+ })
353
+ },
354
+ {
355
+ [mainTranslateProp]: animatedValue.interpolate({
356
+ inputRange: [-1, 0, 1, 2, 3],
357
+ outputRange: [
358
+ -sizeRef * 1.1,
359
+ 0,
360
+ getMainTranslateFromScale(1, card1Scale),
361
+ getMainTranslateFromScale(2, card2Scale),
362
+ getMainTranslateFromScale(3, card3Scale)
363
+ ],
364
+ extrapolate: 'clamp'
365
+ })
366
+ },
367
+ {
368
+ [secondaryTranslateProp]: animatedValue.interpolate({
369
+ inputRange: [0, 1, 2, 3],
370
+ outputRange: [
371
+ 0,
372
+ getSecondaryTranslateFromScale(1, card1Scale),
373
+ getSecondaryTranslateFromScale(2, card2Scale),
374
+ getSecondaryTranslateFromScale(3, card3Scale)
375
+ ],
376
+ extrapolate: 'clamp'
377
+ })
378
+ }
379
+ ]
380
+ };
340
381
  }