-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
ProgressBar.js
65 lines (55 loc) · 1.4 KB
/
ProgressBar.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
'use strict'
//code from: https://github.com/lwansbrough/react-native-progress-bar
import React, { Component } from 'react';
import {
StyleSheet,
Text,
View,
Animated,
Easing,
} from 'react-native';
var styles = StyleSheet.create({
background: {
backgroundColor: '#bbbbbb',
height: 5,
overflow: 'hidden'
},
fill: {
backgroundColor: '#3b5998',
height: 5
}
});
class ProgressBar extends React.Component {
static defaultProps = {
style: styles,
easing: Easing.inOut(Easing.ease),
easingDuration: 500
};
state = {
progress: new Animated.Value(this.props.initialProgress || 0)
};
componentDidUpdate(prevProps, prevState) {
if (this.props.progress >= 0 && this.props.progress != prevProps.progress) {
this.update();
}
}
render() {
var fillWidth = this.state.progress.interpolate({
inputRange: [0, 1],
outputRange: [0 * this.props.style.width, 1 * this.props.style.width],
});
return (
<View style={[styles.background, this.props.backgroundStyle, this.props.style]}>
<Animated.View style={[styles.fill, this.props.fillStyle, { width: fillWidth }]}/>
</View>
);
}
update = () => {
Animated.timing(this.state.progress, {
easing: this.props.easing,
duration: this.props.easingDuration,
toValue: this.props.progress
}).start();
};
}
export default ProgressBar;