-
Notifications
You must be signed in to change notification settings - Fork 0
/
LoginScreen.js
194 lines (180 loc) · 5.15 KB
/
LoginScreen.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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
import React, { useState, useEffect } from "react";
import {
View,
Text,
TextInput,
TouchableOpacity,
StyleSheet,
ImageBackground,
Animated,
TouchableWithoutFeedback,
Keyboard,
} from "react-native";
import { getAuth, signInWithEmailAndPassword } from "firebase/auth";
import { useNavigation } from "@react-navigation/native";
import Icon from "react-native-vector-icons/Ionicons";
const LoginScreen = () => {
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
const [errorMessage, setErrorMessage] = useState(null);
const navigation = useNavigation(); // Navigation instance
// Add an Animated.Value to the state
const [backgroundScale] = useState(new Animated.Value(1));
// Create a function that starts the zoom animation loop
const startZoomAnimation = () => {
Animated.sequence([
Animated.timing(backgroundScale, {
toValue: 1.2,
duration: 10000,
useNativeDriver: true,
}),
Animated.timing(backgroundScale, {
toValue: 1,
duration: 10000,
useNativeDriver: true,
}),
]).start(() => startZoomAnimation());
};
// Start the zoom animation loop when the component mounts
useEffect(() => {
startZoomAnimation();
}, []);
const handleGoBack = () => {
navigation.goBack();
};
const handleLogin = async () => {
try {
if (email && password) {
const auth = getAuth();
await signInWithEmailAndPassword(auth, email, password);
console.log("User logged in successfully!");
} else {
setErrorMessage("Please enter a valid email and password.");
}
} catch (error) {
console.error(error);
}
};
const handleForgotPassword = () => {
// Navigate to ForgotPasswordScreen
// console.log("Forgot Password button pressed");
navigation.navigate("ForgotPassword");
};
return (
<TouchableWithoutFeedback onPress={Keyboard.dismiss}>
<View style={styles.container}>
<Animated.View
style={[
styles.backgroundImageContainer,
{
transform: [
{
scale: backgroundScale,
},
],
},
]}
>
<ImageBackground
source={{
uri: "https://cdn.midjourney.com/abbe3e25-f891-461a-a354-56afa58c2f93/0_2.png",
}}
resizeMode="cover"
style={styles.backgroundImage}
/>
</Animated.View>
<TouchableOpacity onPress={handleGoBack} style={styles.backButton}>
<Icon name="arrow-back" size={30} color="white" />
</TouchableOpacity>
<View style={styles.formContainer}>
{errorMessage && <Text style={{ color: "red" }}>{errorMessage}</Text>}
<TextInput
placeholder="Email"
style={styles.input}
placeholderTextColor="gray"
value={email}
onChangeText={setEmail}
/>
<TextInput
placeholder="Password"
secureTextEntry
style={styles.input}
placeholderTextColor="gray"
value={password}
onChangeText={setPassword}
/>
<TouchableOpacity
style={{
width: "100%",
backgroundColor: "#252526",
borderRadius: 34,
padding: 24,
justifyContent: "center",
alignItems: "center",
marginBottom: 0,
marginTop: 20,
}}
onPress={handleLogin}
>
<Text style={{ color: "white" }}>Login</Text>
</TouchableOpacity>
<TouchableOpacity onPress={handleForgotPassword}>
<Text style={{ marginTop: 20, color: "white" }}>
Forgot Password?
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => navigation.navigate("Register")}>
<Text style={{ marginTop: 20, color: "white" }}>
Don't have an account? Register
</Text>
</TouchableOpacity>
</View>
</View>
</TouchableWithoutFeedback>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
alignItems: "center",
justifyContent: "center",
},
input: {
padding: 24,
paddingLeft: 15,
paddingRight: 15,
backgroundColor: "rgba(255, 255, 255, 0.8)",
borderRadius: 34,
width: "100%",
marginBottom: 15,
color: "black",
marginTop: 50,
},
backgroundImage: {
flex: 1,
justifyContent: "center",
alignItems: "center",
width: "100%",
height: "100%",
},
backButton: {
backgroundColor: "#252526",
borderRadius: 40,
padding: 24,
position: "absolute",
top: 80, // Adjust the value according to your preference
left: 20, // Adjust the value according to your preference
},
backgroundImageContainer: {
...StyleSheet.absoluteFillObject,
justifyContent: "center",
alignItems: "center",
backgroundColor: "black",
},
formContainer: {
position: "absolute",
alignItems: "center",
justifyContent: "center",
},
});
export default LoginScreen;