import React from "react"; import { Image, KeyboardAvoidingView, StyleSheet, Text, TextInput, View, } from "react-native"; // @ts-ignore import type { ImageSource } from "react-native/Libraries/Image/ImageSource"; import ScreenContainer from "../components/ScreenContainer"; import Button from "../components/DeprecatedButton"; import { withTheme } from "../core/theming"; import { Theme } from "../types"; import { GROUPS, COMPONENT_TYPES, FORM_TYPES, PROP_TYPES, } from "../core/component-types"; import { DataContext } from "../core/DataContext"; type Props = { theme: Theme; mainImage: ImageSource; welcomeText: string; navigation: { navigate: (screen: string) => void; }; navigateToOnLogin: string; navigateToOnSignUp: string; }; const EmailLoginScreen = (props: Props) => { const [emailInput, setEmailInput] = React.useState(""); const [passwordInput, setPasswordInput] = React.useState(""); const [errorMessage, setErrorMessage] = React.useState(""); const { theme, mainImage, welcomeText, navigation, navigateToOnLogin, navigateToOnSignUp, } = props; const { signInWithEmailAndPassword } = React.useContext(DataContext); return ( {mainImage ? ( ) : null} {welcomeText} setEmailInput(email)} placeholder="Email" clearTextOnFocus={false} enablesReturnKeyAutomatically={true} placeholderTextColor={theme.colors.medium} clearButtonMode="while-editing" returnKeyType="next" textContentType="emailAddress" /> setPasswordInput(password)} value={passwordInput} placeholderTextColor={theme.colors.medium} clearButtonMode="while-editing" secureTextEntry={true} returnKeyType="done" textContentType="password" /> {errorMessage ? ( {errorMessage} ) : null} {navigateToOnSignUp ? ( {"Don't have an account?"} ) : null} ); }; const styles = StyleSheet.create({ MainImage: { width: 80, height: 80, marginBottom: 46, }, EmailTextInput: { paddingRight: 14, paddingLeft: 14, borderBottomWidth: 1, borderTopWidth: 1, borderLeftWidth: 1, borderRightWidth: 1, marginTop: 12, marginBottom: 12, height: 54, }, PasswordTextInput: { marginBottom: 12, marginTop: 12, borderRightWidth: 1, borderLeftWidth: 1, borderTopWidth: 1, borderBottomWidth: 1, paddingRight: 14, paddingLeft: 14, height: 54, }, SignupButton: { borderTopWidth: 0, borderLeftWidth: 0, borderRightWidth: 0, alignSelf: "center", alignContent: "center", paddingLeft: 12, paddingRight: 12, borderBottomWidth: 0, }, LoginButton: { justifyContent: "center", height: 54, marginTop: 12, alignItems: "center", }, SignupView: { paddingLeft: 32, paddingRight: 32, paddingTop: 32, paddingBottom: 32, alignItems: "center", }, }); export default withTheme(EmailLoginScreen); export const SEED_DATA = { name: "Email Login Screen", tag: "EmailLoginScreen", category: COMPONENT_TYPES.screen, props: { mainImage: { group: GROUPS.data, label: "Main Image", description: "The source of the main image to show on the screen", editable: true, required: false, formType: FORM_TYPES.image, propType: PROP_TYPES.ASSET, defaultValue: null, }, navigateToOnLogin: { group: GROUPS.basic, label: "Post-login screen", description: "After a successful login, navigate to...", editable: true, required: false, formType: FORM_TYPES.string, propType: PROP_TYPES.STRING, }, navigateToOnSignUp: { group: GROUPS.basic, label: "Sign-up screen", description: "Go to this screen if the user wants to sign up", editable: true, required: false, formType: FORM_TYPES.string, propType: PROP_TYPES.STRING, }, welcomeText: { group: GROUPS.basic, label: "Welcome Text", description: "Displayed at the top of the login page", editable: true, required: true, formType: FORM_TYPES.string, propType: PROP_TYPES.STRING, }, }, };