You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import React, {useState, useContext} from "react";
  2. import {
  3. SafeAreaView,
  4. View,
  5. Text,
  6. TouchableOpacity,
  7. StyleSheet,
  8. } from "react-native";
  9. import MaterialIcons from "@expo/vector-icons/MaterialIcons";
  10. import Ionicons from "@expo/vector-icons/Ionicons";
  11. import LoginSVG from "../assets/images/login.svg";
  12. import GoogleSVG from "../assets/images/google.svg";
  13. import FacebookSVG from "../assets/images/facebook.svg";
  14. import TwitterSVG from "../assets/images/twitter.svg";
  15. import CustomButton from "../components/Buttons/CustomButton";
  16. import InputField from "../components/InputField";
  17. import { globalStyles } from "../styles/global";
  18. import { AuthContext } from "../context/AuthContext";
  19. import Loader from "../components/Loader";
  20. const LoginScreen = ({ navigation }) => {
  21. const [email, setEmail] = useState(null);
  22. const [password, setPassword] = useState(null);
  23. const [error, setError] = useState(null);
  24. const {isLoading, login, googleAuth} = useContext(AuthContext);
  25. const handleLogin = () => {
  26. login(email, password, function(result) {
  27. setError(result.error.message);
  28. });
  29. }
  30. return (
  31. <SafeAreaView style={globalStyles.safeArea}>
  32. <Loader visible={isLoading} />
  33. <View style={{ paddingHorizontal: 25 }}>
  34. <View style={{ alignItems: "center" }}>
  35. <LoginSVG height={300} width={300} />
  36. </View>
  37. <Text style={globalStyles.boldText}>Sign In</Text>
  38. <InputField
  39. label={"Email"}
  40. keyboardType="email-address"
  41. onChangeText={text => {
  42. setEmail(text);
  43. }}
  44. text={email}
  45. icon={
  46. <MaterialIcons
  47. name="alternate-email"
  48. size={20}
  49. color="#666"
  50. style={{ marginRight: 5 }}
  51. />
  52. }
  53. />
  54. <InputField
  55. label={"Password"}
  56. filedButtonLabel={"Forgot?"}
  57. fieldButtonFunction={() => {}}
  58. inputType="password"
  59. text={password}
  60. onChangeText={text => {
  61. setPassword(text);
  62. }}
  63. icon={
  64. <Ionicons
  65. name="ios-lock-closed-outline"
  66. size={20}
  67. color="#666"
  68. style={{ marginRight: 5 }}
  69. />
  70. }
  71. />
  72. {error && <Text style={styles.errorMessage}>{error}</Text>}
  73. <CustomButton label={"Login"} onPress={handleLogin} />
  74. <Text style={globalStyles.regularCenteredText}>Or login with ...</Text>
  75. <View style={styles.providersContainer}>
  76. <TouchableOpacity onPress={googleAuth} style={globalStyles.iconButton}>
  77. <GoogleSVG height={24} width={24} />
  78. </TouchableOpacity>
  79. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  80. <FacebookSVG height={24} width={24} />
  81. </TouchableOpacity>
  82. <TouchableOpacity onPress={() => {}} style={globalStyles.iconButton}>
  83. <TwitterSVG height={24} width={24} />
  84. </TouchableOpacity>
  85. </View>
  86. <View style={styles.registerContainer}>
  87. <Text style={globalStyles.regularText}>Need account? </Text>
  88. <TouchableOpacity onPress={() => navigation.navigate("Register")}>
  89. <Text style={styles.registerButtonText}>Sign Up</Text>
  90. </TouchableOpacity>
  91. </View>
  92. </View>
  93. </SafeAreaView>
  94. );
  95. };
  96. const styles = StyleSheet.create({
  97. providerText: {
  98. textAlign: "center",
  99. color: "#666",
  100. marginBottom: 30,
  101. fontFamily: "poppins-regular",
  102. },
  103. providersContainer: {
  104. flexDirection: "row",
  105. justifyContent: "space-between",
  106. marginBottom: 30,
  107. },
  108. registerContainer: {
  109. flexDirection: "row",
  110. justifyContent: "center",
  111. marginBottom: 30,
  112. },
  113. registerButtonText: {
  114. color: "#AD40AF",
  115. fontWeight: "700",
  116. fontFamily: "poppins-semibold",
  117. },
  118. errorMessage: {
  119. marginBottom: 30,
  120. color: 'red'
  121. }
  122. });
  123. export default LoginScreen;