diff --git a/src/components/Image/BaseImage.native.tsx b/src/components/Image/BaseImage.native.tsx index a02c348344b9..6475eb5ca33a 100644 --- a/src/components/Image/BaseImage.native.tsx +++ b/src/components/Image/BaseImage.native.tsx @@ -8,9 +8,12 @@ import type {BaseImageProps} from './types'; function BaseImage({onLoad, source, ...props}: BaseImageProps) { const isLoadedRef = useRef(false); const attachmentContext = useContext(AttachmentStateContext); - const {setAttachmentLoaded} = attachmentContext || {}; + const {setAttachmentLoaded, isAttachmentLoaded} = attachmentContext || {}; useEffect(() => { + if (isAttachmentLoaded?.(source as AttachmentSource)) { + return; + } setAttachmentLoaded(source as AttachmentSource, false); // eslint-disable-next-line react-compiler/react-compiler // eslint-disable-next-line react-hooks/exhaustive-deps diff --git a/src/components/Image/BaseImage.tsx b/src/components/Image/BaseImage.tsx index e9a94fe0757e..8fcf192b9064 100644 --- a/src/components/Image/BaseImage.tsx +++ b/src/components/Image/BaseImage.tsx @@ -1,19 +1,23 @@ import React, {useCallback, useContext, useEffect} from 'react'; import {Image as RNImage} from 'react-native'; -import type {ImageLoadEventData, ImageSourcePropType} from 'react-native'; +import type {ImageLoadEvent, ImageSourcePropType} from 'react-native'; import type {AttachmentSource} from '@components/Attachments/types'; import {AttachmentStateContext} from '@pages/media/AttachmentModalScreen/AttachmentModalBaseContent/AttachmentStateContextProvider'; import type {BaseImageProps} from './types'; function BaseImage({onLoad, source, ...props}: BaseImageProps) { - const {setAttachmentLoaded} = useContext(AttachmentStateContext); + const {setAttachmentLoaded, isAttachmentLoaded} = useContext(AttachmentStateContext); useEffect(() => { + if (isAttachmentLoaded?.(source as AttachmentSource)) { + return; + } + setAttachmentLoaded?.(source as AttachmentSource, false); // eslint-disable-next-line react-compiler/react-compiler // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const imageLoadedSuccessfully = useCallback( - (event: {nativeEvent: ImageLoadEventData}) => { + (event: ImageLoadEvent) => { setAttachmentLoaded?.(source as AttachmentSource, true); if (!onLoad) { return;