forked from fdnhkj/react-native-conical-gradient
/
App.js
91 lines (89 loc) · 2.46 KB
/
App.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
import React from 'react';
import { StyleSheet, Text, View, TouchableOpacity } from 'react-native';
import AnimatedCircularProgress from 'react-native-conical-gradient-progress';
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = { fill: 60 };
}
render() {
return (
<View style={style.container}>
<View style={style.box}>
<AnimatedCircularProgress
size={107}
width={10}
fill={this.state.fill}
prefill={100}
beginColor="#ff0000"
endColor="#0000ff"
segments={16}
backgroundColor="rgba(255, 255, 255, 0.2)"
linecap="round"
>
{fill => (
<View style={style.titleBox}>
<Text style={style.title}>
16 segments{'\n'}
{fill.toFixed(0)}%`
</Text>
</View>
)}
</AnimatedCircularProgress>
</View>
<View style={style.box}>
<AnimatedCircularProgress
size={107}
width={10}
fill={this.state.fill}
segments={16}
prefill={100}
beginColor="#A9E5BE"
endColor="#ffffff"
backgroundColor="rgba(255, 255, 255, 0.2)"
linecap="round"
>
{fill => (
<View style={style.titleBox}>
<Text style={style.title}>
16 segments{'\n'}
{fill.toFixed(0)}%
</Text>
</View>
)}
</AnimatedCircularProgress>
</View>
<TouchableOpacity onPress={() => this.setState({ fill: this.state.fill - 20 })}>
<Text>Touch</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({ fill: 100 })}>
<Text>Reset</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.setState({ fill: 100 * Math.random() })}>
<Text>Random</Text>
</TouchableOpacity>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#4FC87A',
},
titleBox: {
...StyleSheet.absoluteFillObject,
alignItems: 'center',
justifyContent: 'center',
},
title: {
fontSize: 10,
color: 'white',
textAlign: 'center',
},
box: {
margin: 10,
},
});