-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.js
More file actions
96 lines (91 loc) · 2.18 KB
/
App.js
File metadata and controls
96 lines (91 loc) · 2.18 KB
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
/**
* Sample React Native App
* https://github.com/facebook/react-native
*
* @format
* @flow
*/
import React from 'react';
import {
SafeAreaView,
StyleSheet,
Text,
TextInput,
View,
Button,
} from 'react-native';
import {withFormik} from 'formik';
export const App = ({values, setFieldValue, errors, handleSubmit, status}) => {
return (
<SafeAreaView style={styles.container}>
{status !== 'Success' ? (
<>
<Text style={styles.header}>Sample formik app</Text>
<TextInput
style={styles.usernameField}
onChangeText={text => setFieldValue('email', text)}
value={values.email}
placeholder={'Username'}
testID={'Username'}
/>
<TextInput
style={styles.usernameField}
onChangeText={text => setFieldValue('password', text)}
value={values.password}
secureTextEntry={true}
placeholder={'Password'}
testID={'Password'}
/>
{Object.keys(errors).length > 0 && (
<View testID={'ErrorContainer'} style={styles.errorBackground}>
<Text>{errors.email}</Text>
</View>
)}
<Button
testID={'Submit'}
style={styles.submit}
onPress={handleSubmit}
title={'Submit'}
/>
</>
) : (
<Text testID={'Sucesss'}>Success</Text>
)}
</SafeAreaView>
);
};
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: 'grey',
},
header: {
fontSize: 32,
},
usernameField: {
fontSize: 24,
height: 56,
backgroundColor: 'white',
marginTop: 12,
},
errorBackground: {
marginTop: 12,
backgroundColor: 'red',
height: 56,
},
submit: {
marginTop: 12,
},
});
const form = withFormik({
displayName: 'DemoApp',
mapPropsToValues: () => ({email: '', password: ''}),
handleSubmit: (values, {setErrors, setStatus}) => {
if (values.email === '' || values.password === '') {
setErrors({email: 'Username and password are required'});
} else {
setStatus('Success');
}
},
});
export default form(App);