-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathApp.js
131 lines (120 loc) · 4.89 KB
/
App.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
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, View, KeyboardAvoidingView } from 'react-native';
import InputField from './components/InputField'
import InputButton from './components/InputButton'
import Heading from './components/Heading'
import ErrorMessage from './components/ErrorMessage'
import { Formik } from 'formik'
import * as Yup from 'yup'
const validationSchema = Yup.object().shape({
fullname: Yup.string()
.label('Fullname')
.required('Please enter your name'),
email: Yup.string()
.label('Email')
.email('Enter a valid email')
.required('Please enter your email address'),
password: Yup.string()
.label('Password')
.required('Please enter your password')
.min(4, 'Password must have at least 4 characters')
})
export default function App() {
return (
<KeyboardAvoidingView style={styles.avoidKeyboard} behavior="padding" enabled keyboardVerticalOffset={85}>
<View style={styles.container}>
<Heading h2 title="Signup Form" />
<View style={styles.form}>
<Formik
initialValues={{
fullname: '',
email: '',
password: ''
}}
onSubmit={(values) => {
// Use API to handle validated data
alert( JSON.stringify(values) );
}}
validationSchema={validationSchema}>
{({handleChange, values, handleSubmit, errors, isValid, isSubmitting, touched, handleBlur}) => (
<>
<InputField
name='fullname'
label='Full Name'
value={values.fullname}
onChangeText={handleChange('fullname')}
onBlur={handleBlur('fullname')}
placeholder='Enter your name'
returnKeyType='done'
iconName='ios-person'
iconColor='#533263'
/>
<ErrorMessage errorValue={touched.fullname && errors.fullname} />
<InputField
name='email'
label='Email Address'
value={values.email}
onChangeText={handleChange('email')}
onBlur={handleBlur('email')}
placeholder='Enter email'
keyboardType='email-address'
returnKeyType='done'
autoCapitalize='none'
iconName='ios-mail'
iconColor='#533263'
/>
<ErrorMessage errorValue={touched.email && errors.email} />
<InputField
name='password'
label='Password'
value={values.password}
onChangeText={handleChange('password')}
onBlur={handleBlur('password')}
placeholder='Enter password'
returnKeyType='done'
autoCapitalize='none'
secureTextEntry={true}
iconName='ios-lock'
iconColor='#533263'
/>
<ErrorMessage errorValue={touched.password && errors.password} />
<InputButton
onPress={handleSubmit}
disabled={! isValid || isSubmitting}
buttonType='solid'
title='SIGN UP'
buttonColor='#533263'
loading={ isSubmitting }
/>
</>
)}
</Formik>
</View>
<StatusBar style="auto" />
</View>
</KeyboardAvoidingView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#FAFBFE',
alignItems: 'center',
justifyContent: 'center',
},
heading: {
color: '#533263',
fontWeight: 'bold'
},
form: {
width: '90%',
marginTop: 50
},
avoidKeyboard: {
flex: 1,
flexDirection: 'column',
justifyContent: 'center',
height:'100%'
}
});