-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProgressBar.js
74 lines (67 loc) · 1.97 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
68
69
70
71
72
73
74
'use strict';
import React from 'react';
import {
StyleSheet,
Text,
View,
Animated,
Easing,
} from 'react-native';
class ProgressBar extends React.Component {
constructor(props) {
super(props);
this.state = {
percentage: new Animated.Value(0),
incompletePercentage: new Animated.Value(100),
};
}
componentDidMount() {
this.update(this.props.progress);
}
componentWillReceiveProps(newProps) {
this.update(newProps.progress);
}
update(progress) {
var percentage = progress * 100;
var incompletePercentage = Math.abs(percentage - 100);
Animated.timing(this.state.percentage, {
easing: Easing.inOut(Easing.ease),
duration: 500,
toValue: percentage
}).start();
Animated.timing(this.state.incompletePercentage, {
easing: Easing.inOut(Easing.ease),
duration: 500,
toValue: incompletePercentage
}).start();
}
render () {
var interpolatedPercentage = this.state.percentage.interpolate({
inputRange: [0, 1],
outputRange: [0, 100],
});
var interpolatedIncompletePercentage = this.state.incompletePercentage.interpolate({
inputRange: [0, 1],
outputRange: [0, 100],
});
return (
<View style={[styles.container, this.props.backgroundStyle]}>
<Animated.View style={[styles.complete, this.props.progressStyle, {flex: interpolatedPercentage}]}></Animated.View>
<Animated.View style={[styles.incomplete, this.props.incompleteStyle, {flex: interpolatedIncompletePercentage}]}></Animated.View>
</View>
);
}
}
var styles = StyleSheet.create({
container: {
flexDirection: 'row',
flex: 1,
padding: 5,
},
complete: {
height: 20,
},
incomplete: {
}
});
module.exports = ProgressBar;