Last active
October 4, 2018 09:07
-
-
Save janhesters/4c217d12178b9d71f85af019d0226d05 to your computer and use it in GitHub Desktop.
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> | |
| } | |
| export default class LoginForm extends Component<Props, object> { | |
| renderForm = ({ | |
| values, | |
| handleSubmit, | |
| setFieldValue, | |
| touched, | |
| errors, | |
| setFieldTouched, | |
| isSubmitting | |
| }: FormikProps<FormValues>) => ( | |
| <View style={styles.container}> | |
| <Input | |
| placeholder={strings.emailAddress} | |
| keyboardType="email-address" | |
| autoCapitalize="none" | |
| value={values.email} | |
| onChangeText={value => setFieldValue("email", value)} | |
| onBlur={() => setFieldTouched("email")} | |
| editable={!isSubmitting} | |
| errorMessage={touched.email && errors.email ? errors.email : undefined} | |
| /> | |
| <Input | |
| placeholder={strings.password} | |
| secureTextEntry | |
| autoCapitalize="none" | |
| value={values.password} | |
| onChangeText={value => setFieldValue("password", value)} | |
| onBlur={() => setFieldTouched("password")} | |
| editable={!isSubmitting} | |
| errorMessage={touched.password && errors.password ? errors.password : undefined} | |
| /> | |
| <Button | |
| clear | |
| title={loginStrings.forgottenPassword} | |
| containerStyle={styles.forgottenPasswordButtonContainer} | |
| titleStyle={styles.forgottenPasswordTitle} | |
| onPress={() => this.props.navigation.navigate("PasswordResetScreen")} | |
| /> | |
| <Button | |
| title={loginStrings.loginTitle} | |
| containerStyle={styles.loginButtonContainer} | |
| buttonStyle={styles.loginButton} | |
| disabledStyle={styles.disabled} | |
| titleStyle={styles.loginButtonTitle} | |
| disabledTitleStyle={styles.loginButtonTitle} | |
| onPress={handleSubmit} | |
| disabled={isSubmitting} | |
| loading={isSubmitting} | |
| loadingProps={{ size: "large", color: "white" }} | |
| /> | |
| </View> | |
| ); | |
| render() { | |
| return ( | |
| <Formik | |
| initialValues={{ email: "", password: "" }} | |
| onSubmit={() => {}} | |
| render={(formikBag: FormikProps<FormValues>) => this.renderForm(formikBag)} | |
| /> | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment