-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
59 lines (54 loc) · 1.47 KB
/
index.tsx
File metadata and controls
59 lines (54 loc) · 1.47 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
import React, { Component } from 'react';
import { StyleSheet, View } from 'react-native';
import {
State,
TapGestureHandler,
TapGestureHandlerStateChangeEvent,
} from 'react-native-gesture-handler';
interface PressBoxProps {
setDuration?: (duration: number) => void;
}
export class PressBox extends Component<PressBoxProps> {
private doubleTapRef = React.createRef<TapGestureHandler>();
private onSingleTap = (event: TapGestureHandlerStateChangeEvent) => {
if (event.nativeEvent.state === State.ACTIVE) {
// eslint-disable-next-line no-alert
window.alert("I'm touched");
}
};
private onDoubleTap = (event: TapGestureHandlerStateChangeEvent) => {
if (event.nativeEvent.state === State.ACTIVE) {
// eslint-disable-next-line no-alert
window.alert('Double tap, good job!');
}
};
render() {
return (
<TapGestureHandler
onHandlerStateChange={this.onSingleTap}
waitFor={this.doubleTapRef}>
<TapGestureHandler
ref={this.doubleTapRef}
onHandlerStateChange={this.onDoubleTap}
numberOfTaps={2}>
<View style={styles.box} />
</TapGestureHandler>
</TapGestureHandler>
);
}
}
export default class Example extends Component<Record<string, never>> {
render() {
return <PressBox />;
}
}
const styles = StyleSheet.create({
box: {
width: 150,
height: 150,
alignSelf: 'center',
backgroundColor: 'plum',
margin: 10,
zIndex: 200,
},
});