This repository has been archived by the owner on Feb 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 368
/
Avatar.js
80 lines (72 loc) · 2.36 KB
/
Avatar.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
69
70
71
72
73
74
75
76
77
78
79
80
import React, {Component, PropTypes} from "react";
import {View, Image, Text} from "react-native";
import Icon from './Icon';
import { getColor } from './helpers';
export default class Avatar extends Component {
static propTypes = {
image: PropTypes.shape({ type: PropTypes.oneOf([Image]) }),
icon: PropTypes.string,
size: PropTypes.number,
color: PropTypes.string,
backgroundColor: PropTypes.string,
text: PropTypes.string,
borderRadius: PropTypes.number,
borderColor: PropTypes.string,
borderWidth: PropTypes.number
};
static defaultProps = {
size: 40,
color: '#ffffff',
backgroundColor: getColor('paperGrey500'),
borderRadius: 40 / 2,
borderColor: 'rgba(0,0,0,.1)',
borderWidth: 1
};
render() {
const {
image,
icon,
size,
color,
backgroundColor,
text,
borderRadius,
borderColor,
borderWidth
} = this.props;
if (image) {
return React.cloneElement(image, {
style: {
width: size,
height: size,
borderRadius: borderRadius,
borderColor: borderColor,
borderWidth: borderWidth
}
});
}
if (icon) {
return (
<View style={{ flex: 1 }}>
<View style={{ width: size, height: size, borderRadius: borderRadius, backgroundColor: getColor(backgroundColor), alignItems:'center', justifyContent: 'center' }}>
<Icon
name={icon}
color={getColor(color)}
size={0.6 * size}
/>
</View>
</View>
);
}
if (text) {
return (
<View style={{ flex: 1 }}>
<View style={{ width: size, height: size, borderRadius: borderRadius, backgroundColor: getColor(backgroundColor), alignItems:'center', justifyContent: 'center' }}>
<Text style={{ color: getColor(color) }}>{text}</Text>
</View>
</View>
);
}
return null;
}
}