forked from software-mansion/react-native-gesture-handler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
124 lines (107 loc) · 3.16 KB
/
index.js
File metadata and controls
124 lines (107 loc) · 3.16 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
import React, { Component } from 'react';
import { Alert, StyleSheet, View, PanResponder } from 'react-native';
import { ScrollView } from 'react-native-gesture-handler';
import { DraggableBox } from '../draggable';
import { LoremIpsum } from '../common';
var CIRCLE_SIZE = 80;
// A clone of: https://github.com/facebook/react-native/blob/master/RNTester/js/PanResponderExample.js
class PanResponderExample extends Component {
_panResponder = {};
_previousLeft = 0;
_previousTop = 0;
_circleStyles = {};
componentWillMount() {
this._panResponder = PanResponder.create({
onStartShouldSetPanResponder: this._handleStartShouldSetPanResponder,
onMoveShouldSetPanResponder: this._handleMoveShouldSetPanResponder,
onPanResponderGrant: this._handlePanResponderGrant,
onPanResponderMove: this._handlePanResponderMove,
onPanResponderRelease: this._handlePanResponderEnd,
onPanResponderTerminate: this._handlePanResponderEnd,
});
this._previousLeft = 20;
this._previousTop = 84;
this._circleStyles = {
style: {
left: this._previousLeft,
top: this._previousTop,
backgroundColor: 'green',
},
};
}
componentDidMount() {
this._updateNativeStyles();
}
render() {
return (
<View
ref={circle => {
this.circle = circle;
}}
style={styles.circle}
{...this._panResponder.panHandlers}
/>
);
}
_highlight = () => {
this._circleStyles.style.backgroundColor = 'blue';
this._updateNativeStyles();
};
_unHighlight = () => {
this._circleStyles.style.backgroundColor = 'green';
this._updateNativeStyles();
};
_updateNativeStyles = () => {
this.circle && this.circle.setNativeProps(this._circleStyles);
};
_handleStartShouldSetPanResponder = (e, gestureState) => {
// Should we become active when the user presses down on the circle?
return true;
};
_handleMoveShouldSetPanResponder = (e, gestureState) => {
// Should we become active when the user moves a touch over the circle?
return true;
};
_handlePanResponderGrant = (e, gestureState) => {
this._highlight();
};
_handlePanResponderMove = (e, gestureState) => {
this._circleStyles.style.left = this._previousLeft + gestureState.dx;
this._circleStyles.style.top = this._previousTop + gestureState.dy;
this._updateNativeStyles();
};
_handlePanResponderEnd = (e, gestureState) => {
this._unHighlight();
this._previousLeft += gestureState.dx;
this._previousTop += gestureState.dy;
};
}
export default class Example extends Component {
_onClick = () => {
Alert.alert("I'm so touched");
};
render() {
return (
<ScrollView
waitFor={['dragbox', 'image_pinch', 'image_rotation', 'image_tilt']}
style={styles.scrollView}>
<LoremIpsum words={40} />
<PanResponderExample />
<DraggableBox />
<LoremIpsum />
</ScrollView>
);
}
}
const styles = StyleSheet.create({
scrollView: {
flex: 1,
backgroundColor: '#F5FCFF',
},
circle: {
width: CIRCLE_SIZE,
height: CIRCLE_SIZE,
borderRadius: CIRCLE_SIZE / 2,
zIndex: 100,
},
});