/
Badge.js
81 lines (72 loc) 路 1.45 KB
/
Badge.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
81
/**
* Material badge for showing notifications, maybe more functionality in the future
* @flow
*/
import React, { Component } from 'react'
import {
View,
Text,
StyleSheet
} from 'react-native';
type BProps = {
text: string,
size: number,
children: Array<ReactElement<*>>,
style: any,
isVisible: boolean,
}
const defaultProps = {
size: 20,
isVisible: true,
style: {},
}
export default class Badge extends Component {
static defaultProps: typeof defaultProps
props: BProps
static defaultProps = defaultProps
createStyles() {
const { size, style } = this.props;
const container = Object.assign(
{},
{
position: "absolute",
width: size,
height: size,
borderRadius: size / 2,
alignItems: "center",
justifyContent: "center",
backgroundColor: "#F50057",
zIndex: 9999,
bottom: 10,
},
style.container
);
const text = Object.assign(
{},
{
color: "#fff",
fontWeight: "500",
fontSize: 12,
},
style.text
)
return StyleSheet.create({
container,
text,
})
}
render() {
const { children, text, isVisible } = this.props;
const styles = this.createStyles();
if (!isVisible) {
return null;
}
return (
<View>
<View style={styles.container}>
<Text style={styles.text}>{text}</Text>
</View>
</View>
)
}
}