Skip to content

Instantly share code, notes, and snippets.

@burhanyilmaz
Created October 3, 2019 05:15
Show Gist options
  • Save burhanyilmaz/86c908e8efe0151d3aa9b532f178bee6 to your computer and use it in GitHub Desktop.
Save burhanyilmaz/86c908e8efe0151d3aa9b532f178bee6 to your computer and use it in GitHub Desktop.
const CustomTextInput = ({ placeholder, input, meta, label }) => (
<View style={styles.container}>
{label && <Text style={styles.labelTitle}>{label}</Text>}
<TextInput style={styles.textInput} {...input} placeholder={placeholder} />
{meta.error && meta.touched && (
<Text style={styles.errorTitle}>{meta.error}</Text>
)}
</View>
);
const Button = ({ handleSubmit }) => (
<TouchableOpacity
style={[styles.button, styles.container]}
onPress={handleSubmit}>
<Text style={styles.buttonTitle}>Giriş</Text>
</TouchableOpacity>
);
const CustomField = ({ name, placeholder, label, validate }) => {
return (
<Field
{...{ name, validate }}
render={({ input, meta }) => (
<>
<CustomTextInput {...{ input, meta, label, placeholder }} />
</>
)}
/>
);
};
<Form
initialValues={initialValues}
onSubmit={values => alert(JSON.stringify(values))}
render={({ handleSubmit }) => {
return (
<>
<CustomField
name="email"
validate={required}
placeholder="Eposta Giriniz"
label="Eposta"
/>
<CustomField
name="password"
validate={required}
placeholder="Şifre Giriniz"
label="Şifre"
/>
<CustomField
name="securityQuestion"
validate={(required, checkQuestionValue)}
placeholder="İşlemi yapınız"
label="2 + 1"
/>
<Button {...{ handleSubmit }} />
</>
);
}}
/>
const styles = {
safeArea: {
flex: 1,
justifyContent: 'center',
},
container: {
margin: 12,
},
textInput: {
borderBottomColor: '#787878',
backgroundColor: '#f4f4f4',
padding: 16,
borderRadius: 8,
color: 'gray',
fontFamily: 'Avenir-Medium',
},
button: {
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#6610f2',
padding: 12,
borderRadius: 8,
},
buttonTitle: {
fontSize: 18,
color: 'white',
fontFamily: 'Avenir-Medium',
},
errorTitle: {
fontSize: 13,
color: 'red',
fontFamily: 'Avenir-Medium',
marginTop: 8,
},
labelTitle: {
marginBottom: 8,
fontSize: 16,
fontFamily: 'Avenir-Medium',
},
};
const required = value => !value && 'Lütfen boş bırakmayınız';
const checkQuestionValue = value =>
isNaN(value)
? 'Girilen değer numara olmalı'
: value == 3
? undefined
: 'Sonuç hatalı';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment