-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (74 loc) · 1.66 KB
/
index.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
82
83
84
85
86
import React, { Component, PropTypes } from 'react'
import { InfoBoxStyle } from '../styles'
import Icon from 'react-native-vector-icons/Ionicons'
import {
TouchableWithoutFeedback,
View
} from 'react-native'
export default class InfoBox extends Component {
state = {
hidden: this.props.hidden
}
static propTypes = {
hidden: PropTypes.bool,
onClose: PropTypes.func,
timeout: PropTypes.number,
containerStyle: PropTypes.object,
iconName: PropTypes.string,
iconColor: PropTypes.string,
iconSize: PropTypes.number,
type: PropTypes.string,
}
static defaultProps = {
hidden: false,
onClose: () => {},
timeout: 0,
containerStyle: {},
iconName: 'ios-close',
iconColor: '#FFFFFF',
iconSize: 30,
type: 'info',
}
constructor(props) {
super(props)
}
componentDidMount() {
if(this.props.timeout > 0) {
setTimeout(() => {
this.onClose()
}, this.props.timeout*1000)
}
}
onClose = () => {
this.setState({hidden: true})
this.props.onClose()
}
getType() {
switch (this.props.type) {
case 'error':
return InfoBoxStyle.error
case 'warning':
return InfoBoxStyle.warning
case 'info':
default:
return InfoBoxStyle.info
}
}
render() {
if(!this.state.hidden) {
return (
<View style={[InfoBoxStyle.container, this.getType(), this.props.containerStyle]}>
<TouchableWithoutFeedback onPress={this.onClose}>
<Icon
name={this.props.iconName}
size={this.props.iconSize}
color={this.props.iconColor}
style={InfoBoxStyle.close}/>
</TouchableWithoutFeedback>
{this.props.children}
</View>
)
}
return null
}
}