-
Notifications
You must be signed in to change notification settings - Fork 0
/
ProgressBar.js
67 lines (56 loc) · 1.3 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
66
67
var React = require('react-native');
var {
Animated,
Easing,
StyleSheet,
View
} = React;
var styles = StyleSheet.create({
background: {
backgroundColor: '#54728C',
height: 5,
overflow: 'hidden'
},
fill: {
backgroundColor: '#8DA7BE',
height: 5,
}
});
var ProgressBar = React.createClass({
getDefaultProps() {
return {
style: styles,
easing: Easing.inOut(Easing.ease),
easingDuration: 500
};
},
getInitialState() {
return {
progress: new Animated.Value(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();
}
});
module.exports = ProgressBar;