-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathhitSlopExample.tsx
More file actions
87 lines (78 loc) · 1.96 KB
/
hitSlopExample.tsx
File metadata and controls
87 lines (78 loc) · 1.96 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
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import TestingBase from './testingBase';
const HIT_SLOP = 40;
const PRESS_RETENTION_OFFSET = HIT_SLOP;
export function HitSlopExample() {
const pressIn = () => {
console.log('Pressable pressed in');
};
const pressOut = () => {
console.log('Pressable pressed out');
};
const press = () => {
console.log('Pressable pressed');
};
const hoverIn = () => {
console.log('Hovered in');
};
const hoverOut = () => {
console.log('Hovered out');
};
const longPress = () => {
console.log('Long pressed');
};
return (
<View style={styles.retentionIndicator}>
<View style={styles.slopIndicator}>
<View style={styles.container}>
<TestingBase
style={styles.pressable}
hitSlop={HIT_SLOP}
pressRetentionOffset={PRESS_RETENTION_OFFSET}
onPressIn={() => pressIn()}
onPressOut={() => pressOut()}
onPress={() => press()}
onHoverIn={() => hoverIn()}
onHoverOut={() => hoverOut()}
onLongPress={() => longPress()}
/>
</View>
<Text style={styles.text}>Hit Slop</Text>
</View>
<Text style={styles.text}>Retention Offset</Text>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
justifyContent: 'flex-start',
alignItems: 'center',
gap: 40,
},
pressable: {
backgroundColor: 'mediumpurple',
width: 100,
height: 100,
},
text: {
alignSelf: 'flex-end',
marginBottom: 4,
marginRight: 6,
marginTop: 12,
},
slopIndicator: {
display: 'flex',
alignItems: 'center',
width: 100 + HIT_SLOP * 2,
borderRightWidth: StyleSheet.hairlineWidth,
},
retentionIndicator: {
display: 'flex',
alignItems: 'center',
width: 180 + PRESS_RETENTION_OFFSET * 2,
borderRightWidth: StyleSheet.hairlineWidth,
margin: 20,
},
});