This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import LocalizedStrings from "react-native-localization"; | |
| let strings = new LocalizedStrings({ | |
| en: { | |
| emailAddress: "Email address", | |
| password: "Password", | |
| invalidEmailFormat: "A valid email can only contain latin letters, numbers, '@' and '.'.", | |
| emailRequired: "An email address is required.", | |
| passwordRequired: "A password is required.", | |
| passwordMinLength: "A secure password must be at least 8 characters long." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import LoginForm from "./LoginForm"; | |
| export default LoginForm; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import strings from "./strings"; | |
| import styles from "./styles"; | |
| import { strings as loginStrings } from "../../screens/Login"; | |
| import React, { Component } from "react"; | |
| import { View } from "react-native"; | |
| import { Button, Input } from "react-native-elements"; | |
| import { NavigationScreenProp } from "react-navigation"; | |
| interface Props { | |
| navigation: NavigationScreenProp<any, any> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... imports | |
| import LoginForm from "../../components/LoginForm"; | |
| import { KeyboardAvoidingView, Platform } from "react-native"; | |
| import { NavigationScreenProp } from "react-navigation"; | |
| interface Props { | |
| navigation: NavigationScreenProp<any, any> | |
| } | |
| export default class LoginScreen extends Component<Props, object> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ... imports | |
| import { Formik, FormikProps, FormikActions } from "formik"; | |
| interface FormValues { | |
| email: string; | |
| password: string; | |
| } | |
| interface Props { | |
| navigation: NavigationScreenProp<any, any> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| handleSubmit = (values: FormValues, formikBag: FormikActions<FormValues>) => { | |
| formikBag.setSubmitting(true); | |
| // Here you would usually make a call to your API for a login. | |
| setTimeout(() => { | |
| formikBag.setSubmitting(false); | |
| this.props.navigation.navigate("HomeScreen"); | |
| }, 3000); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onSubmit={(values: FormValues, formikBag: FormikActions<FormValues>) => | |
| this.handleSubmit(values, formikBag) | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import { object as yupObject, string as yupString } from "yup"; | |
| // ... | |
| validationSchema={yupObject().shape({ | |
| email: yupString() | |
| .email(strings.invalidEmailFormat) | |
| .required(strings.emailRequired), | |
| password: yupString() | |
| .min(8, strings.passwordMinLength) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <KeyboardAvoidingView | |
| style={styles.container} | |
| behavior={Platform.OS === "ios" ? "padding" : undefined} | |
| > |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| describe("rendering", () => { | |
| let wrapper: ShallowWrapper; | |
| let props: Props; | |
| let Platform: PlatformStatic; | |
| beforeEach(() => { | |
| props = createTestProps({}); | |
| wrapper = shallow(<LoginScreen {...props} />); | |
| Platform = require("react-native").Platform; | |
| }); |