11import { Str } from 'expensify-common' ;
2- import { ImageManipulator , SaveFormat } from 'expo-image-manipulator' ;
2+ import { manipulateAsync , SaveFormat } from 'expo-image-manipulator' ;
33import React , { useCallback , useMemo , useRef , useState } from 'react' ;
44import { Alert , View } from 'react-native' ;
55import RNFetchBlob from 'react-native-blob-util' ;
@@ -19,7 +19,7 @@ import useResponsiveLayout from '@hooks/useResponsiveLayout';
1919import useStyleUtils from '@hooks/useStyleUtils' ;
2020import useTheme from '@hooks/useTheme' ;
2121import useThemeStyles from '@hooks/useThemeStyles' ;
22- import { cleanFileName , showCameraPermissionsAlert , verifyFileFormat } from '@libs/fileDownload/FileUtils' ;
22+ import * as FileUtils from '@libs/fileDownload/FileUtils' ;
2323import CONST from '@src/CONST' ;
2424import type { TranslationPaths } from '@src/languages/types' ;
2525import type IconAsset from '@src/types/utils/IconAsset' ;
@@ -85,7 +85,7 @@ const getDocumentPickerOptions = (type: string, fileLimit: number): DocumentPick
8585const getDataForUpload = ( fileData : FileResponse ) : Promise < FileObject > => {
8686 const fileName = fileData . name || 'chat_attachment' ;
8787 const fileResult : FileObject = {
88- name : cleanFileName ( fileName ) ,
88+ name : FileUtils . cleanFileName ( fileName ) ,
8989 type : fileData . type ,
9090 width : fileData . width ,
9191 height : fileData . height ,
@@ -122,6 +122,7 @@ function AttachmentPicker({
122122 const [ isVisible , setIsVisible ] = useState ( false ) ;
123123 const StyleUtils = useStyleUtils ( ) ;
124124 const theme = useTheme ( ) ;
125+
125126 const completeAttachmentSelection = useRef < ( data : FileObject [ ] ) => void > ( ( ) => { } ) ;
126127 const onModalHide = useRef < ( ) => void > ( ) ;
127128 const onCanceled = useRef < ( ) => void > ( ( ) => { } ) ;
@@ -157,7 +158,7 @@ function AttachmentPicker({
157158 if ( response . errorCode ) {
158159 switch ( response . errorCode ) {
159160 case 'permission' :
160- showCameraPermissionsAlert ( ) ;
161+ FileUtils . showCameraPermissionsAlert ( ) ;
161162 return resolve ( ) ;
162163 default :
163164 showGeneralAlert ( ) ;
@@ -175,41 +176,30 @@ function AttachmentPicker({
175176 }
176177
177178 if ( targetAsset ?. type ?. startsWith ( 'image' ) ) {
178- verifyFileFormat ( { fileUri : targetAssetUri , formatSignatures : CONST . HEIC_SIGNATURES } )
179+ FileUtils . verifyFileFormat ( { fileUri : targetAssetUri , formatSignatures : CONST . HEIC_SIGNATURES } )
179180 . then ( ( isHEIC ) => {
180181 // react-native-image-picker incorrectly changes file extension without transcoding the HEIC file, so we are doing it manually if we detect HEIC signature
181182 if ( isHEIC && targetAssetUri ) {
182- const manipulateContext = ImageManipulator . manipulate ( targetAssetUri ) ;
183-
184- manipulateContext . renderAsync ( ) . then ( ( image ) =>
185- image
186- . saveAsync ( { format : SaveFormat . JPEG } )
187- . then ( ( result ) => {
188- manipulateContext . release ( ) ;
189- image . release ( ) ;
190- return result ;
191- } )
192- . then ( ( manipResult ) => {
193- const uri = manipResult . uri ;
194- const convertedAsset = {
195- uri,
196- name : uri
197- . substring ( uri . lastIndexOf ( '/' ) + 1 )
198- . split ( '?' )
199- . at ( 0 ) ,
200- type : 'image/jpeg' ,
201- width : manipResult . width ,
202- height : manipResult . height ,
203- } ;
204- return resolve ( [ convertedAsset ] ) ;
205- } )
206- . catch ( ( ) => {
207- manipulateContext ?. release ( ) ;
208- resolve ( response . assets ?? [ ] ) ;
209- } ) ,
210- ) ;
183+ manipulateAsync ( targetAssetUri , [ ] , { format : SaveFormat . JPEG } )
184+ . then ( ( manipResult ) => {
185+ const uri = manipResult . uri ;
186+ const convertedAsset = {
187+ uri,
188+ name : uri
189+ . substring ( uri . lastIndexOf ( '/' ) + 1 )
190+ . split ( '?' )
191+ . at ( 0 ) ,
192+ type : 'image/jpeg' ,
193+ width : manipResult . width ,
194+ height : manipResult . height ,
195+ } ;
196+
197+ return resolve ( [ convertedAsset ] ) ;
198+ } )
199+ . catch ( ( err ) => reject ( err ) ) ;
200+ } else {
201+ return resolve ( response . assets ) ;
211202 }
212- return resolve ( response . assets ) ;
213203 } )
214204 . catch ( ( err ) => reject ( err ) ) ;
215205 } else {
0 commit comments