Skip to content

Commit

Permalink
Merge pull request #37322 from dukenv0307/fix/37240
Browse files Browse the repository at this point in the history
Fix unable to add the file that is not image
  • Loading branch information
NikkiWines authored Feb 27, 2024
2 parents e35876f + f2c9300 commit 59511b0
Showing 1 changed file with 33 additions and 17 deletions.
50 changes: 33 additions & 17 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import Str from 'expensify-common/lib/str';
import lodashCompact from 'lodash/compact';
import PropTypes from 'prop-types';
import React, {useCallback, useMemo, useRef, useState} from 'react';
Expand Down Expand Up @@ -230,6 +231,28 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
setIsVisible(false);
};

/**
* @param {Object} fileData
* @returns {Promise}
*/
const validateAndCompleteAttachmentSelection = useCallback(
(fileData) => {
if (fileData.width === -1 || fileData.height === -1) {
showImageCorruptionAlert();
return Promise.resolve();
}
return getDataForUpload(fileData)
.then((result) => {
completeAttachmentSelection.current(result);
})
.catch((error) => {
showGeneralAlert(error.message);
throw error;
});
},
[showGeneralAlert, showImageCorruptionAlert],
);

/**
* Handles the image/document picker result and
* sends the selected attachment to the caller (parent component)
Expand All @@ -244,24 +267,17 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
return Promise.resolve();
}
const fileData = _.first(attachments);
RNImage.getSize(fileData.uri, (width, height) => {
fileData.width = width;
fileData.height = height;
if (fileData.width === -1 || fileData.height === -1) {
showImageCorruptionAlert();
return Promise.resolve();
}
return getDataForUpload(fileData)
.then((result) => {
completeAttachmentSelection.current(result);
})
.catch((error) => {
showGeneralAlert(error.message);
throw error;
});
});
if (Str.isImage(fileData.fileName || fileData.name)) {
RNImage.getSize(fileData.fileCopyUri || fileData.uri, (width, height) => {
fileData.width = width;
fileData.height = height;
return validateAndCompleteAttachmentSelection(fileData);
});
} else {
return validateAndCompleteAttachmentSelection(fileData);
}
},
[showGeneralAlert, showImageCorruptionAlert],
[validateAndCompleteAttachmentSelection],
);

/**
Expand Down

0 comments on commit 59511b0

Please sign in to comment.