forked from RealOrangeOne/react-native-busy-indicator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
139 lines (121 loc) · 2.82 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
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
131
132
133
134
135
136
137
138
139
import React from 'react';
import PropTypes from 'prop-types';
import {
StyleSheet,
View,
Text,
DeviceEventEmitter,
ActivityIndicator
} from 'react-native';
const styles = StyleSheet.create({
container: {
position: 'absolute',
backgroundColor: 'rgba(0,0,0,0.3)',
justifyContent: 'center',
alignItems: 'center',
top: 0,
bottom: 0,
left: 0,
right: 0,
flex: 1
},
progressBar: {
margin: 10,
justifyContent: 'center',
alignItems: 'center',
padding: 10
},
nocontainer: {
position: 'absolute',
top: 0,
left: 0,
width: 0.001,
height: 0.001
},
overlay: {
alignItems: 'center',
justifyContent: 'center',
borderRadius: 10,
padding: 10
},
text: {
marginTop: 8
}
});
class BusyIndicator extends React.Component {
constructor(props) {
super(props);
this.state = {
isVisible: props.startVisible
};
}
componentDidMount () {
this.emitter = DeviceEventEmitter.addListener('changeLoadingEffect', this.changeLoadingEffect.bind(this));
}
componentWillUnmount() {
this.emitter.remove();
}
changeLoadingEffect(state) {
this.setState({
isVisible: state.isVisible,
text: state.title ? state.title : this.props.text
});
}
render() {
if (!this.state.isVisible) {
return (<View style={styles.nocontainer} />);
}
const customStyles = StyleSheet.create({
overlay: {
backgroundColor: this.props.overlayColor,
width: this.props.overlayWidth,
height: this.props.overlayHeight
},
text: {
color: this.props.textColor,
fontSize: this.props.textFontSize
}
});
return (
<View style={styles.container}>
<View style={[styles.overlay, customStyles.overlay]}>
<ActivityIndicator
color={this.props.color}
size={this.props.size}
style={styles.progressBar} />
<Text
numberOfLines={this.props.textNumberOfLines}
style={[styles.text, customStyles.text]}>
{this.state.text}
</Text>
</View>
</View>
);
}
}
BusyIndicator.propTypes = {
color: PropTypes.string,
overlayColor: PropTypes.string,
overlayHeight: PropTypes.number,
overlayWidth: PropTypes.number,
size: PropTypes.oneOf(['small', 'large']),
startVisible: PropTypes.bool,
text: PropTypes.string,
textColor: PropTypes.string,
textFontSize: PropTypes.number,
textNumberOfLines: PropTypes.number
};
BusyIndicator.defaultProps = {
isDismissible: false,
overlayWidth: 120,
overlayHeight: 100,
overlayColor: '#333333',
color: '#f5f5f5',
size: 'small',
startVisible: false,
text: 'Please wait...',
textColor: '#f5f5f5',
textFontSize: 14,
textNumberOfLines: 1
};
module.exports = BusyIndicator;