Skip to content

Commit

Permalink
Fix: Add fallback name for attachments lacking the original filename
Browse files Browse the repository at this point in the history
  • Loading branch information
kidroca committed Nov 1, 2023
1 parent 2db8172 commit c1536f9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/components/ImageView/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import FullscreenLoadingIndicator from '@components/FullscreenLoadingIndicator';
import Image from '@components/Image';
import PressableWithoutFeedback from '@components/Pressable/PressableWithoutFeedback';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import * as FileUtils from '@libs/fileDownload/FileUtils';
import styles from '@styles/styles';
import * as StyleUtils from '@styles/StyleUtils';
import CONST from '@src/CONST';
Expand All @@ -21,14 +22,15 @@ const propTypes = {
url: PropTypes.string.isRequired,

/** image file name */
fileName: PropTypes.string.isRequired,
fileName: PropTypes.string,

onError: PropTypes.func,
};

const defaultProps = {
isAuthTokenRequired: false,
onError: () => {},
fileName: '',
};

function ImageView({isAuthTokenRequired, url, fileName, onError}) {
Expand All @@ -49,6 +51,7 @@ function ImageView({isAuthTokenRequired, url, fileName, onError}) {

const scrollableRef = useRef(null);
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();
const accessibilityLabel = fileName || FileUtils.getAttachmentName(url);

/**
* @param {Number} newContainerWidth
Expand Down Expand Up @@ -263,7 +266,7 @@ function ImageView({isAuthTokenRequired, url, fileName, onError}) {
onPressIn={onContainerPressIn}
onPress={onContainerPress}
accessibilityRole={CONST.ACCESSIBILITY_ROLE.IMAGE}
accessibilityLabel={fileName}
accessibilityLabel={accessibilityLabel}
>
<Image
source={{uri: url}}
Expand Down

0 comments on commit c1536f9

Please sign in to comment.