Skip to content
This repository was archived by the owner on Jul 9, 2024. It is now read-only.

Commit 0662694

Browse files
authoredMar 19, 2017
Merge pull request #12 from RealOrangeOne/improvements
Improvements
2 parents eb078a5 + 8fc72bf commit 0662694

File tree

4 files changed

+81
-73
lines changed

4 files changed

+81
-73
lines changed
 

‎README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# react-native-busy-indicator
1+
# React-Native Busy Indicator
22
[![npm version](https://badge.fury.io/js/react-native-busy-indicator.svg)](https://badge.fury.io/js/react-native-busy-indicator)
33
[![Circle CI](https://circleci.com/gh/RealOrangeOne/react-native-busy-indicator.svg)](https://circleci.com/gh/RealOrangeOne/react-native-busy-indicator)
44
[![NPM downloads](http://img.shields.io/npm/dm/react-native-busy-indicator.svg?style=flat-square)](https://www.npmjs.com/package/react-native-busy-indicator)
@@ -31,7 +31,8 @@ Toggling the component can be done from any file, provided the component has alr
3131
```js
3232
const loaderHandler = require('react-native-busy-indicator/LoaderHandler');
3333

34-
loaderHandler.showLoader("Loading"); // Show indicator with message 'loading'
34+
loaderHandler.showLoader("Loading"); // Show indicator with message 'Loading'
35+
loaderHandler.showLoader("Loading More"); // Show indicator with message 'Loading More'
3536

3637
loaderHandler.hideLoader(); // Hide the loader
3738
```
@@ -48,12 +49,11 @@ loaderHandler.hideLoader(); // Hide the loader
4849
|**`textColor`**|`string`| text color|
4950
|**`textFontSize`**|`number`|text font size|
5051
|**`textNumberOfLines`**|`number`| total number of lines does not exceed this number. Default: 1|
52+
|**`Size`**|`small/large`| Size of the spinner. Default: small|
5153
5254
5355
## Demo
5456
5557
![Demo](https://raw.githubusercontent.com/RealOrangeOne/react-native-busy-indicator/master/demo.gif)
5658
57-
## License
58-
59-
[MIT License](http://opensource.org/licenses/mit-license.html)
59+
__Note__: The spinner moves much smoother than shown in recording!

‎index.js

+75-60
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
DeviceEventEmitter,
88
ActivityIndicator
99
} from 'react-native';
10+
1011
const styles = StyleSheet.create({
1112
container: {
1213
position: 'absolute',
@@ -19,105 +20,119 @@ const styles = StyleSheet.create({
1920
right: 0,
2021
flex: 1
2122
},
23+
2224
progressBar: {
2325
margin: 10,
2426
justifyContent: 'center',
2527
alignItems: 'center',
2628
padding: 10
2729
},
30+
2831
nocontainer: {
2932
position: 'absolute',
3033
top: 0,
3134
left: 0,
3235
width: 0.001,
3336
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
4837
},
4938

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
6344
},
6445

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
6856
};
69-
},
57+
}
58+
7059
componentDidMount () {
71-
this.emitter = DeviceEventEmitter.addListener('changeLoadingEffect', this.changeLoadingEffect, null);
72-
},
60+
this.emitter = DeviceEventEmitter.addListener('changeLoadingEffect', this.changeLoadingEffect.bind(this));
61+
}
7362

7463
componentWillUnmount() {
7564
this.emitter.remove();
76-
},
65+
}
7766

7867
changeLoadingEffect(state) {
7968
this.setState({
8069
isVisible: state.isVisible,
81-
text: state.title ? state.title : 'Please wait...'
70+
text: state.title ? state.title : this.props.text
8271
});
83-
},
84-
72+
}
8573

8674
render() {
75+
if (!this.state.isVisible) {
76+
return (<View style={styles.nocontainer} />);
77+
}
78+
8779
const customStyles = StyleSheet.create({
8880
overlay: {
89-
alignItems: 'center',
90-
justifyContent: 'center',
91-
borderRadius: 10,
92-
padding: 10,
9381
backgroundColor: this.props.overlayColor,
9482
width: this.props.overlayWidth,
9583
height: this.props.overlayHeight
9684
},
85+
9786
text: {
9887
color: this.props.textColor,
99-
fontSize: this.props.textFontSize,
100-
marginTop: 8
88+
fontSize: this.props.textFontSize
10189
}
10290
});
10391

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>
118105
</View>
119-
);
120-
}
106+
</View>
107+
);
121108
}
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+
123138
module.exports = BusyIndicator;

‎package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"main": "index.js",
55
"description": "A simple busy indicator which can be trigger from any child or navigated page in react native application",
66
"scripts": {
7-
"lint": "eslint index.js LoaderHandler.js",
7+
"lint": "eslint index.js LoaderHandler.js scripts/ tests/",
88
"mocha": "mocha --require babel-core/register scripts/test-helper.js --bail 'tests/**/*.test.js'",
99
"test": "npm run lint && npm run mocha"
1010
},

‎tests/basic.test.js

-7
This file was deleted.

0 commit comments

Comments
 (0)
This repository has been archived.