7
7
DeviceEventEmitter ,
8
8
ActivityIndicator
9
9
} from 'react-native' ;
10
+
10
11
const styles = StyleSheet . create ( {
11
12
container : {
12
13
position : 'absolute' ,
@@ -19,105 +20,119 @@ const styles = StyleSheet.create({
19
20
right : 0 ,
20
21
flex : 1
21
22
} ,
23
+
22
24
progressBar : {
23
25
margin : 10 ,
24
26
justifyContent : 'center' ,
25
27
alignItems : 'center' ,
26
28
padding : 10
27
29
} ,
30
+
28
31
nocontainer : {
29
32
position : 'absolute' ,
30
33
top : 0 ,
31
34
left : 0 ,
32
35
width : 0.001 ,
33
36
height : 0.001
34
- }
35
- } ) ;
36
-
37
- const BusyIndicator = React . createClass ( {
38
- propTypes : {
39
- color : React . PropTypes . string ,
40
- overlayColor : React . PropTypes . string ,
41
- overlayHeight : React . PropTypes . number ,
42
- overlayWidth : React . PropTypes . number ,
43
- startVisible : React . PropTypes . bool ,
44
- text : React . PropTypes . string ,
45
- textColor : React . PropTypes . string ,
46
- textFontSize : React . PropTypes . number ,
47
- textNumberOfLines : React . PropTypes . number
48
37
} ,
49
38
50
- getDefaultProps ( ) {
51
- return {
52
- isDismissible : false ,
53
- overlayWidth : 120 ,
54
- overlayHeight : 100 ,
55
- overlayColor : '#333333' ,
56
- color : '#f5f5f5' ,
57
- startVisible : false ,
58
- text : 'Please wait...' ,
59
- textColor : '#f5f5f5' ,
60
- textFontSize : 14 ,
61
- textNumberOfLines : 1
62
- } ;
39
+ overlay : {
40
+ alignItems : 'center' ,
41
+ justifyContent : 'center' ,
42
+ borderRadius : 10 ,
43
+ padding : 10
63
44
} ,
64
45
65
- getInitialState ( ) {
66
- return {
67
- isVisible : this . props . startVisible
46
+ text : {
47
+ marginTop : 8
48
+ }
49
+ } ) ;
50
+
51
+ class BusyIndicator extends React . Component {
52
+ constructor ( props ) {
53
+ super ( props ) ;
54
+ this . state = {
55
+ isVisible : props . startVisible
68
56
} ;
69
- } ,
57
+ }
58
+
70
59
componentDidMount ( ) {
71
- this . emitter = DeviceEventEmitter . addListener ( 'changeLoadingEffect' , this . changeLoadingEffect , null ) ;
72
- } ,
60
+ this . emitter = DeviceEventEmitter . addListener ( 'changeLoadingEffect' , this . changeLoadingEffect . bind ( this ) ) ;
61
+ }
73
62
74
63
componentWillUnmount ( ) {
75
64
this . emitter . remove ( ) ;
76
- } ,
65
+ }
77
66
78
67
changeLoadingEffect ( state ) {
79
68
this . setState ( {
80
69
isVisible : state . isVisible ,
81
- text : state . title ? state . title : 'Please wait...'
70
+ text : state . title ? state . title : this . props . text
82
71
} ) ;
83
- } ,
84
-
72
+ }
85
73
86
74
render ( ) {
75
+ if ( ! this . state . isVisible ) {
76
+ return ( < View style = { styles . nocontainer } /> ) ;
77
+ }
78
+
87
79
const customStyles = StyleSheet . create ( {
88
80
overlay : {
89
- alignItems : 'center' ,
90
- justifyContent : 'center' ,
91
- borderRadius : 10 ,
92
- padding : 10 ,
93
81
backgroundColor : this . props . overlayColor ,
94
82
width : this . props . overlayWidth ,
95
83
height : this . props . overlayHeight
96
84
} ,
85
+
97
86
text : {
98
87
color : this . props . textColor ,
99
- fontSize : this . props . textFontSize ,
100
- marginTop : 8
88
+ fontSize : this . props . textFontSize
101
89
}
102
90
} ) ;
103
91
104
- if ( ! this . state . isVisible ) {
105
- return ( < View style = { [ styles . nocontainer ] } /> ) ;
106
- } else {
107
- return (
108
- < View style = { [ styles . container ] } >
109
- < View style = { customStyles . overlay } >
110
- < ActivityIndicator
111
- color = { this . props . color }
112
- size = "small"
113
- style = { styles . progressBar } />
114
- < Text numberOfLines = { this . props . textNumberOfLines } style = { customStyles . text } >
115
- { this . state . text }
116
- </ Text >
117
- </ View >
92
+ return (
93
+ < View style = { styles . container } >
94
+ < View style = { [ styles . overlay , customStyles . overlay ] } >
95
+ < ActivityIndicator
96
+ color = { this . props . color }
97
+ size = { this . props . size }
98
+ style = { styles . progressBar } />
99
+
100
+ < Text
101
+ numberOfLines = { this . props . textNumberOfLines }
102
+ style = { [ styles . text , customStyles . text ] } >
103
+ { this . state . text }
104
+ </ Text >
118
105
</ View >
119
- ) ;
120
- }
106
+ </ View >
107
+ ) ;
121
108
}
122
- } ) ;
109
+ }
110
+
111
+ BusyIndicator . propTypes = {
112
+ color : React . PropTypes . string ,
113
+ overlayColor : React . PropTypes . string ,
114
+ overlayHeight : React . PropTypes . number ,
115
+ overlayWidth : React . PropTypes . number ,
116
+ size : React . PropTypes . oneOf ( [ 'small' , 'large' ] ) ,
117
+ startVisible : React . PropTypes . bool ,
118
+ text : React . PropTypes . string ,
119
+ textColor : React . PropTypes . string ,
120
+ textFontSize : React . PropTypes . number ,
121
+ textNumberOfLines : React . PropTypes . number
122
+ } ;
123
+
124
+ BusyIndicator . defaultProps = {
125
+ isDismissible : false ,
126
+ overlayWidth : 120 ,
127
+ overlayHeight : 100 ,
128
+ overlayColor : '#333333' ,
129
+ color : '#f5f5f5' ,
130
+ size : 'small' ,
131
+ startVisible : false ,
132
+ text : 'Please wait...' ,
133
+ textColor : '#f5f5f5' ,
134
+ textFontSize : 14 ,
135
+ textNumberOfLines : 1
136
+ } ;
137
+
123
138
module . exports = BusyIndicator ;
0 commit comments