forked from Galaxies-dev/meetings-react-native-stream
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
109 lines (103 loc) · 2.58 KB
/
index.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
import {
Text,
StyleSheet,
Alert,
Button,
TextInput,
TouchableOpacity,
KeyboardAvoidingView,
Platform,
} from 'react-native';
import React, { useState } from 'react';
import Colors from '../constants/Colors';
import Spinner from 'react-native-loading-spinner-overlay';
import { useAuth } from '../context/AuthContext';
const Page = () => {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [loading, setLoading] = useState(false);
const { onLogin, onRegister } = useAuth();
// Sign in with email and password
const onSignInPress = async () => {
setLoading(true);
try {
const result = await onLogin!(email, password);
} catch (e) {
Alert.alert('Error', 'Could not log in');
} finally {
setLoading(false);
}
};
// Create a new user
const onSignUpPress = async () => {
setLoading(true);
try {
const result = await onRegister!(email, password);
} catch (e) {
Alert.alert('Error', 'Could not log in');
} finally {
setLoading(false);
}
};
return (
<KeyboardAvoidingView
behavior={Platform.OS === 'ios' ? 'padding' : 'height'}
style={styles.container}>
<Spinner visible={loading} />
<Text style={styles.header}>Meet Me</Text>
<Text style={styles.subheader}>The fastest way to meet</Text>
<TextInput
autoCapitalize="none"
placeholder="[email protected]"
value={email}
onChangeText={setEmail}
style={styles.inputField}
/>
<TextInput
placeholder="password"
value={password}
onChangeText={setPassword}
secureTextEntry
style={styles.inputField}
/>
<TouchableOpacity onPress={onSignInPress} style={styles.button}>
<Text style={{ color: '#fff' }}>Sign in</Text>
</TouchableOpacity>
<Button onPress={onSignUpPress} title="Create Account" color={Colors.primary}></Button>
</KeyboardAvoidingView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 20,
paddingHorizontal: '20%',
justifyContent: 'center',
},
header: {
fontSize: 30,
textAlign: 'center',
marginBottom: 10,
},
subheader: {
fontSize: 18,
textAlign: 'center',
marginBottom: 40,
},
inputField: {
marginVertical: 4,
height: 50,
borderWidth: 1,
borderColor: Colors.primary,
borderRadius: 4,
padding: 10,
},
button: {
marginVertical: 15,
alignItems: 'center',
backgroundColor: Colors.primary,
padding: 12,
borderRadius: 4,
},
});
export default Page;