import React, { useState, useEffect } from "react"; import { useFormikContext } from "formik"; import TextInput from "../TextInput"; import ErrorMessage from "./ErrorMessage"; import { View, Text } from "react-native"; import { TouchableOpacity } from "react-native-gesture-handler"; import colors from "../../config/colors"; import defaultStyles from "../../config/styles"; function IncreaseDecreaseButtons({ content }) { return ( {content} ); } function RenderPluviometerInput({ name, setFieldTouched, setFieldValue, otherProps, width, values, }) { const [fieldVal, setFieldVal] = useState(values[name]); useEffect(() => { setFieldValue(name, fieldVal, true); }, [fieldVal]); const increase = () => { Number(fieldVal) + 1 <= 999 && setFieldVal((Number(fieldVal) + 1).toString()); }; const decrease = () => { Number(fieldVal) - 1 >= 0 && setFieldVal((Number(fieldVal) - 1).toString()); }; return ( setFieldTouched(name)} onChangeText={(val) => { setFieldVal(val); }} value={fieldVal.toString()} {...otherProps} /> { decrease(); }} style={{ paddingLeft: 4, paddingRight: 1.5, }} > { increase(); }} style={{ paddingLeft: 1.5, paddingRight: 16, }} > ); } function AppFormField({ name, width, increaseDecreaseButtons = false, flex = 0, paddingLeft = 16, paddingRight = 16, numberOfLines = 1, ...otherProps }) { const { values, setFieldTouched, setFieldValue, handleChange, errors, touched, } = useFormikContext(); return ( {name != "pluviometer" ? ( setFieldTouched(name)} onChangeText={handleChange(name)} width={width} {...otherProps} /> ) : ( )} ); } export default AppFormField;