From f8027bb997c27fa236e2d4208040b8172e941727 Mon Sep 17 00:00:00 2001 From: Edgar Aroutiounian Date: Sun, 13 Aug 2017 14:00:51 -0700 Subject: [PATCH 1/2] Implement deletion of asset-library files --- Libraries/CameraRoll/CameraRoll.js | 4 ++++ Libraries/CameraRoll/RCTCameraRollManager.m | 22 +++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/Libraries/CameraRoll/CameraRoll.js b/Libraries/CameraRoll/CameraRoll.js index 50487873545bd7..466bb9729e2779 100644 --- a/Libraries/CameraRoll/CameraRoll.js +++ b/Libraries/CameraRoll/CameraRoll.js @@ -135,6 +135,10 @@ class CameraRoll { return this.saveToCameraRoll(tag, 'photo'); } + static deletePhotos(photos: Array) { + return RCTCameraRollManager.deletePhotos(photos); + } + /** * Saves the photo or video to the camera roll / gallery. * diff --git a/Libraries/CameraRoll/RCTCameraRollManager.m b/Libraries/CameraRoll/RCTCameraRollManager.m index 64cf734b1ac3cd..dbe8450a29d8b0 100644 --- a/Libraries/CameraRoll/RCTCameraRollManager.m +++ b/Libraries/CameraRoll/RCTCameraRollManager.m @@ -12,6 +12,7 @@ #import #import #import +#import #import #import @@ -234,6 +235,27 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve, }]; } +RCT_EXPORT_METHOD(deletePhotos:(NSArray*)assets + resolve:(RCTPromiseResolveBlock)resolve + reject:(RCTPromiseRejectBlock)reject) +{ + NSArray *assets_ = [RCTConvert NSURLArray:assets]; + [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{ + PHFetchResult *fetched = + [PHAsset fetchAssetsWithALAssetURLs:assets_ options:nil]; + [PHAssetChangeRequest deleteAssets:fetched]; + } + completionHandler:^(BOOL success, NSError *error) { + if (success == YES) { + resolve(@(success)); + } + else { + reject(@"Couldn't delete", @"Couldn't delete assets", error); + } + } + ]; +} + static void checkPhotoLibraryConfig() { #if RCT_DEV From 4fecedcc2b0d2885eeec14740bf2a186f600838c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=A9ctor=20Ramos?= <165856+hramos@users.noreply.github.com> Date: Wed, 29 Nov 2017 11:14:02 -0800 Subject: [PATCH 2/2] Update RCTCameraRollManager.m --- Libraries/CameraRoll/RCTCameraRollManager.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Libraries/CameraRoll/RCTCameraRollManager.m b/Libraries/CameraRoll/RCTCameraRollManager.m index dbe8450a29d8b0..4b6a78bde2c21b 100644 --- a/Libraries/CameraRoll/RCTCameraRollManager.m +++ b/Libraries/CameraRoll/RCTCameraRollManager.m @@ -247,10 +247,10 @@ static void RCTResolvePromise(RCTPromiseResolveBlock resolve, } completionHandler:^(BOOL success, NSError *error) { if (success == YES) { - resolve(@(success)); + resolve(@(success)); } else { - reject(@"Couldn't delete", @"Couldn't delete assets", error); + reject(@"Couldn't delete", @"Couldn't delete assets", error); } } ];