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 { Shadow } from "react-native-shadow-2"; function IncreaseDecreaseButtons({ content }) { return ( {content} ); } function RenderPluviometerInput({ name, setFieldTouched, setFieldValue, otherProps, width, values, }) { console.log(name == "pluviometer"); const [fieldVal, setFieldVal] = useState(values[name]); useEffect(() => { setFieldValue(name, fieldVal, true); }, [fieldVal]); const increase = () => { setFieldVal((Number(fieldVal) + 1).toString()); }; const decrease = () => { setFieldVal((Number(fieldVal) - 1).toString()); }; return ( setFieldTouched(name)} onChangeText={(val) => { setFieldVal(val); }} width={width} value={fieldVal.toString()} {...otherProps}/> { decrease(); }} style={{ paddingLeft: 4, paddingBottom: 8, paddingRight: 1.5, }} > { increase(); }} style={{ paddingLeft: 1.5, paddingBottom: 8, paddingRight: 16, }} > ); } function AppFormField({ name, width, increaseDecreaseButtons = false, flex = 0, paddingLeft = 16, paddingRight = 16, ...otherProps }) { const { values, setFieldTouched, setFieldValue, handleChange, errors, touched, } = useFormikContext(); return ( {name != "pluviometer" ? ( setFieldTouched(name)} onChangeText={handleChange(name)} width={width} {...otherProps} /> ) : ( )} ); } export default AppFormField;