@momo-kits/carousel 0.0.62-alpha.15 → 0.0.62-alpha.17
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 +2 -4
- package/package.json +3 -2
- package/pagination/NumberPagination.js +31 -0
- package/pagination/Pagination.js +45 -36
- package/pagination/PaginationDot.js +42 -37
- package/pagination/styles.js +6 -6
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,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@momo-kits/carousel",
|
|
3
|
-
"version": "0.0.62-alpha.
|
|
3
|
+
"version": "0.0.62-alpha.17",
|
|
4
4
|
"private": false,
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"dependencies": {
|
|
@@ -9,7 +9,8 @@
|
|
|
9
9
|
},
|
|
10
10
|
"peerDependencies": {
|
|
11
11
|
"react": "16.9.0",
|
|
12
|
-
"react-native": ">=0.55"
|
|
12
|
+
"react-native": ">=0.55",
|
|
13
|
+
"@momo-kits/core-v2": ">=0.0.4-beta"
|
|
13
14
|
},
|
|
14
15
|
"devDependencies": {},
|
|
15
16
|
"license": "MoMo"
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Colors, Radius, Spacing, Text } from '@momo-kits/core-v2';
|
|
3
|
+
import { View, StyleSheet } from 'react-native';
|
|
4
|
+
|
|
5
|
+
const NumberPagination = (props) => {
|
|
6
|
+
const { dataLength, activeIndex, style } = props;
|
|
7
|
+
|
|
8
|
+
return (
|
|
9
|
+
<View style={style}>
|
|
10
|
+
<View style={styles.container}>
|
|
11
|
+
<Text.Label1 style={styles.number}>{`${
|
|
12
|
+
activeIndex + 1
|
|
13
|
+
}/${dataLength}`}</Text.Label1>
|
|
14
|
+
</View>
|
|
15
|
+
</View>
|
|
16
|
+
);
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const styles = StyleSheet.create({
|
|
20
|
+
container: {
|
|
21
|
+
backgroundColor: Colors.black_08,
|
|
22
|
+
alignSelf: 'baseline',
|
|
23
|
+
paddingHorizontal: Spacing.S,
|
|
24
|
+
borderRadius: Radius.M,
|
|
25
|
+
},
|
|
26
|
+
number: {
|
|
27
|
+
color: Colors.black_01,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
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 } 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,7 @@ export default class Pagination extends PureComponent {
|
|
|
59
61
|
inactiveDotScale,
|
|
60
62
|
inactiveDotStyle,
|
|
61
63
|
renderDots,
|
|
62
|
-
tappableDots
|
|
64
|
+
tappableDots,
|
|
63
65
|
} = this.props;
|
|
64
66
|
|
|
65
67
|
if (renderDots) {
|
|
@@ -85,23 +87,29 @@ export default class Pagination extends PureComponent {
|
|
|
85
87
|
|
|
86
88
|
for (let i = 0; i < dotsLength; i += 1) {
|
|
87
89
|
const isActive = i === this._activeDotIndex;
|
|
88
|
-
dots.push(
|
|
89
|
-
(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
90
|
+
dots.push(
|
|
91
|
+
React.cloneElement(
|
|
92
|
+
(isActive ? dotElement : inactiveDotElement) || DefaultDot,
|
|
93
|
+
{
|
|
94
|
+
key: `pagination-dot-${i}`,
|
|
95
|
+
active: i === this._activeDotIndex,
|
|
96
|
+
index: i,
|
|
97
|
+
},
|
|
98
|
+
),
|
|
99
|
+
);
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
return dots;
|
|
99
103
|
}
|
|
100
104
|
|
|
105
|
+
_needsRTLAdaptations() {
|
|
106
|
+
const { vertical } = this.props;
|
|
107
|
+
return IS_RTL && !IS_IOS && !vertical;
|
|
108
|
+
}
|
|
109
|
+
|
|
101
110
|
render() {
|
|
102
|
-
const {
|
|
103
|
-
|
|
104
|
-
} = this.props;
|
|
111
|
+
const { dotsLength, containerStyle, vertical, accessibilityLabel } =
|
|
112
|
+
this.props;
|
|
105
113
|
|
|
106
114
|
if (!dotsLength || dotsLength < 2) {
|
|
107
115
|
return false;
|
|
@@ -112,9 +120,11 @@ export default class Pagination extends PureComponent {
|
|
|
112
120
|
{
|
|
113
121
|
flexDirection: vertical
|
|
114
122
|
? 'column'
|
|
115
|
-
:
|
|
123
|
+
: this._needsRTLAdaptations()
|
|
124
|
+
? 'row-reverse'
|
|
125
|
+
: 'row',
|
|
116
126
|
},
|
|
117
|
-
containerStyle || {}
|
|
127
|
+
containerStyle || {},
|
|
118
128
|
];
|
|
119
129
|
|
|
120
130
|
return (
|
|
@@ -122,9 +132,8 @@ export default class Pagination extends PureComponent {
|
|
|
122
132
|
pointerEvents="box-none"
|
|
123
133
|
style={style}
|
|
124
134
|
accessible={!!accessibilityLabel}
|
|
125
|
-
accessibilityLabel={accessibilityLabel}
|
|
126
|
-
|
|
127
|
-
{ this.dots }
|
|
135
|
+
accessibilityLabel={accessibilityLabel}>
|
|
136
|
+
{this.dots}
|
|
128
137
|
</View>
|
|
129
138
|
);
|
|
130
139
|
}
|
|
@@ -147,12 +156,12 @@ Pagination.propTypes = {
|
|
|
147
156
|
vertical: PropTypes.bool,
|
|
148
157
|
accessibilityLabel: PropTypes.string,
|
|
149
158
|
containerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
150
|
-
dotContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array])
|
|
159
|
+
dotContainerStyle: PropTypes.oneOfType([PropTypes.object, PropTypes.array]),
|
|
151
160
|
};
|
|
152
161
|
|
|
153
162
|
Pagination.defaultProps = {
|
|
154
163
|
inactiveDotOpacity: 0.5,
|
|
155
164
|
inactiveDotScale: 0.5,
|
|
156
165
|
tappableDots: false,
|
|
157
|
-
vertical: false
|
|
166
|
+
vertical: false,
|
|
158
167
|
};
|
|
@@ -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(
|
|
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 {
|
|
@@ -80,50 +81,54 @@ export default class PaginationDot extends PureComponent {
|
|
|
80
81
|
inactiveScale,
|
|
81
82
|
index,
|
|
82
83
|
style,
|
|
83
|
-
tappable
|
|
84
|
+
tappable,
|
|
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
|
-
animatedColor
|
|
117
|
+
animatedColor,
|
|
116
118
|
];
|
|
117
119
|
|
|
118
|
-
const onPress = tappable
|
|
120
|
+
const onPress = tappable
|
|
121
|
+
? () =>
|
|
122
|
+
carouselRef &&
|
|
123
|
+
carouselRef._snapToItem(carouselRef._getPositionIndex(index))
|
|
124
|
+
: undefined;
|
|
119
125
|
|
|
120
126
|
return (
|
|
121
127
|
<TouchableOpacity
|
|
122
128
|
accessible={false}
|
|
123
129
|
style={dotContainerStyle}
|
|
124
130
|
activeOpacity={tappable ? activeOpacity : 1}
|
|
125
|
-
onPress={onPress}
|
|
126
|
-
>
|
|
131
|
+
onPress={onPress}>
|
|
127
132
|
<Animated.View style={dotStyle} />
|
|
128
133
|
</TouchableOpacity>
|
|
129
134
|
);
|
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
|
});
|