import React from 'react'; import { useState } from 'react'; import { Image as RNImage, ImageProps, Text, TouchableOpacity, View, TouchableOpacityProps, ActivityIndicatorProps } from 'react-native'; import useTheme from '../hooks/useTheme'; import Skeleton from './Skeleton' export type Props = ImageProps & { src: string | null | undefined; isBorder?: boolean; showImageError?: boolean; blurUrl?: string | null | undefined; source?: undefined; isTouchableOpacity?: boolean; touchableOpacityProps?: TouchableOpacityProps activityIndicatorProps?: ActivityIndicatorProps isActivityIndicator?: boolean; onPress?: () => void onLongPress?: () => void }; const Image = ({ style, src, isTouchableOpacity = false, touchableOpacityProps, activityIndicatorProps, isActivityIndicator = true, isBorder = true, showImageError = false, onPress, onLongPress, blurUrl, ...otherProps }: Props) => { const { currentTheme } = useTheme(); const [state, setState] = useState<"idle" | "pending" | "normal" | "error">("idle"); if (state === "error" && showImageError || !src) { return ( {/* */} Failed to load image ) } const ImageComponent = () => { return ( { if (state === "error") return; setState("error") }} onLoadEnd={() => { if (state === "normal") return; setState("normal") }} {...otherProps} />) } return ( ) } export default Image;