Skip to content

Commit 7a5f10f

Browse files
committed
First commit
0 parents  commit 7a5f10f

File tree

5 files changed

+224
-0
lines changed

5 files changed

+224
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015 Loch Wansbrough
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

ProgressBar.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
var React = require('react-native');
2+
var {
3+
StyleSheet,
4+
View
5+
} = React;
6+
var tweenState = require('react-tween-state');
7+
8+
9+
var styles = StyleSheet.create({
10+
background: {
11+
backgroundColor: '#bbbbbb',
12+
height: 5,
13+
overflow: 'hidden'
14+
},
15+
fill: {
16+
backgroundColor: '#3b5998',
17+
height: 5
18+
}
19+
});
20+
21+
22+
var ProgressBar = React.createClass({
23+
24+
mixins: [tweenState.Mixin],
25+
26+
getDefaultProps() {
27+
return {
28+
style: styles,
29+
easing: tweenState.easingTypes.easeInOutQuad,
30+
easingDuration: 500
31+
};
32+
},
33+
34+
getInitialState() {
35+
return {
36+
progress: 0
37+
};
38+
},
39+
40+
componentDidUpdate(prevProps, prevState) {
41+
if (this.props.progress >= 0 && this.props.progress != prevProps.progress) {
42+
this.update(this.props.progress);
43+
}
44+
},
45+
46+
render() {
47+
48+
var progress = this.getTweeningValue('progress') || this.props.progress;
49+
50+
var fillWidth = progress * this.props.style.width;
51+
52+
return (
53+
<View style={[styles.background, this.props.backgroundStyle, this.props.style]}>
54+
<View style={[styles.fill, this.props.fillStyle, { width: fillWidth }]}/>
55+
</View>
56+
);
57+
},
58+
59+
update(progress) {
60+
this.tweenState('progress', {
61+
easing: this.props.easing,
62+
duration: this.props.easingDuration,
63+
endValue: this.props.progress
64+
});
65+
}
66+
});
67+
68+
ProgressBar.easingTypes = tweenState.easingTypes;
69+
70+
module.exports = ProgressBar;

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
# react-native-google-analytics
2+
3+
An animated progress bar for React Native.
4+
5+
![](https://i.imgur.com/EGufppz.gif)
6+
7+
## Getting started
8+
9+
1. `npm install react-native-progress-bar@latest --save`
10+
11+
## Example usage
12+
13+
```javascript
14+
var React = require('react-native');
15+
var {
16+
AppRegistry,
17+
StyleSheet,
18+
Text,
19+
View,
20+
} = React;
21+
var ProgressBar = require('react-native-progress-bar');
22+
23+
var rnsandbox = React.createClass({
24+
25+
getInitialState() {
26+
return {
27+
progress: 0
28+
};
29+
},
30+
31+
render() {
32+
33+
setTimeout((function() {
34+
this.setState({ progress: this.state.progress + (0.4 * Math.random())});
35+
}).bind(this), 1000);
36+
37+
return (
38+
<View style={styles.container}>
39+
<Text style={styles.welcome}>
40+
Welcome to React Native!
41+
</Text>
42+
<Text style={styles.instructions}>
43+
To get started, edit index.ios.js
44+
</Text>
45+
<Text style={styles.instructions}>
46+
Press Cmd+R to reload,{'\n'}
47+
Cmd+Control+Z for dev menu
48+
</Text>
49+
<ProgressBar
50+
fillStyle={{}}
51+
backgroundStyle={{backgroundColor: '#cccccc', borderRadius: 2}}
52+
style={{marginTop: 10, width: 300}}
53+
progress={this.state.progress}
54+
/>
55+
</View>
56+
);
57+
}
58+
});
59+
60+
var styles = StyleSheet.create({
61+
container: {
62+
flex: 1,
63+
justifyContent: 'center',
64+
alignItems: 'center',
65+
backgroundColor: '#F5FCFF',
66+
},
67+
welcome: {
68+
fontSize: 20,
69+
textAlign: 'center',
70+
margin: 10,
71+
},
72+
instructions: {
73+
textAlign: 'center',
74+
color: '#333333',
75+
marginBottom: 5,
76+
},
77+
});
78+
79+
AppRegistry.registerComponent('rnsandbox', () => rnsandbox);
80+
81+
```
82+
83+
## Properties
84+
85+
#### `progress`
86+
87+
The progress value for the progress bar. Ranges from `0..1`.
88+
89+
#### `fillStyle`
90+
91+
The style for the progress bar fill.
92+
93+
#### `backgroundStyle`
94+
95+
The style for the progress bar's background.
96+
97+
#### `style`
98+
99+
The style for the entire component. This doesn't really differ from the `backgroundStyle` property. You must set `width` either here or in `backgroundStyle` in order to make sure the component works properly.
100+
101+
102+
## Component methods
103+
104+
#### `update(progress)`
105+
106+
The recommended way to update the progress of the progress bar is to use the `progress` property. If you prefer, you can use this `update` method to update the progress directly. To access this method, set the `ref` property on the `<ProgressBar>` and call `this.refs.progressBarName.update(0.3)`

index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = require('./ProgressBar');

package.json

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
"name": "react-native-progress-bar",
3+
"repository": {
4+
"type": "git",
5+
"url": "https://github.com/lwansbrough/react-native-progress-bar.git"
6+
},
7+
"version": "0.1.0",
8+
"description": "An animated progress bar component for React Native",
9+
"main": "index.js",
10+
"author": "Lochlan Wansbrough <lochie@live.com> (http://lwansbrough.com)",
11+
"peerDependencies": {
12+
"react-native": "^0.4.0"
13+
},
14+
"keywords": [
15+
"react",
16+
"native",
17+
"react-native",
18+
"progress",
19+
"bar",
20+
"load",
21+
"loading"
22+
],
23+
"dependencies": {
24+
"react-tween-state": "0.0.5"
25+
}
26+
}

0 commit comments

Comments
 (0)