import React, { FC } from 'react'; import { View, TouchableOpacity, StyleSheet } from 'react-native'; import type { StyleProp, ViewStyle } from 'react-native'; import { IconXClosesmall1 } from '../../icons'; import createStyle from './style'; import { FileInfo, ImageInfo } from './interface'; import { useTheme } from '../Theme/Theme'; import { filePathOSDisplay } from './help'; import Image from '../Image'; import Loading from '../Loading'; import { renderIcon } from './TextList'; import { JPEG, PNG, SVG, WEBP } from './enum'; const imagesTypes = [...JPEG, ...PNG, ...SVG, ...WEBP]; interface ImagePreviewProps { file: ImageInfo; disabled: boolean; deleteIcon?: React.ReactNode; showDeleteIcon?: boolean; onPreviewImage: () => void; onPreviewFile?: (uri: string, file: FileInfo) => void; onRemove: () => void; onReUpload?: () => void; style?: StyleProp; contentStyle?: StyleProp; } const ImagePreview: FC = ({ file, disabled, deleteIcon, showDeleteIcon: outShowDeleteIcon = true, onPreviewImage, onPreviewFile, onRemove, style, contentStyle, }) => { const { uri } = file; const token = useTheme(); const styles = createStyle(token); const renderDeleteIcon = () => { return deleteIcon ? ( deleteIcon ) : ( ); }; const renderLoading = () => ( ); const renderContent = () => { const fileType = uri?.split('.')?.pop()?.toLowerCase(); if (fileType && imagesTypes.includes(fileType)) { return ( {file.status === 'isUploading' ? ( renderLoading() ) : ( )} ); } return ( onPreviewFile?.(uri, file)}> {file.status === 'isUploading' ? renderLoading() : renderIcon(uri, 64)} ); }; const showDeleteIcon = !disabled && file.status !== 'isUploading' && outShowDeleteIcon; return ( {showDeleteIcon ? ( {renderDeleteIcon()} ) : null} {renderContent()} ); }; export default ImagePreview;