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
import React, { useState } from "react";
import {
StyleSheet,
TextInput,
Button,
Image,
Dimensions,
View,
Text,
ActivityIndicator,
} from "react-native";
import EditScreenInfo from "../components/EditScreenInfo";
// import { Text, View } from '../components/Themed';
import { TouchableOpacity } from "react-native";
import { ScrollView, Toast } from "native-base";
import { ERROR_TOAST_PROPS } from "../util/util";
import { screenWidth, styles } from "../util/styles";
import TTS_logo from "../assets/images/TTS_logo.jpeg";
export const LoginScreen = ({ onLogin, navigation }) => {
return (
<ScrollView style={styles.loginScreenContainer}>
<View style={{ alignContent: "center", justifyContent: "center" }}>
<Text
style={{
padding: 10,
textAlign: "center",
fontWeight: "bold",
fontSize: 30,
}}
>
Driver App
</Text>
<Image
source={TTS_logo}
style={{
height: screenWidth - 30,
width: screenWidth - 30,
margin: "auto",
}}
/>
</View>
<Text
style={{
padding: 10,
textAlign: "center",
// fontWeight: 'bold',
fontSize: 40,
}}
>
Login
</Text>
<View
style={{ flexDirection: "row", padding: 10, justifyContent: "center" }}
>
<Text style={{ textAlign: "center" }}>Don't have an account? </Text>
<Text
style={{ fontWeight: "bold", textAlign: "center" }}
onPress={() => navigation.replace("Signup")}
>
Sign up
</Text>
</View>
<View style={styles.formContainer}>
<LoginForm onLogin={onLogin} />
</View>
</ScrollView>
);
};
const LoginForm = ({ onLogin, navigation }) => {
var passwordInput;
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [loading, setLoading] = useState(false);
const onSubmit = () => {
console.log({ username, password });
setLoading(true);
if (!username || !password) {
Toast.show({
title: "Please fill in all the fields!",
...ERROR_TOAST_PROPS,
});
} else {
onLogin(username, password);
}
setLoading(false);
};
return (
<View>
<TextInput
style={styles.input}
defaultValue={username}
onChangeText={(e) => {
console.log(e);
setUsername(e);
}}
autoCapitalize="none"
onSubmitEditing={() => passwordInput.focus()}
autoCorrect={false}
keyboardType="email-address"
returnKeyType="next"
placeholder="Email"
// placeholderTextColor='rgba(225,225,225,0.7)'
/>
<TextInput
style={styles.input}
defaultValue={password}
onChangeText={(e) => setPassword(e)}
returnKeyType="go"
autoCapitalize="none"
ref={(input) => (passwordInput = input)}
placeholder="Password"
onSubmitEditing={onSubmit}
// placeholderTextColor='rgba(225,225,225,0.7)'
secureTextEntry
/>
<TouchableOpacity
style={styles.buttonContainer}
// onPress={onButtonPress}
// disabled={!username || !password}
onPress={onSubmit}
disabled={loading}
>
{loading ? (
<ActivityIndicator />
) : (
<Text style={styles.buttonText}>LOGIN</Text>
)}
</TouchableOpacity>
</View>
// define your styles
);
};