-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignUpScreen.jsx
122 lines (119 loc) · 2.76 KB
/
SignUpScreen.jsx
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
import React, { useState } from 'react';
import {
View,
StyleSheet,
TextInput,
Text,
TouchableOpacity,
Alert,
} from 'react-native';
import firebase from 'firebase';
import Button from '../components/Button';
import { translateErrors } from '../utils';
function SingUpScreen(props) {
const { navigation } = props;
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
function handlePress() {
firebase
.auth()
.createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
const { user } = userCredential;
navigation.reset({
index: 0,
routes: [{ name: 'MemoList' }],
});
})
.catch((error) => {
const errorMsg = translateErrors(error.code);
Alert.alert(errorMsg.title, errorMsg.description);
});
}
return (
<View style={styles.container}>
<View style={styles.inner}>
<Text style={styles.title}>Sign Up</Text>
<TextInput
style={styles.input}
value={email}
onChangeText={(text) => {
setEmail(text);
}}
autoCapitalize="none"
keyboardType="email-address"
placeholder="Email Address"
textContentType="emailAddress"
/>
<TextInput
style={styles.input}
value={password}
onChangeText={(text) => {
setPassword(text);
}}
autoCapitalize="none"
placeholder="Password"
secureTextEntry
/>
<Button
label="Submit"
onPress={() => {
handlePress();
}}
/>
<View style={styles.footer}>
<Text style={styles.footerText}>Already registered?</Text>
<TouchableOpacity
onPress={() => {
navigation.reset({
index: 0,
routes: [{ name: 'Login' }],
});
}}
>
<Text style={styles.footerLink}>Log in</Text>
</TouchableOpacity>
</View>
</View>
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'rgba(244,223,186,0.3)',
},
inner: {
paddingHorizontal: 27,
paddingVertical: 24,
},
title: {
fontSize: 24,
lineHeight: 32,
fontWeight: 'bold',
marginBottom: 24,
},
input: {
backgroundColor: '#fff',
fontSize: 16,
minHeight: 48,
borderColor: '#ddd',
borderWidth: 1,
paddingHorizontal: 8,
marginBottom: 16,
},
footer: {
flexDirection: 'row',
},
footerText: {
fontSize: 14,
lineHeight: 24,
marginRight: 8,
},
footerLink: {
fontSize: 14,
lineHeight: 24,
color: '#876445',
},
});
export default SingUpScreen;