import { useAccessibility } from '@utils/accessibility/AccessibilityManager' import { connectMedia } from '@utils/api/helpers/connect' import { useTheme } from '@utils/styles/ThemeManager' import { Image, ImageSource, ImageStyle } from 'expo-image' import React, { useState } from 'react' import { AccessibilityProps, Pressable, StyleProp, View, ViewStyle } from 'react-native' export interface Props { accessibilityLabel?: AccessibilityProps['accessibilityLabel'] accessibilityHint?: AccessibilityProps['accessibilityHint'] hidden?: boolean sources: { preview?: ImageSource default?: ImageSource remote?: ImageSource static?: ImageSource blurhash?: string } dimension?: { width: number; height: number } onPress?: () => void style?: StyleProp imageStyle?: ImageStyle // For image viewer when there is no image size available setImageDimensions?: React.Dispatch< React.SetStateAction<{ width: number height: number }> > dim?: boolean enableLiveTextInteraction?: boolean } const GracefullyImage = ({ accessibilityLabel, accessibilityHint, hidden = false, sources, dimension, onPress, style, imageStyle, setImageDimensions, dim, enableLiveTextInteraction = false }: Props) => { const { reduceMotionEnabled } = useAccessibility() const { theme } = useTheme() const [currentSource, setCurrentSource] = useState( sources.default || sources.remote ) const source: ImageSource | undefined = reduceMotionEnabled && sources.static ? sources.static : currentSource return ( { if (setImageDimensions && event.source) { setImageDimensions(event.source) } }} onError={() => { if ( sources.default?.uri && sources.default?.uri === currentSource?.uri && sources.remote ) { setCurrentSource(sources.remote) } }} enableLiveTextInteraction={enableLiveTextInteraction} /> {dim && theme !== 'light' ? ( ) : null} ) } export default GracefullyImage