You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

48 lines
1.1 KiB

import React from "react";
import { useFormikContext } from "formik";
import ErrorMessage from "./ErrorMessage";
import ImageInputList from "../ImageInputList";
import { View, Text, StyleSheet } from "react-native";
import colors from "../../config/colors";
import { dimensions } from "../../config/dimensions";
function FormImagePicker({ name }) {
const { errors, setFieldValue, touched, values } = useFormikContext();
const imageUris = values[name];
const handleAdd = (uri) => {
setFieldValue(name, [...imageUris, uri]);
};
const handleRemove = (uri) => {
setFieldValue(
name,
imageUris.filter((imageUri) => imageUri !== uri)
);
};
return (
<View>
<ImageInputList
imageUris={imageUris}
onAddImage={handleAdd}
onRemoveImage={handleRemove}
/>
<ErrorMessage error={errors[name]} visible={touched[name]} />
</View>
);
}
const styles = StyleSheet.create({
labelStyle: {
fontSize: dimensions.text.secondary,
fontWeight: "bold",
textAlign: "left",
color: colors.primary,
marginBottom: 5,
marginTop: 15,
},
});
export default FormImagePicker;