-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuickSelect.js
More file actions
164 lines (142 loc) · 4.41 KB
/
QuickSelect.js
File metadata and controls
164 lines (142 loc) · 4.41 KB
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
'use strict';
var React = require('react-native');
var {
StyleSheet,
Text,
View,
Image,
Component,
ListView,
TouchableHighlight,
Animated,
PanResponder,
} = React;
var clamp = require('clamp');
var TeamImages = require('./TeamImages');
var SWIPE_THRESHOLD = 120;
var People = [
'red',
'green',
'blue',
'purple',
'orange'
]
class QuickSelect extends Component{
constructor(props){
super(props);
this.state = {
pan: new Animated.ValueXY(),
enter: new Animated.Value(0.5),
images: TeamImages,
}
}
componentWillMount(){
this.leftPanResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture:() => true,
onPanResponderGrant: (e, gestureState) => {
this.state.pan.setOffset({x: this.state.pan.x._value, y:this.state.pan.y._value});
this.state.pan.setValue({x:0, y:0});
},
onPanResponderMove: Animated.event([
null, {dx: this.state.pan.x, dy: this.state.pan.y},
]),
onPanResponderRelease: (e, {vx,vy}) => {
this.state.pan.flattenOffset();
var velocity;
if(vx>0){
velocity = clamp(vx, 3, 5);
}else if(vx < 0){
velocity = clamp(vx*-1, 3, 5) *-1;
}
var st = this.state;
if(this.state.pan.x._value > SWIPE_THRESHOLD){
Animated.spring(this.state.pan,{
toValue:{x:100, y:0},
friction:10
}).start()
}else{
Animated.spring(this.state.pan,{
toValue: {x:0, y:0},
friction: 4
}).start()
}
}
})
this.rightPanResponder = PanResponder.create({
onMoveShouldSetResponderCapture: () => true,
onMoveShouldSetPanResponderCapture:() => true,
onPanResponderGrant: (e, gestureState) => {
this.state.pan.setOffset({x: this.state.pan.x._value, y:this.state.pan.y._value});
this.state.pan.setValue({x:0, y:0});
},
onPanResponderMove: Animated.event([
null, {dx: this.state.pan.x, dy: this.state.pan.y},
]),
onPanResponderRelease: (e, {vx,vy}) => {
this.state.pan.flattenOffset();
var velocity;
if(vx>0){
velocity = clamp(vx, 3, 5);
}else if(vx < 0){
velocity = clamp(vx*-1, 3, 5) *-1;
}
var st = this.state;
if(Math.abs(this.state.pan.x._value) > SWIPE_THRESHOLD){
Animated.spring(this.state.pan,{
toValue:{x:-100, y:0},
friction:10
}).start()
}else{
Animated.spring(this.state.pan,{
toValue: {x:0, y:0},
friction: 4
}).start()
}
}
})
}
_resetState(){
// this.state.pan.setValue({x:0,y:0});
// this.state.enter.setValue(0);
}
render(){
let {pan, enter, } = this.state;
let [translateX, translateY] = [pan.x, pan.y];
let rotate = pan.x.interpolate({inputRange: [-200,0,200], outputRange:["-30deg", "0deg", "30deg"]});
let opacityLeft = pan.x.interpolate({inputRange: [-100,0,200], outputRange:[0,1,1]});
let opacityRight = pan.x.interpolate({inputRange: [-200,0,100], outputRange:[1,1,0]});
let scaleLeft = pan.x.interpolate({inputRange:[-200,0,200], outputRange:[0.5,1,2]});
let scaleRight = pan.x.interpolate({inputRange:[-200,0,200], outputRange:[2,1,0.5]});
let leftCardStyles = {transform: [{translateX}, {translateY}, {scale:scaleLeft}], opacity:opacityLeft};
let rightCardStyles = {transform: [{translateX}, {translateY}, {scale:scaleRight}], opacity:opacityRight};
let shouldMoveLeft= false;
return(
<View style = {styles.container}>
<Animated.Image source ={require('image!Baltimore')} style={[styles.pic, leftCardStyles && shouldMoveLeft]} {...this.leftPanResponder.panHandlers}/>
<Text style = {{fontSize:60, padding:10, top:10}}>@</Text>
<Animated.Image source ={require('image!Denver')} style={[styles.pic, rightCardStyles]} {...this.rightPanResponder.panHandlers}/>
</View>
)
}
}
var styles = StyleSheet.create({
container: {
flex: 1,
flexDirection:'row',
justifyContent: 'center',
alignItems:'flex-start',
paddingTop: 140,
},
pic:{
height:120,
width:120,
borderRadius:60,
backgroundColor:'#333',
},
selected:{
borderWidth:3,
borderColor:"#47c6b2"
}
});
module.exports = QuickSelect;