Skip to content

Commit

Permalink
Merge pull request Expensify#37316 from shahinyan11/issue/36870
Browse files Browse the repository at this point in the history
Fix displaying error message when image has been downloaded
  • Loading branch information
thienlnam authored Mar 5, 2024
2 parents 570c53f + 683aae1 commit 7002422
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 32 deletions.
6 changes: 4 additions & 2 deletions ios/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1169,7 +1169,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)
Expand Down Expand Up @@ -1938,7 +1940,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
Expand Down
12 changes: 7 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
"@kie/mock-github": "^1.0.0",
"@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",
Expand Down
15 changes: 0 additions & 15 deletions patches/@react-native-camera-roll+camera-roll+5.4.0.patch

This file was deleted.

34 changes: 34 additions & 0 deletions patches/@react-native-camera-roll+camera-roll+7.4.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
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..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) {
}

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/ios/RNCCameraRoll.mm b/node_modules/@react-native-camera-roll/camera-roll/ios/RNCCameraRoll.mm
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,14 @@ static void requestPhotoLibraryAccess(RCTPromiseRejectBlock reject, PhotosAuthor
options.fetchLimit = 1;
PHFetchResult<PHAsset *> *createdAsset = [PHAsset fetchAssetsWithLocalIdentifiers:@[placeholder.localIdentifier]
options:options];
+
+ if (![createdAsset isKindOfClass:[PHAsset class]]) {
+ resolve(@{
+ @"node": [NSNull null]
+ });
+ return;
+ }
+
if (createdAsset.count < 1) {
reject(kErrorUnableToSave, nil, nil);
return;
16 changes: 7 additions & 9 deletions src/libs/fileDownload/index.ios.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<string> {
function downloadVideo(fileUrl: string, fileName: string): Promise<PhotoIdentifier> {
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)
Expand All @@ -47,20 +48,17 @@ function downloadVideo(fileUrl: string, fileName: string): Promise<string> {
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));
});
Expand Down

0 comments on commit 7002422

Please sign in to comment.