Skip to content

Commit

Permalink
fix: add height and width to attachment
Browse files Browse the repository at this point in the history
  • Loading branch information
dukenv0307 committed Feb 23, 2024
1 parent 06b8688 commit f409821
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/components/AttachmentPicker/index.native.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import lodashCompact from 'lodash/compact';
import PropTypes from 'prop-types';
import React, {useCallback, useMemo, useRef, useState} from 'react';
import {Alert, View} from 'react-native';
import {Alert, Image as RNImage, View} from 'react-native';
import RNFetchBlob from 'react-native-blob-util';
import RNDocumentPicker from 'react-native-document-picker';
import {launchImageLibrary} from 'react-native-image-picker';
Expand Down Expand Up @@ -243,22 +243,23 @@ function AttachmentPicker({type, children, shouldHideCameraOption}) {
onCanceled.current();
return Promise.resolve();
}

const fileData = _.first(attachments);

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;
});
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;
});
});
},
[showGeneralAlert, showImageCorruptionAlert],
);
Expand Down

0 comments on commit f409821

Please sign in to comment.