-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
96 lines (90 loc) · 2.48 KB
/
index.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
import React from "react";
import { View, Text, TouchableOpacity } from "react-native";
// LIST OF PROPS
// 1 - increment - DONE
// 2 - buttonBackgroundColor - DONE
// 3 - fillupColor - DONE
// 4 - buttonText - DONE
// 5 - height - DONE
// 6 - width - DONE
// 7 - incrementSpeed (millseconds) - DONE
// 8 - buttonTextStyle - DONE
// 9 - activeOpacity - DONE
// 10 - onFilled - DONE
// 11 - borderRadius - To be implmeneted
class FillUpButton extends React.Component {
constructor(props) {
super(props);
this.state = {
first_flex: 1.0,
second_flex: 0.0,
};
this.timer = null;
this.fillUp = this.fillUp.bind(this);
this.resetFillUp = this.resetFillUp.bind(this);
}
render() {
return (
<View style={{ borderRadius: 20 }}>
<TouchableOpacity
activeOpacity={this.props.activeOpacity}
onPressIn={this.fillUp}
onPressOut={this.resetFillUp}
style={{
flexDirection: "row",
height: this.props.height,
width: this.props.width,
}}
>
<View
style={{
flex: this.state.second_flex,
backgroundColor: this.props.fillupColor || "#292929",
}}
></View>
<View
style={{
flex: this.state.first_flex,
backgroundColor: this.props.buttonBackgroundColor || "#000000",
}}
></View>
<View
style={{
position: "absolute",
width: "100%",
height: "100%",
justifyContent: "center",
alignItems: "center",
}}
>
<View style={{ zIndex: 111 }}>
<Text style={this.props.buttonTextStyle}>
{" "}
{this.props.buttonText}{" "}
</Text>
</View>
</View>
</TouchableOpacity>
</View>
);
}
fillUp() {
this.setState({
first_flex: this.state.first_flex - (this.props.increment || 0.05),
second_flex: this.state.second_flex + (this.props.increment || 0.05),
});
this.timer = setTimeout(this.fillUp, this.props.incrementSpeed || 10);
if (this.state.second_flex >= 1.0 && this.props.onFilled !== undefined) {
this.props.onFilled();
this.resetFillUp();
}
}
resetFillUp() {
this.setState({
first_flex: 1.0,
second_flex: 0.0,
});
clearTimeout(this.timer);
}
}
export default FillUpButton;