diff --git a/src/components/Attachments/AttachmentView/AttachmentViewImage/index.native.js b/src/components/Attachments/AttachmentView/AttachmentViewImage/index.native.js index faf2f21c133d..eb38e9001140 100755 --- a/src/components/Attachments/AttachmentView/AttachmentViewImage/index.native.js +++ b/src/components/Attachments/AttachmentView/AttachmentViewImage/index.native.js @@ -13,7 +13,7 @@ const propTypes = { ...withLocalizePropTypes, }; -function AttachmentViewImage({source, file, isAuthTokenRequired, isFocused, isUsedInCarousel, loadComplete, onPress, isImage, onScaleChanged, translate}) { +function AttachmentViewImage({source, file, isAuthTokenRequired, isFocused, isUsedInCarousel, loadComplete, onPress, onError, isImage, onScaleChanged, translate}) { const children = isUsedInCarousel ? ( ); diff --git a/src/components/Attachments/AttachmentView/index.js b/src/components/Attachments/AttachmentView/index.js index 98086dcc4a0c..87b9dc57d969 100755 --- a/src/components/Attachments/AttachmentView/index.js +++ b/src/components/Attachments/AttachmentView/index.js @@ -79,9 +79,9 @@ function AttachmentView({ isUsedInAttachmentModal, }) { const [loadComplete, setLoadComplete] = useState(false); - const [imageError, setImageError] = useState(false); + const [isValidImage, setIsValidImage] = useState(true); - useNetwork({onReconnect: () => setImageError(false)}); + useNetwork({onReconnect: () => setIsValidImage(true)}); // Handles case where source is a component (ex: SVG) if (_.isFunction(source)) { @@ -147,11 +147,12 @@ function AttachmentView({ // For this check we use both source and file.name since temporary file source is a blob // both PDFs and images will appear as images when pasted into the text field. // We also check for numeric source since this is how static images (used for preview) are represented in RN. - const isImage = typeof source === 'number' || Str.isImage(source); - if (isImage || (file && Str.isImage(file.name))) { + const isImage = typeof source === 'number' || Str.isImage(source) || (file && Str.isImage(file.name)); + + if (isImage && (isValidImage || fallbackSource)) { return ( { - setImageError(true); + setIsValidImage(false); }} /> ); diff --git a/src/components/ImageView/index.native.js b/src/components/ImageView/index.native.js index dd17e2d27a4e..41c8dbb39f54 100644 --- a/src/components/ImageView/index.native.js +++ b/src/components/ImageView/index.native.js @@ -25,6 +25,9 @@ const propTypes = { /** Function for handle on press */ onPress: PropTypes.func, + /** Bubbles up RNImage's onError callback so we can handle it in AttachmentView */ + onError: PropTypes.func.isRequired, + /** Additional styles to add to the component */ style: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.object), PropTypes.object]), }; @@ -39,7 +42,7 @@ const defaultProps = { // https://github.com/ascoders/react-native-image-zoom/blob/master/src/image-zoom/image-zoom.type.ts#L79 const DOUBLE_CLICK_INTERVAL = 175; -function ImageView({isAuthTokenRequired, url, onScaleChanged, onPress, style}) { +function ImageView({isAuthTokenRequired, url, onScaleChanged, onPress, onError, style}) { const {windowWidth, windowHeight} = useWindowDimensions(); const [isLoading, setIsLoading] = useState(true); @@ -221,6 +224,7 @@ function ImageView({isAuthTokenRequired, url, onScaleChanged, onPress, style}) { resizeMode={Image.resizeMode.contain} onLoadStart={imageLoadingStart} onLoad={configureImageZoom} + onError={onError} /> {/** Create an invisible view on top of the image so we can capture and set the amount of touches before