From d513f644f09bd8858037dac1a044a323f8473161 Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Tue, 27 Feb 2024 19:56:59 +0400 Subject: [PATCH 1/2] Fix displaying error message when image has been downloaded --- ios/Podfile.lock | 6 ++- package-lock.json | 12 +++-- package.json | 2 +- ...native-camera-roll+camera-roll+5.4.0.patch | 15 ------ ...native-camera-roll+camera-roll+7.4.0.patch | 54 +++++++++++++++++++ src/libs/fileDownload/index.ios.ts | 16 +++--- 6 files changed, 73 insertions(+), 32 deletions(-) delete mode 100644 patches/@react-native-camera-roll+camera-roll+5.4.0.patch create mode 100644 patches/@react-native-camera-roll+camera-roll+7.4.0.patch diff --git a/ios/Podfile.lock b/ios/Podfile.lock index dc8eb94eeb3f..52c817c739b3 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -1163,7 +1163,9 @@ PODS: - React-Core - react-native-blob-util (0.19.4): - React-Core - - react-native-cameraroll (5.4.0): + - react-native-cameraroll (7.4.0): + - glog + - RCT-Folly (= 2022.05.16.00) - React-Core - react-native-config (1.4.6): - react-native-config/App (= 1.4.6) @@ -1929,7 +1931,7 @@ SPEC CHECKSUMS: React-Mapbuffer: 9ee041e1d7be96da6d76a251f92e72b711c651d6 react-native-airship: 6ded22e4ca54f2f80db80b7b911c2b9b696d9335 react-native-blob-util: 30a6c9fd067aadf9177e61a998f2c7efb670598d - react-native-cameraroll: 8ffb0af7a5e5de225fd667610e2979fc1f0c2151 + react-native-cameraroll: 3301d62d45616ee9da55ceed04be8d788c3de3ef react-native-config: 7cd105e71d903104e8919261480858940a6b9c0e react-native-document-picker: 3599b238843369026201d2ef466df53f77ae0452 react-native-geolocation: 0f7fe8a4c2de477e278b0365cce27d089a8c5903 diff --git a/package-lock.json b/package-lock.json index 5fe54d0f27a7..5efcce4f1d80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -26,7 +26,7 @@ "@oguzhnatly/react-native-image-manipulator": "github:Expensify/react-native-image-manipulator#5cdae3d4455b03a04c57f50be3863e2fe6c92c52", "@onfido/react-native-sdk": "10.6.0", "@react-native-async-storage/async-storage": "1.21.0", - "@react-native-camera-roll/camera-roll": "5.4.0", + "@react-native-camera-roll/camera-roll": "7.4.0", "@react-native-clipboard/clipboard": "^1.13.2", "@react-native-community/geolocation": "^3.0.6", "@react-native-community/netinfo": "11.2.1", @@ -8737,10 +8737,12 @@ } }, "node_modules/@react-native-camera-roll/camera-roll": { - "version": "5.4.0", - "resolved": "https://registry.npmjs.org/@react-native-camera-roll/camera-roll/-/camera-roll-5.4.0.tgz", - "integrity": "sha512-SMEhc+2hQWubwzxR6Zac0CmrJ2rdoHHBo0ibG2iNMsxR0dnU5AdRGnYF/tyK9i20/i7ZNxn+qsEJ69shpkd6gg==", - "license": "MIT", + "version": "7.4.0", + "resolved": "https://registry.npmjs.org/@react-native-camera-roll/camera-roll/-/camera-roll-7.4.0.tgz", + "integrity": "sha512-y0bVpMJLaFphYvMMx1BsqgMA0kXq9CKxKYNnt4ocUvwJj5Rp4TZ233rzJoDqz1oxd56Tz5f1g+yhYN5RImKl8Q==", + "engines": { + "node": ">= 18.17.0" + }, "peerDependencies": { "react-native": ">=0.59" } diff --git a/package.json b/package.json index 66ebe720a448..a5f340f10408 100644 --- a/package.json +++ b/package.json @@ -74,7 +74,7 @@ "@oguzhnatly/react-native-image-manipulator": "github:Expensify/react-native-image-manipulator#5cdae3d4455b03a04c57f50be3863e2fe6c92c52", "@onfido/react-native-sdk": "10.6.0", "@react-native-async-storage/async-storage": "1.21.0", - "@react-native-camera-roll/camera-roll": "5.4.0", + "@react-native-camera-roll/camera-roll": "7.4.0", "@react-native-clipboard/clipboard": "^1.13.2", "@react-native-community/geolocation": "^3.0.6", "@react-native-community/netinfo": "11.2.1", diff --git a/patches/@react-native-camera-roll+camera-roll+5.4.0.patch b/patches/@react-native-camera-roll+camera-roll+5.4.0.patch deleted file mode 100644 index f0429bc10125..000000000000 --- a/patches/@react-native-camera-roll+camera-roll+5.4.0.patch +++ /dev/null @@ -1,15 +0,0 @@ -diff --git a/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle b/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle -index 3f76132..63dc946 100644 ---- a/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle -+++ b/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle -@@ -81,7 +81,9 @@ def findNodeModulePath(baseDir, packageName) { - } - - def resolveReactNativeDirectory() { -- def reactNative = file("${findNodeModulePath(rootProject.projectDir, "react-native")}") -+ def projectDir = this.hasProperty('reactNativeProject') ? this.reactNativeProject : rootProject.projectDir -+ def modulePath = file(projectDir); -+ def reactNative = file("${findNodeModulePath(modulePath, 'react-native')}") - if (reactNative.exists()) { - return reactNative - } diff --git a/patches/@react-native-camera-roll+camera-roll+7.4.0.patch b/patches/@react-native-camera-roll+camera-roll+7.4.0.patch new file mode 100644 index 000000000000..9fdaf8e4e00b --- /dev/null +++ b/patches/@react-native-camera-roll+camera-roll+7.4.0.patch @@ -0,0 +1,54 @@ +diff --git a/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle b/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle +index 6891fa3..3759bed 100644 +--- a/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle ++++ b/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle +@@ -81,7 +81,9 @@ def findNodeModulePath(baseDir, packageName) { + } + + def resolveReactNativeDirectory() { +- def reactNative = file("${findNodeModulePath(rootProject.projectDir, "react-native")}") ++ def projectDir = this.hasProperty('reactNativeProject') ? this.reactNativeProject : rootProject.projectDir ++ def modulePath = file(projectDir); ++ def reactNative = file("${findNodeModulePath(modulePath, 'react-native')}") + if (reactNative.exists()) { + return reactNative + } +diff --git a/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml b/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml +index dbda53f..98fb413 100644 +--- a/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml ++++ b/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml +@@ -1,6 +1,6 @@ + + ++ > + + + +\ No newline at end of file +diff --git a/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm +index 4769d28..75b74b9 100644 +--- a/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm ++++ b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm +@@ -207,6 +207,21 @@ static void requestPhotoLibraryAccess(RCTPromiseRejectBlock reject, PhotosAuthor + options.fetchLimit = 1; + PHFetchResult *createdAsset = [PHAsset fetchAssetsWithLocalIdentifiers:@[placeholder.localIdentifier] + options:options]; ++ ++ if (![createdAsset isKindOfClass:[PHAsset class]]) { ++ resolve(@{ ++ @"node": [NSNull null] ++ }); ++ return; ++ } ++ ++ if (![createdAsset isKindOfClass:[PHAsset class]]) { ++ resolve(@{ ++ @"node": [NSNull null] ++ }); ++ return; ++ } ++ + if (createdAsset.count < 1) { + reject(kErrorUnableToSave, nil, nil); + return; diff --git a/src/libs/fileDownload/index.ios.ts b/src/libs/fileDownload/index.ios.ts index 4990c389fd9f..7960f6c9e4ba 100644 --- a/src/libs/fileDownload/index.ios.ts +++ b/src/libs/fileDownload/index.ios.ts @@ -1,4 +1,5 @@ import {CameraRoll} from '@react-native-camera-roll/camera-roll'; +import type {PhotoIdentifier} from '@react-native-camera-roll/camera-roll'; import RNFetchBlob from 'react-native-blob-util'; import CONST from '@src/CONST'; import * as FileUtils from './FileUtils'; @@ -29,16 +30,16 @@ function downloadFile(fileUrl: string, fileName: string) { * Download the image to photo lib in iOS */ function downloadImage(fileUrl: string) { - return CameraRoll.save(fileUrl); + return CameraRoll.saveAsset(fileUrl); } /** * Download the video to photo lib in iOS */ -function downloadVideo(fileUrl: string, fileName: string): Promise { +function downloadVideo(fileUrl: string, fileName: string): Promise { return new Promise((resolve, reject) => { let documentPathUri: string | null = null; - let cameraRollUri: string | null = null; + let cameraRollAsset: PhotoIdentifier; // Because CameraRoll doesn't allow direct downloads of video with remote URIs, we first download as documents, then copy to photo lib and unlink the original file. downloadFile(fileUrl, fileName) @@ -47,20 +48,17 @@ function downloadVideo(fileUrl: string, fileName: string): Promise { if (!documentPathUri) { throw new Error('Error downloading video'); } - return CameraRoll.save(documentPathUri); + return CameraRoll.saveAsset(documentPathUri); }) .then((attachment) => { - cameraRollUri = attachment; + cameraRollAsset = attachment; if (!documentPathUri) { throw new Error('Error downloading video'); } return RNFetchBlob.fs.unlink(documentPathUri); }) .then(() => { - if (!cameraRollUri) { - throw new Error('Error downloading video'); - } - resolve(cameraRollUri); + resolve(cameraRollAsset); }) .catch((err) => reject(err)); }); From 683aae19fc2367c06e39de16cb5cc674ef7e88af Mon Sep 17 00:00:00 2001 From: Shahe Shahinyan Date: Thu, 29 Feb 2024 14:58:30 +0400 Subject: [PATCH 2/2] Fix patch file --- ...native-camera-roll+camera-roll+7.4.0.patch | 26 +++---------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/patches/@react-native-camera-roll+camera-roll+7.4.0.patch b/patches/@react-native-camera-roll+camera-roll+7.4.0.patch index 9fdaf8e4e00b..59fdaf904c8e 100644 --- a/patches/@react-native-camera-roll+camera-roll+7.4.0.patch +++ b/patches/@react-native-camera-roll+camera-roll+7.4.0.patch @@ -1,5 +1,5 @@ diff --git a/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle b/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle -index 6891fa3..3759bed 100644 +index 6891fa3..8397f95 100644 --- a/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle +++ b/node_modules/@react-native-camera-roll/camera-roll/android/build.gradle @@ -81,7 +81,9 @@ def findNodeModulePath(baseDir, packageName) { @@ -13,24 +13,11 @@ index 6891fa3..3759bed 100644 if (reactNative.exists()) { return reactNative } -diff --git a/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml b/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml -index dbda53f..98fb413 100644 ---- a/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml -+++ b/node_modules/@react-native-camera-roll/camera-roll/android/src/main/AndroidManifest.xml -@@ -1,6 +1,6 @@ - - -+ > - - - -\ No newline at end of file diff --git a/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm -index 4769d28..75b74b9 100644 +index 4769d28..ef88a07 100644 --- a/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm +++ b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm -@@ -207,6 +207,21 @@ static void requestPhotoLibraryAccess(RCTPromiseRejectBlock reject, PhotosAuthor +@@ -207,6 +207,14 @@ static void requestPhotoLibraryAccess(RCTPromiseRejectBlock reject, PhotosAuthor options.fetchLimit = 1; PHFetchResult *createdAsset = [PHAsset fetchAssetsWithLocalIdentifiers:@[placeholder.localIdentifier] options:options]; @@ -41,13 +28,6 @@ index 4769d28..75b74b9 100644 + }); + return; + } -+ -+ if (![createdAsset isKindOfClass:[PHAsset class]]) { -+ resolve(@{ -+ @"node": [NSNull null] -+ }); -+ return; -+ } + if (createdAsset.count < 1) { reject(kErrorUnableToSave, nil, nil);