SuperMan.js
3.41 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
'use strict';
import React from 'react';
import ReactNative from 'react-native';
import ImmutablePropTypes from 'react-immutable-proptypes';
import SlicedImage from '../../../common/components/SlicedImage';
const {
View,
Text,
Image,
TouchableOpacity,
StyleSheet,
Dimensions,
} = ReactNative;
export default class SuperMan extends React.Component {
static propTypes = {
uid: React.PropTypes.number,
avatar: React.PropTypes.string,
msgCount: React.PropTypes.string,
onSaveingTheWorld: React.PropTypes.func,
};
constructor(props) {
super (props);
}
renderText() {
if (this.props.uid == 0 ) {
return (
<Text style={styles.loginText}>请登录</Text>
);
} else {
return null;
}
}
renderMsgCount() {
if (this.props.uid > 0 && parseInt(this.props.msgCount) !== 0) {
return (
<View style={styles.textContainer}>
<Text style={styles.text}>{this.props.msgCount}</Text>
</View>
);
} else {
return null;
}
}
render() {
let avatarContainerStyle = this.props.uid > 0 && this.props.avatar ? styles.avatarContainer : null;
let avatarStyle = this.props.uid > 0 && this.props.avatar ? styles.avatarBorder : null;
let defaultSource = this.props.uid > 0 && this.props.avatar ? null : require('../../images/avatar/superman.png');
return (
<View style={[styles.container, this.props.fly]}>
<TouchableOpacity activeOpacity={0.8} onPress={() => {
this.props.onSaveingTheWorld && this.props.onSaveingTheWorld();
}}>
<View style={avatarContainerStyle}>
<SlicedImage style={[styles.avatar, avatarStyle]} source={{uri: this.props.avatar}} resizeMode={'cover'} defaultSource={defaultSource}/>
</View>
{this.renderText()}
{this.renderMsgCount()}
</TouchableOpacity>
</View>
);
}
}
let styles = StyleSheet.create({
container: {
position: 'absolute',
right: 20,
bottom: 20,
flexDirection: 'column',
alignItems: 'center',
backgroundColor: 'transparent',
width: 45,
height: 45,
justifyContent: 'center',
},
avatarContainer: {
width: 44,
height: 44,
borderRadius: 22,
backgroundColor: 'white',
shadowColor: 'darkgray',
shadowOpacity: 1,
shadowOffset: {width: 0, height: 0},
},
avatar: {
width: 44,
height: 44,
borderRadius: 22,
},
avatarBorder: {
borderColor: 'white',
borderWidth: 1,
},
loginText: {
marginTop: 2,
fontSize: 10,
textAlign: 'center',
},
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',
},
});