-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
110 lines (108 loc) · 3.46 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
import * as React from 'react';
import {Text, View, Animated, PanResponder,TouchableWithoutFeedback } from 'react-native';
export default class StepperTouch extends React.Component {
static defaultProps = {
radius: 40
};
constructor(props) {
super(props);
this.state = {
pan: new Animated.ValueXY(),
};
this.state.panResponder = PanResponder.create({
onStartShouldSetPanResponder: () => true,
onPanResponderMove: (e, gestureState) =>
Math.abs(gestureState.dx) > this.props.radius
? null
: Animated.event([null, { dx: this.state.pan.x }])(e, gestureState),
onPanResponderRelease: (e, { vx, dx }) => {
console.log(vx, dx);
if (dx > this.props.radius) {
this.props.onValueChange(true);
}
if (dx < -this.props.radius) {
this.props.onValueChange(false);
}
Animated.spring(this.state.pan, {
toValue: 0,
}).start();
},
});
}
getCircleStyle(){
return[
{
width: this.props.radius,
height: this.props.radius,
backgroundColor: 'white',
borderRadius: this.props.radius / 2,
alignItems: 'center',
justifyContent: 'center'},this.props.circleStyle,this.state.pan.getLayout()]
}
getCircleTextStyle(){
return[
{fontSize: this.props.radius / 2,color:"#2196F3"},
this.props.circleTextStyle
]
}
getContainerViewStyle(){
return [
{
width: this.props.radius * 2.5,
height: this.props.radius,
flexDirection: 'column',
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#2196F3',
borderRadius: this.props.radius / 2,
},
this.props.containerStyle
]
}
getInnerContainerView(){
return [
{
position: 'absolute',
top: 0,
left: 0,
right: 0,
bottom: 0,
paddingHorizontal: 8,
justifyContent: 'space-between',
alignItems: 'center',
flexDirection: 'row'
}, this.props.innerContainerStyle
]
}
getSignTextStyle(){
return[
{
fontSize: this.props.radius / 3, color: 'white'
},
this.props.signTextStyle
]
}
render() {
return <View
pointerEvents={this.props.disabled === true ? "none": "auto"}
overflow={"hidden"}
style={this.getContainerViewStyle()}>
<View
style={this.getInnerContainerView()}>
<Text style={this.getSignTextStyle()}>
-
</Text>
<Text style={this.getSignTextStyle()}>
+
</Text>
</View>
<Animated.View
{...this.state.panResponder.panHandlers}
style={[this.getCircleStyle()]}>
<Text style={this.getCircleTextStyle()}>
{this.props.value}
</Text>
</Animated.View>
</View>;
}
}