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
74 lines (69 loc) · 1.7 KB
/
index.js
File metadata and controls
74 lines (69 loc) · 1.7 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
import React, { Component } from 'react';
import { Alert, StyleSheet, View } from 'react-native';
import {
LongPressGestureHandler,
ScrollView,
State,
TapGestureHandler,
} from 'react-native-gesture-handler';
import { LoremIpsum } from '../common';
export class PressBox extends Component {
doubleTapRef = React.createRef();
_onHandlerStateChange = event => {
if (event.nativeEvent.state === State.ACTIVE) {
Alert.alert("I'm being pressed for so long");
}
};
_onSingleTap = event => {
if (event.nativeEvent.state === State.ACTIVE) {
Alert.alert("I'm touched");
}
};
_onDoubleTap = event => {
if (event.nativeEvent.state === State.ACTIVE) {
Alert.alert('D0able tap, good job!');
}
};
render() {
return (
<LongPressGestureHandler
onHandlerStateChange={this._onHandlerStateChange}
minDurationMs={800}>
<TapGestureHandler
onHandlerStateChange={this._onSingleTap}
waitFor={this.doubleTapRef}>
<TapGestureHandler
ref={this.doubleTapRef}
onHandlerStateChange={this._onDoubleTap}
numberOfTaps={2}>
<View style={styles.box} />
</TapGestureHandler>
</TapGestureHandler>
</LongPressGestureHandler>
);
}
}
export default class Example extends Component {
render() {
return (
<ScrollView style={styles.scrollView}>
<LoremIpsum words={40} />
<PressBox />
<LoremIpsum />
</ScrollView>
);
}
}
const styles = StyleSheet.create({
scrollView: {
flex: 1,
},
box: {
width: 150,
height: 150,
alignSelf: 'center',
backgroundColor: 'plum',
margin: 10,
zIndex: 200,
},
});