callback to js with more info

This commit is contained in:
Ran Greenberg 2016-06-26 18:38:37 +03:00
parent 2a4f155601
commit aeefe87ada
4 changed files with 38 additions and 29 deletions

View File

@ -31,7 +31,7 @@
* on the same Wi-Fi network. * 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 * OPTION 2

View File

@ -417,16 +417,24 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
[PHPhotoLibrary requestAuthorization:^( PHAuthorizationStatus status ) { [PHPhotoLibrary requestAuthorization:^( PHAuthorizationStatus status ) {
if ( status == PHAuthorizationStatusAuthorized ) { if ( status == PHAuthorizationStatusAuthorized ) {
NSMutableDictionary *imageInfoDict = [[NSMutableDictionary alloc] init];
NSURL *temporaryFileURL = [self saveToTmpFolder:imageData]; NSURL *temporaryFileURL = [self saveToTmpFolder:imageData];
if (temporaryFileURL) {
imageInfoDict[@"uri"] = temporaryFileURL.description;
imageInfoDict[@"name"] = temporaryFileURL.lastPathComponent;
}
imageInfoDict[@"size"] = [NSNumber numberWithInteger:imageData.length];
if (shouldSaveToCameraRoll) { if (shouldSaveToCameraRoll) {
[self saveImageToCameraRoll:imageData temporaryFileURL:temporaryFileURL]; [self saveImageToCameraRoll:imageData temporaryFileURL:temporaryFileURL];
} }
if (block) { if (block) {
block(temporaryFileURL.description); block(imageInfoDict);
} }
} }
}]; }];
@ -755,7 +763,7 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{
{ {
// CGPoint devicePoint = CGPointMake( 0.5, 0.5 ); // CGPoint devicePoint = CGPointMake( 0.5, 0.5 );
// [self focusWithMode:AVCaptureFocusModeContinuousAutoFocus exposeWithMode:AVCaptureExposureModeContinuousAutoExposure atDevicePoint:devicePoint monitorSubjectAreaChange:NO]; // [self focusWithMode:AVCaptureFocusModeContinuousAutoFocus exposeWithMode:AVCaptureExposureModeContinuousAutoExposure atDevicePoint:devicePoint monitorSubjectAreaChange:NO];
// NSLog(@"subjectAreaDidChange"); // NSLog(@"subjectAreaDidChange");
} }

View File

@ -100,6 +100,12 @@ RCT_EXPORT_MODULE();
NSMutableDictionary *albumsDict = [[NSMutableDictionary alloc] init]; NSMutableDictionary *albumsDict = [[NSMutableDictionary alloc] init];
NSInteger collectionCount = collections.count; NSInteger collectionCount = collections.count;
if (collectionCount == 0) {
if (block) {
block(nil);
}
}
[collections enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL * _Nonnull stop) { [collections enumerateObjectsUsingBlock:^(PHAssetCollection *collection, NSUInteger idx, BOOL * _Nonnull stop) {
[self extractCollection:collection imageRequestOptions:options thumbnailSize:thumbnailSize block:^(NSDictionary *album) { [self extractCollection:collection imageRequestOptions:options thumbnailSize:thumbnailSize block:^(NSDictionary *album) {

View File

@ -181,29 +181,10 @@ static NSString * const CellReuseIdentifier = @"Cell";
[self.selectedAssets addObject:asset]; [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 { - (void)collectionView:(UICollectionView *)collectionView didDeselectItemAtIndexPath:(NSIndexPath *)indexPath {
} }
@ -241,6 +222,7 @@ RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve
NSMutableArray *assetsUrls = [[NSMutableArray alloc] init]; NSMutableArray *assetsUrls = [[NSMutableArray alloc] init];
for (PHAsset *asset in self.galleryView.selectedAssets) { 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) { [self.galleryView.imageManager requestImageDataForAsset:asset options:nil resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
NSURL *fileURLKey = info[@"PHImageFileURLKey"]; NSURL *fileURLKey = info[@"PHImageFileURLKey"];
@ -250,13 +232,26 @@ RCT_EXPORT_METHOD(getSelectedImages:(RCTPromiseResolveBlock)resolve
} }
} }
NSMutableDictionary *assetInfoDict = [[NSMutableDictionary alloc] init];
NSString *fileName = ((NSURL*)info[@"PHImageFileURLKey"]).lastPathComponent; 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]; NSURL *fileURL = [directoryURL URLByAppendingPathComponent:fileName];
NSError *error = nil; NSError *error = nil;
[imageData writeToURL:fileURL options:NSDataWritingAtomic error:&error]; [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) { if (asset == self.galleryView.selectedAssets.lastObject) {