From f409821ff04b65144669376d354d266e979ee9a4 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Fri, 23 Feb 2024 15:08:31 +0700 Subject: [PATCH] fix: add height and width to attachment --- .../AttachmentPicker/index.native.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/components/AttachmentPicker/index.native.js b/src/components/AttachmentPicker/index.native.js index a0fe760abcc1..d4d3d0696c59 100644 --- a/src/components/AttachmentPicker/index.native.js +++ b/src/components/AttachmentPicker/index.native.js @@ -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'; @@ -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], );