SuperMan.js
2.68 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
const {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
Dimensions,
} = ReactNative;
export default class SuperMan extends React.Component {
static propTypes = {
avatar: React.PropTypes.string,
msgNumber: React.PropTypes.number,
onSaveingTheWorld: React.PropTypes.func,
};
constructor(props) {
super (props);
}
renderMsgNumber() {
if (this.props.msgNumber > 0) {
return (
<View style={styles.textContainer}>
<Text style={styles.text}>{this.props.msgNumber}</Text>
</View>
);
} else {
return null;
}
}
render() {
let avtatStyle = this.props.avatar ? styles.avatarContainer : null;
return (
<View style={[styles.container, this.props.fly]}>
<TouchableOpacity onPress={() => {
this.props.onSaveingTheWorld && this.props.onSaveingTheWorld();
}}>
<View style={avtatStyle}>
<Image style={styles.avatar} source={{uri: this.props.avatar}} resizeMode={'cover'} defaultSource={require('../../images/home/superman.png')}/>
</View>
{this.renderMsgNumber()}
</TouchableOpacity>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'transparent',
width: 45,
height: 45,
justifyContent: 'center',
},
avatarContainer: {
width: 44,
height: 44,
borderRadius: 22,
shadowColor: 'darkgray',
shadowOpacity: 1,
shadowOffset: {width: 0, height: 0},
},
avatar: {
width: 44,
height: 44,
borderRadius: 22,
borderColor: 'white',
borderWidth: 1,
// shadowColor: 'red',
// shadowOpacity: 1,
// // shadowRadius: 20,
// shadowOffset: {width: 0, height: 0},
},
textContainer: {
position: 'absolute',
top: -4,
right: -4,
height: 18,
borderRadius: 9,
borderColor: 'red',
borderWidth: 1,
justifyContent: 'center',
alignItems: 'center',
opacity: 0.9,
backgroundColor: 'white',
},
text: {
fontSize: 12,
color: 'red',
textAlign: 'center',
marginHorizontal: 6,
marginVertical: 6,
backgroundColor: 'transparent',
},
});