-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.tsx
153 lines (146 loc) · 4.24 KB
/
App.tsx
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
import React, {useState} from 'react';
import {SafeAreaView, StyleSheet, Text, TextInput, View} from 'react-native';
import {
KeyboardAwareScrollView,
KeyboardProvider,
} from 'react-native-keyboard-controller';
type FormSchema = {
username: string;
firstname: string;
lastname: string;
email: string;
addressOne: string;
addressTwo: string;
phoneNumber: string;
promoCode: string;
message: string;
comment: string;
};
type FormKey = keyof FormSchema;
function App(): React.JSX.Element {
const [form, setForm] = useState<FormSchema>({
username: '',
firstname: '',
lastname: '',
email: '',
addressOne: '',
addressTwo: '',
phoneNumber: '',
promoCode: '',
message: '',
comment: '',
});
const changeFormChange = (key: FormKey, value: string) => {
setForm(prev => ({...prev, [key]: value}));
};
return (
<KeyboardProvider>
<SafeAreaView style={styles.container}>
<KeyboardAwareScrollView
bottomOffset={50}
style={styles.container}
contentContainerStyle={styles.content}>
<Text style={styles.heading}>Keyboard Aware ScrollView</Text>
<TextInput
style={styles.input}
value={form.username}
placeholder="Username"
placeholderTextColor="#747474"
testID={`TextInput#Username`}
onChangeText={value => changeFormChange('username', value)}
/>
<TextInput
style={styles.input}
value={form.firstname}
placeholder="Firstname"
placeholderTextColor="#747474"
testID={`TextInput#Firstname`}
onChangeText={value => changeFormChange('firstname', value)}
/>
<TextInput
style={styles.input}
value={form.lastname}
placeholder="Lastname"
placeholderTextColor="#747474"
testID={`TextInput#Lastname`}
onChangeText={value => changeFormChange('lastname', value)}
/>
<TextInput
style={styles.input}
value={form.email}
placeholder="Email"
placeholderTextColor="#747474"
testID={`TextInput#Email`}
onChangeText={value => changeFormChange('email', value)}
/>
<TextInput
style={styles.input}
value={form.addressOne}
placeholder="Address 1"
placeholderTextColor="#747474"
testID={`TextInput#Address`}
onChangeText={value => changeFormChange('addressOne', value)}
/>
<TextInput
style={styles.input}
value={form.addressTwo}
placeholder="Address 2"
placeholderTextColor="#747474"
testID={`TextInput#Address`}
onChangeText={value => changeFormChange('addressTwo', value)}
/>
<TextInput
style={styles.input}
value={form.phoneNumber}
placeholder="Phone number"
placeholderTextColor="#747474"
testID={`TextInput#Phone`}
onChangeText={value => changeFormChange('phoneNumber', value)}
/>
<TextInput
style={styles.input}
value={form.message}
placeholder="Message"
placeholderTextColor="#747474"
testID={`TextInput#Message`}
onChangeText={value => changeFormChange('message', value)}
/>
<TextInput
style={styles.input}
value={form.comment}
placeholder="Comment"
placeholderTextColor="#747474"
testID={`TextInput#Comment`}
onChangeText={value => changeFormChange('comment', value)}
/>
</KeyboardAwareScrollView>
</SafeAreaView>
</KeyboardProvider>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
},
heading: {
fontSize: 36,
fontWeight: '800',
marginBottom: 8,
color: '#000',
},
content: {
padding: 16,
gap: 8,
},
input: {
height: 48,
borderRadius: 12,
paddingHorizontal: 12,
backgroundColor: '#fafafa',
borderWidth: 1,
borderColor: '#dddddd',
color: '#000',
},
});
export default App;