-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
111 lines (104 loc) · 2.88 KB
/
App.js
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
import React, { useState } from 'react';
import { SafeAreaView, StyleSheet, Text, View, Pressable } from 'react-native';
function App() {
const [withoutFeedbackPressed, setWithoutFeedbackPressed] = useState(0);
const [opacityPressed, setOpacityPressed] = useState(0);
const [highlightPressed, setHighlightPressed] = useState(0);
return (
<View style={styles.screen}>
<SafeAreaView style={styles.safeArea}>
<View style={styles.header}>
<Text style={styles.headerText}>React Native Pressable</Text>
</View>
</SafeAreaView>
<View style={styles.content}>
<View style={styles.buttonRow}>
<Text style={styles.label}>
Pressable as a TouchableWithoutFeedback
</Text>
<Pressable
onPress={() =>
setWithoutFeedbackPressed(withoutFeedbackPressed + 1)
}
style={() => [styles.button]}>
<Text style={styles.buttonText}>
{`${withoutFeedbackPressed} pressed`}
</Text>
</Pressable>
</View>
<View style={styles.buttonRow}>
<Text style={styles.label}>Pressable as a TouchableOpacity</Text>
<Pressable
onPress={() => setOpacityPressed(opacityPressed + 1)}
style={({ pressed }) => [
styles.button,
{ opacity: pressed ? 0.5 : 1 },
]}>
<Text style={styles.buttonText}>{`${opacityPressed} pressed`}</Text>
</Pressable>
</View>
<View style={styles.buttonRow}>
<Text style={styles.label}>Pressable as a TouchableHighlight</Text>
<Pressable
onPress={() => setHighlightPressed(highlightPressed + 1)}
style={({ pressed }) => [
styles.button,
{
backgroundColor: pressed ? '#008080' : '#a4c936',
opacity: pressed ? 0.5 : 1,
},
]}>
<Text style={styles.buttonText}>
{`${highlightPressed} pressed`}
</Text>
</Pressable>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
screen: {
flex: 1,
backgroundColor: '#f2f2fC',
},
safeArea: {
backgroundColor: '#62d1bc',
},
header: {
height: 50,
backgroundColor: '#62d1bc',
alignItems: 'center',
justifyContent: 'center',
},
headerText: {
color: '#ffffff',
fontSize: 20,
},
content: {
flex: 1,
},
buttonRow: {
justifyContent: 'center',
paddingHorizontal: 16,
paddingTop: 28,
},
button: {
paddingVertical: 12,
backgroundColor: '#a4c936',
borderRadius: 8,
},
buttonText: {
textAlign: 'center',
color: '#ffffff',
fontSize: 15,
fontWeight: '600',
},
label: {
fontSize: 15,
fontWeight: '700',
color: '#2C2C2C',
paddingVertical: 12,
},
});
export default App;