@momo-kits/carousel 0.0.65-beta → 0.0.65-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.
- package/Carousel.js +242 -263
- package/CarouselV2.js +1380 -0
- package/index.js +3 -4
- package/package.json +15 -14
- package/pagination/NumberPagination.js +43 -0
- package/pagination/Pagination.js +64 -34
- package/pagination/PaginationDot.js +45 -39
- package/pagination/styles.js +6 -6
- package/publish.sh +1 -1
- package/utils/animationsV2.js +381 -0
package/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import Carousel from './
|
|
1
|
+
import Carousel from './CarouselV2';
|
|
2
2
|
import Pagination from './pagination/Pagination';
|
|
3
|
+
import NumberPagination from './pagination/NumberPagination';
|
|
3
4
|
|
|
4
|
-
export {
|
|
5
|
-
Carousel, Pagination
|
|
6
|
-
};
|
|
5
|
+
export {Carousel, Pagination, NumberPagination};
|
package/package.json
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
2
|
+
"name": "@momo-kits/carousel",
|
|
3
|
+
"version": "0.0.65-beta.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
|
+
"@momo-kits/core-v2": ">=0.0.4-beta"
|
|
14
|
+
},
|
|
15
|
+
"devDependencies": {},
|
|
16
|
+
"license": "MoMo"
|
|
16
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;
|
package/pagination/Pagination.js
CHANGED
|
@@ -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 (
|
|
16
|
+
if (
|
|
17
|
+
(props.dotColor && !props.inactiveDotColor) ||
|
|
18
|
+
(!props.dotColor && props.inactiveDotColor)
|
|
19
|
+
) {
|
|
18
20
|
console.warn(
|
|
19
|
-
'react-native-snap-carousel | Pagination: '
|
|
20
|
-
|
|
21
|
+
'react-native-snap-carousel | Pagination: ' +
|
|
22
|
+
'You need to specify both `dotColor` and `inactiveDotColor`',
|
|
21
23
|
);
|
|
22
24
|
}
|
|
23
|
-
if (
|
|
25
|
+
if (
|
|
26
|
+
(props.dotElement && !props.inactiveDotElement) ||
|
|
27
|
+
(!props.dotElement && props.inactiveDotElement)
|
|
28
|
+
) {
|
|
24
29
|
console.warn(
|
|
25
|
-
'react-native-snap-carousel | Pagination: '
|
|
26
|
-
|
|
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
|
-
|
|
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()
|
|
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(
|
|
89
|
-
(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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,
|
|
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
|
-
:
|
|
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
|
-
|
|
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:
|
|
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(
|
|
56
|
-
|
|
57
|
-
|
|
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
|
-
|
|
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: [
|
|
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
|
-
|
|
117
|
+
type === 'light'
|
|
118
|
+
? animatedColor
|
|
119
|
+
: { backgroundColor: Colors.black_01 },
|
|
116
120
|
];
|
|
117
121
|
|
|
118
|
-
const onPress = tappable
|
|
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,
|
package/pagination/styles.js
CHANGED
|
@@ -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 =
|
|
4
|
-
const DEFAULT_DOT_COLOR =
|
|
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:
|
|
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
|
});
|