From aeefe87adae6f7d98e3006054b46c7dd4c08f736 Mon Sep 17 00:00:00 2001 From: Ran Greenberg Date: Sun, 26 Jun 2016 18:38:37 +0300 Subject: [PATCH] callback to js with more info --- example/ios/example/AppDelegate.m | 2 +- ios/lib/ReactNativeCameraKit/CKCamera.m | 20 +++++++--- .../ReactNativeCameraKit/CKGalleryManager.m | 6 +++ .../CKGalleryViewManager.m | 39 ++++++++----------- 4 files changed, 38 insertions(+), 29 deletions(-) diff --git a/example/ios/example/AppDelegate.m b/example/ios/example/AppDelegate.m index 108d029..1f3f411 100644 --- a/example/ios/example/AppDelegate.m +++ b/example/ios/example/AppDelegate.m @@ -31,7 +31,7 @@ * on the same Wi-Fi network. */ - jsCodeLocation = [NSURL URLWithString:@"http://172.31.9.92:8081/index.ios.bundle?platform=ios&dev=true"]; + jsCodeLocation = [NSURL URLWithString:@"http://172.31.9.77:8081/index.ios.bundle?platform=ios&dev=true"]; /** * OPTION 2 diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.m b/ios/lib/ReactNativeCameraKit/CKCamera.m index 3284618..0775797 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.m +++ b/ios/lib/ReactNativeCameraKit/CKCamera.m @@ -44,9 +44,9 @@ RCT_ENUM_CONVERTER(CKCameraFocushMode, (@{ @implementation RCTConvert(CKCameraZoomMode) RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ - @"on": @(CKCameraZoomModeOn), - @"off": @(CKCameraZoomModeOff) - }), CKCameraZoomModeOn, integerValue) + @"on": @(CKCameraZoomModeOn), + @"off": @(CKCameraZoomModeOff) + }), CKCameraZoomModeOn, integerValue) @end @@ -417,16 +417,24 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ [PHPhotoLibrary requestAuthorization:^( PHAuthorizationStatus status ) { if ( status == PHAuthorizationStatusAuthorized ) { + NSMutableDictionary *imageInfoDict = [[NSMutableDictionary alloc] init]; NSURL *temporaryFileURL = [self saveToTmpFolder:imageData]; + if (temporaryFileURL) { + imageInfoDict[@"uri"] = temporaryFileURL.description; + imageInfoDict[@"name"] = temporaryFileURL.lastPathComponent; + } + + imageInfoDict[@"size"] = [NSNumber numberWithInteger:imageData.length]; + + if (shouldSaveToCameraRoll) { - [self saveImageToCameraRoll:imageData temporaryFileURL:temporaryFileURL]; } if (block) { - block(temporaryFileURL.description); + block(imageInfoDict); } } }]; @@ -755,7 +763,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ { // CGPoint devicePoint = CGPointMake( 0.5, 0.5 ); // [self focusWithMode:AVCaptureFocusModeContinuousAutoFocus exposeWithMode:AVCaptureExposureModeContinuousAutoExposure atDevicePoint:devicePoint monitorSubjectAreaChange:NO]; -// NSLog(@"subjectAreaDidChange"); + // NSLog(@"subjectAreaDidChange"); } diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryManager.m b/ios/lib/ReactNativeCameraKit/CKGalleryManager.m index 77a1328..877e766 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryManager.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryManager.m @@ -100,6 +100,12 @@ RCT_EXPORT_MODULE(); NSMutableDictionary *albumsDict = [[NSMutableDictionary alloc] init]; NSInteger collectionCount = collections.count; + if (collectionCount == 0) { + if (block) { + block(nil); + } + } + [collections enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL * _Nonnull stop) { [self extractCollection:collection imageRequestOptions:options thumbnailSize:thumbnailSize block:^(NSDictionary *album) { diff --git a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m index 8616f14..ec9d572 100644 --- a/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m +++ b/ios/lib/ReactNativeCameraKit/CKGalleryViewManager.m @@ -181,29 +181,10 @@ static NSString * const CellReuseIdentifier = @"Cell"; [self.selectedAssets addObject:asset]; } } - - // [self.imageManager requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { - // - // self.selectedImagesUrls addObject: - // - // - // }]; - - // [asset requestContentEditingInputWithOptions:nil - // completionHandler:^(PHContentEditingInput * _Nullable contentEditingInput, NSDictionary * _Nonnull info) - // { - // [self.selectedImagesUrls removeObject:contentEditingInput.fullSizeImageURL.description]; - // - // - // if (ckCell.isSelected) { - // [self.selectedImagesUrls addObject:contentEditingInput.fullSizeImageURL.absoluteString]; - // } - // }]; - } - } + - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath { } @@ -241,6 +222,7 @@ RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve NSMutableArray *assetsUrls = [[NSMutableArray alloc] init]; for (PHAsset *asset in self.galleryView.selectedAssets) { + [self.galleryView.imageManager requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) { NSURL *fileURLKey = info[@"PHImageFileURLKey"]; @@ -250,13 +232,26 @@ RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve } } - NSString *fileName = ((NSURL*)info[@"PHImageFileURLKey"]).lastPathComponent; + NSMutableDictionary *assetInfoDict = [[NSMutableDictionary alloc] init]; + NSString *fileName = ((NSURL*)info[@"PHImageFileURLKey"]).lastPathComponent; + if (fileName) { + assetInfoDict[@"name"] = fileName; + } + + float imageSize = imageData.length; + assetInfoDict[@"size"] = [NSNumber numberWithFloat:imageSize]; + NSURL *fileURL = [directoryURL URLByAppendingPathComponent:fileName]; NSError *error = nil; [imageData writeToURL:fileURL options:NSDataWritingAtomic error:&error]; - [assetsUrls addObject:fileURL.absoluteString]; + if (!error && fileURL) { + assetInfoDict[@"uri"] = fileURL.absoluteString; + } + + + [assetsUrls addObject:assetInfoDict]; if (asset == self.galleryView.selectedAssets.lastObject) {