|
@ -1,50 +1,57 @@ |
|
|
import React, {useState} from "react"; |
|
|
|
|
|
|
|
|
import React, { useState } from "react"; |
|
|
import ErrorMessage from "./ErrorMessage"; |
|
|
import ErrorMessage from "./ErrorMessage"; |
|
|
import { useFormikContext } from "formik"; |
|
|
import { useFormikContext } from "formik"; |
|
|
import { View, TextInput, StyleSheet } from "react-native"; |
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
View, |
|
|
|
|
|
TextInput, |
|
|
|
|
|
StyleSheet, |
|
|
|
|
|
TouchableNativeFeedback, |
|
|
|
|
|
} from "react-native"; |
|
|
import { MaterialCommunityIcons } from "@expo/vector-icons"; |
|
|
import { MaterialCommunityIcons } from "@expo/vector-icons"; |
|
|
import colors from "../../config/colors"; |
|
|
import colors from "../../config/colors"; |
|
|
import defaultStyles from "../../config/styles"; |
|
|
import defaultStyles from "../../config/styles"; |
|
|
|
|
|
|
|
|
function PasswordFormField({ name, ...otherProps }) { |
|
|
|
|
|
const { |
|
|
|
|
|
values, |
|
|
|
|
|
setFieldTouched, |
|
|
|
|
|
setFieldValue, |
|
|
|
|
|
handleChange, |
|
|
|
|
|
errors, |
|
|
|
|
|
touched, |
|
|
|
|
|
} = useFormikContext(); |
|
|
|
|
|
|
|
|
function PasswordFormField({ |
|
|
|
|
|
name, |
|
|
|
|
|
flex = 0, |
|
|
|
|
|
paddingLeft = 16, |
|
|
|
|
|
paddingRight = 16, |
|
|
|
|
|
...otherProps |
|
|
|
|
|
}) { |
|
|
|
|
|
const { values, setFieldTouched, errors, touched } = useFormikContext(); |
|
|
const [fieldVal, setFieldVal] = useState(values[name]); |
|
|
const [fieldVal, setFieldVal] = useState(values[name]); |
|
|
|
|
|
|
|
|
|
|
|
const [hidePswd, setHidePswd] = useState(true); |
|
|
|
|
|
|
|
|
return ( |
|
|
return ( |
|
|
<View> |
|
|
|
|
|
<View style={styles.container}> |
|
|
|
|
|
<TextInput |
|
|
|
|
|
flex={1} |
|
|
|
|
|
onBlur={() => setFieldTouched(name)} |
|
|
|
|
|
onChangeText={(val) => { |
|
|
|
|
|
setFieldVal(val); |
|
|
|
|
|
}} |
|
|
|
|
|
value={fieldVal.toString()} |
|
|
|
|
|
style={defaultStyles.text} |
|
|
|
|
|
height={48} |
|
|
|
|
|
placeholderTextColor={colors.medium} |
|
|
|
|
|
{...otherProps} |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
<View flex={flex} paddingLeft={paddingLeft} paddingRight={paddingRight}> |
|
|
|
|
|
<View style={styles.container}> |
|
|
|
|
|
<TextInput |
|
|
|
|
|
flex={1} |
|
|
|
|
|
onBlur={() => setFieldTouched(name)} |
|
|
|
|
|
onChangeText={(val) => { |
|
|
|
|
|
setFieldVal(val); |
|
|
|
|
|
}} |
|
|
|
|
|
value={fieldVal.toString()} |
|
|
|
|
|
style={defaultStyles.text} |
|
|
|
|
|
height={48} |
|
|
|
|
|
secureTextEntry={hidePswd} |
|
|
|
|
|
placeholderTextColor={colors.medium} |
|
|
|
|
|
{...otherProps} |
|
|
|
|
|
/> |
|
|
|
|
|
|
|
|
<MaterialCommunityIcons |
|
|
|
|
|
name={"eye"} |
|
|
|
|
|
size={20} |
|
|
|
|
|
color={defaultStyles.colors.medium} |
|
|
|
|
|
style={styles.icon} |
|
|
|
|
|
/> |
|
|
|
|
|
</View> |
|
|
|
|
|
<View style={{ paddingHorizontal: 16 }}> |
|
|
|
|
|
<ErrorMessage error={errors[name]} visible={touched[name]} /> |
|
|
|
|
|
</View> |
|
|
|
|
|
|
|
|
<TouchableNativeFeedback onPress={() => setHidePswd(!hidePswd)}> |
|
|
|
|
|
<MaterialCommunityIcons |
|
|
|
|
|
name={hidePswd ? "eye-off" : "eye"} |
|
|
|
|
|
size={25} |
|
|
|
|
|
color={defaultStyles.colors.medium} |
|
|
|
|
|
style={styles.icon} |
|
|
|
|
|
/> |
|
|
|
|
|
</TouchableNativeFeedback> |
|
|
</View> |
|
|
</View> |
|
|
|
|
|
{/* <View style={{ paddingHorizontal: 2 }}> */} |
|
|
|
|
|
<ErrorMessage error={errors[name]} visible={touched[name]} /> |
|
|
|
|
|
{/* </View> */} |
|
|
|
|
|
</View> |
|
|
); |
|
|
); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -59,11 +66,10 @@ const styles = StyleSheet.create({ |
|
|
borderWidth: 1, |
|
|
borderWidth: 1, |
|
|
padding: 5, |
|
|
padding: 5, |
|
|
paddingLeft: 10, |
|
|
paddingLeft: 10, |
|
|
marginHorizontal: 16 |
|
|
|
|
|
}, |
|
|
}, |
|
|
icon: { |
|
|
icon: { |
|
|
marginRight: 10, |
|
|
marginRight: 10, |
|
|
alignItems: "flex-end" |
|
|
|
|
|
|
|
|
alignItems: "flex-end", |
|
|
}, |
|
|
}, |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|