-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.ios.js
109 lines (97 loc) · 2.35 KB
/
index.ios.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import React, { Component } from "react";
import { AppRegistry, StyleSheet, Text, View, Animated } from "react-native";
class ProgressBar extends Component {
componentWillMount() {
this.animation = new Animated.Value(this.props.progress);
}
componentDidUpdate(prevProps, prevState) {
if (prevProps.progress !== this.props.progress) {
Animated.timing(this.animation, {
toValue: this.props.progress,
duration: this.props.duration
}).start();
}
}
render() {
const {
height,
borderColor,
borderWidth,
borderRadius,
barColor,
fillColor,
row
} = this.props;
const widthInterpolated = this.animation.interpolate({
inputRange: [0, 1],
outputRange: ["0%", "100%"],
extrapolate: "clamp"
})
return (
<View style={[{flexDirection: "row", height }, row ? { flex: 1} : undefined ]}>
<View style={{ flex: 1, borderColor, borderWidth, borderRadius}}>
<View
style={[StyleSheet.absoluteFill, { backgroundColor: fillColor }]}
/>
<Animated.View
style={{
position: "absolute",
left: 0,
top: 0,
bottom: 0,
width: widthInterpolated,
backgroundColor: barColor
}}
/>
</View>
</View>
)
}
}
ProgressBar.defaultProps = {
height: 10,
borderColor: "#000",
borderWidth: 2,
borderRadius: 4,
barColor: "tomato",
fillColor: "rgba(0,0,0,.5)",
duration: 100
}
export default class rn_progress_bars extends Component {
state = {
progress: 0,
};
componentDidMount() {
setInterval(() => {
this.setState(state => ({
progress: state.progress + 0.1,
}));
}, 1000);
}
render() {
return (
<View style={styles.container}>
<View style={styles.progressContainer}>
<Text>Load progress:</Text>
<ProgressBar
row
progress={this.state.progress}
duration={500}
/>
<Text>100%</Text>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 250,
},
progressContainer: {
alignItems: "center",
flexDirection: "row"
}
});
AppRegistry.registerComponent("rn_progress_bars", () => rn_progress_bars);