-
Notifications
You must be signed in to change notification settings - Fork 0
/
app1.js
120 lines (107 loc) · 2.92 KB
/
app1.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
111
112
113
114
115
116
117
118
119
120
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View, Animated, Dimensions, TouchableWithoutFeedback} from 'react-native';
import GestureRecognizer from 'react-native-swipe-gestures';
const {width} = Dimensions.get('screen');
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
myText: 'I\'m ready to get swiped!',
gestureName: 'none',
backgroundColor: '#fff',
left: new Animated.Value(-width)
};
}
// onSwipeUp(gestureState) {
// this.setState({myText: 'You swiped up!'});
// }
// onSwipeDown(gestureState) {
// this.setState({myText: 'You swiped down!'});
// }
onSwipeLeft(gestureState) {
Animated.timing(
this.state.left,
{
toValue: -width,
duration: 300
}
).start();
}
onSwipeRight(gestureState) {
Animated.timing(
this.state.left,
{
toValue: 0,
duration: 300
}
).start();
}
// onSwipe(gestureName, gestureState) {
// const {SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT} = swipeDirections;
// this.setState({gestureName: gestureName});
// switch (gestureName) {
// case SWIPE_UP:
// this.setState({backgroundColor: 'red'});
// break;
// case SWIPE_DOWN:
// this.setState({backgroundColor: 'green'});
// break;
// case SWIPE_LEFT:
// this.setState({backgroundColor: 'blue'});
// break;
// case SWIPE_RIGHT:
// this.setState({backgroundColor: 'yellow'});
// break;
// }
// }
render() {
const config = {
velocityThreshold: 0.3,
directionalOffsetThreshold: 80
};
return (
<GestureRecognizer
// onSwipe={(direction, state) => this.onSwipe(direction, state)}
// onSwipeUp={(state) => this.onSwipeUp(state)}
// onSwipeDown={(state) => this.onSwipeDown(state)}
onSwipeLeft={(state) => this.onSwipeLeft(state)}
onSwipeRight={(state) => this.onSwipeRight(state)}
config={config}
style={{
flex: 1,
backgroundColor: this.state.backgroundColor
}}
>
<Animated.View style={{ elevation: 4, width: width*3/4, position: 'absolute', top: 0, bottom: 0, left: this.state.left, backgroundColor: 'red' }}>
</Animated.View>
<Text>{this.state.myText}</Text>
<Text>onSwipe callback received gesture: {this.state.gestureName}</Text>
</GestureRecognizer>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
});