forked from osdio/noder-react-native
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMessageOverlay.js
More file actions
115 lines (98 loc) · 1.96 KB
/
MessageOverlay.js
File metadata and controls
115 lines (98 loc) · 1.96 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
import React, {
View,
Text,
Component,
StyleSheet,
Dimensions,
PropTypes
} from 'react-native';
import OverlayButton from './base/OverlayButton';
import Icon from 'react-native-vector-icons/Ionicons';
class MessageOverlay extends Component {
static propTypes = {
count: PropTypes.number,
toMessage: PropTypes.func
};
static defaultProps = {
count: 0,
toMessage: ()=>null
};
_renderMessageCount() {
const count = this.props.count;
if (count > 0) {
return (
<View style={styles.countWrapper}>
<Text style={styles.countText}>
{count > 999 ? '1k+' : count}
</Text>
</View>
)
}
return null
}
render() {
if (this.props.user) {
return (
<OverlayButton
position={styles.position}
onPress={ () => this.props.toMessage() }>
<View style={styles.iconWrapper}>
<Icon
name='ios-email-outline'
size={28}
color='rgba(255,255,255,0.9)'
style={styles.icon}/>
</View>
{this._renderMessageCount()}
</OverlayButton>
)
}
return null
}
}
const overlaySize = 45;
const countBoxSize = 20;
const countTextSize = 10;
const styles = StyleSheet.create({
iconWrapper: {
height: overlaySize,
width: overlaySize,
borderRadius: overlaySize / 2,
flex: 1,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center'
},
icon: {
flex: 1,
textAlign: 'center'
},
countWrapper: {
height: countBoxSize,
width: countBoxSize,
borderRadius: countBoxSize / 2,
backgroundColor: 'red',
position: 'absolute',
right: -5,
top: -5
},
countText: {
color: 'rgba(255,255,255,0.8)',
fontSize: countTextSize,
lineHeight: countBoxSize - countTextSize / 2,
textAlign: 'center',
height: countBoxSize,
width: countBoxSize,
borderRadius: countBoxSize / 2,
backgroundColor: 'transparent'
},
position: {
right: 20,
bottom: 20
},
container: {
backgroundColor: 'blue',
borderRadius: overlaySize / 2
}
});
export default MessageOverlay;