import React from "react"; import { View, TouchableOpacity } from "react-native"; import { Image } from 'expo-image'; import MyText from "./text"; import tw from '../lib/tailwind'; import Ionicons from "@expo/vector-icons/Ionicons"; import { MaterialIcons } from "@expo/vector-icons"; interface ImageUploaderProps { images: { uri?: string }[]; onAddImage: () => void; onRemoveImage: (uri: string) => void; existingImageUrls?: string[]; // URLs of existing images that should be displayed onRemoveExistingImage?: (url: string) => void; // Callback to track which existing images are removed allowMultiple?: boolean; // Whether to allow multiple image uploads } const ImageUploader: React.FC = ({ images, existingImageUrls = [], onAddImage, onRemoveImage, onRemoveExistingImage, allowMultiple = true, }) => { const totalImageCount = images.length + existingImageUrls.length; return ( {/* Render existing images with URLs */} {existingImageUrls.map((url, index) => ( onRemoveExistingImage?.(url)} style={tw`absolute top-0 right-0 bg-red-500 rounded-full p-1`} > ))} {/* Render newly added images */} {images.map((image, index) => ( onRemoveImage(image.uri!)} style={tw`absolute top-0 right-0 bg-red-500 rounded-full p-1`} > ))} = 1} onPress={onAddImage} style={tw`w-1/3 px-1 mb-2`}> {!allowMultiple && totalImageCount >= 1 ? ( Only one image allowed ) : } ); }; export default ImageUploader;