-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConcentricCircles.js
68 lines (63 loc) · 2.02 KB
/
ConcentricCircles.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React, { Component } from 'react';
import { Animated, StyleSheet, View } from 'react-native';
import PropTypes from 'prop-types';
import Flex from 'react-native-flex-helper';
import createColor from 'color';
class ConcentricCircles extends Component {
render() {
const { style, color, animValue, size, circles, contentScale, children } = this.props;
const baseColor = createColor(color);
return (
<View style={[style, { position: 'relative' }]}>
{circles.map((circle, i) => (
<View key={i} style={[StyleSheet.absoluteFill, Flex.center]}>
<Animated.View
style={{
width: size,
height: size,
borderRadius: 99999,
backgroundColor: baseColor.fade(1 - circle.alpha).string(),
transform: [{
scale: animValue.interpolate({
inputRange: [0, 1],
outputRange: [circle.initialScale || 1, circle.scale],
}),
}],
}} />
</View>
))}
<Animated.View
style={[StyleSheet.absoluteFill, Flex.center, {
transform: [{
scale: animValue.interpolate({
inputRange: [0, 1],
outputRange: [1, contentScale],
}),
}],
}]}>
{children}
</Animated.View>
</View>
);
}
}
ConcentricCircles.propTypes = {
style: PropTypes.any.isRequired,
animValue: PropTypes.instanceOf(Animated.Value).isRequired,
color: PropTypes.string.isRequired,
size: PropTypes.number.isRequired,
contentScale: PropTypes.number,
circles: PropTypes.arrayOf(PropTypes.shape({
alpha: PropTypes.number.isRequired,
scale: PropTypes.number.isRequired,
initialScale: PropTypes.number,
})).isRequired,
children: PropTypes.oneOfType([
PropTypes.arrayOf(PropTypes.node),
PropTypes.node,
]),
};
ConcentricCircles.defaultProps = {
contentScale: 1,
};
export default ConcentricCircles;