-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Expand file tree
/
Copy pathindex.tsx
More file actions
99 lines (91 loc) · 2.17 KB
/
index.tsx
File metadata and controls
99 lines (91 loc) · 2.17 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
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { Pressable } from 'react-native-gesture-handler';
export default function PressableExample() {
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={{ flex: 1, backgroundColor: 'white' }}>
<View style={styles.pressRectContainer}>
<View style={styles.hitRectContainer}>
<Pressable
style={({ pressed }) =>
pressed ? styles.highlight : styles.pressable
}
onPressIn={pressIn}
onPressOut={pressOut}
onPress={press}
onHoverIn={hoverIn}
onHoverOut={hoverOut}
onLongPress={longPress}
hitSlop={20}
pressRetentionOffset={20}>
<View style={styles.textWrapper}>
<Text style={styles.text}>Pressable!</Text>
</View>
</Pressable>
<Text style={styles.rectText}>Hit Rect</Text>
</View>
<Text style={styles.rectText}>Press Rect</Text>
</View>
</View>
);
}
const BACKGROUND_COLOR = '#F5FCFF';
const styles = StyleSheet.create({
pressRectContainer: {
backgroundColor: '#FFD6E0',
padding: 20,
width: 200,
height: 200,
margin: 'auto',
},
hitRectContainer: {
backgroundColor: '#F29DC3',
padding: 20,
width: 160,
height: 160,
margin: 'auto',
},
rectText: {
color: BACKGROUND_COLOR,
fontWeight: '700',
position: 'absolute',
right: 5,
bottom: 2,
},
pressable: {
width: 120,
height: 120,
backgroundColor: 'mediumpurple',
},
highlight: {
width: 120,
height: 120,
backgroundColor: 'red',
},
textWrapper: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
},
text: {
color: BACKGROUND_COLOR,
},
});