import { useState, forwardRef } from 'react'; import { Image as RNImage, View } from 'react-native'; import { imageStyles } from './Image.styles'; import type { ImageProps } from './types'; import ActivityIndicator from '../ActivityIndicator'; import type { IdealystElement } from '../utils/refTypes'; const Image = forwardRef(({ source, alt, width, height, aspectRatio, objectFit = 'cover', placeholder, fallback, onLoad, onError, borderRadius, style, testID, accessibilityLabel, id, }, ref) => { const [isLoading, setIsLoading] = useState(true); const [hasError, setHasError] = useState(false); const handleLoad = () => { setIsLoading(false); onLoad?.(); }; const handleError = (e: any) => { setIsLoading(false); setHasError(true); onError?.(e); }; // Map objectFit to React Native resizeMode const resizeMode = objectFit === 'contain' ? 'contain' : objectFit === 'cover' ? 'cover' : objectFit === 'fill' ? 'stretch' : objectFit === 'scale-down' ? 'contain' : 'cover'; const imageSource = typeof source === 'string' ? { uri: source } : source; const containerStyle = [ imageStyles.container, { width: width || '100%', height: height || undefined, aspectRatio: aspectRatio || undefined, borderRadius: borderRadius || undefined, }, style, ]; return ( {isLoading && !hasError && ( {placeholder || } )} {hasError && ( {fallback} )} ); }); Image.displayName = 'Image'; export default Image;