Merge pull request #407 from gameboyVito/min-files

added minFiles option, and a new response called sourceURL
This commit is contained in:
Ivan Pusic 2017-08-04 11:23:31 +02:00 committed by GitHub
commit 6b79866963
2 changed files with 27 additions and 17 deletions

View File

@ -82,6 +82,7 @@ ImagePicker.clean().then(() => {
| cropperStatusBarColor (android only) | string (default `#424242`) | When cropping image, determines the color of StatusBar. | | cropperStatusBarColor (android only) | string (default `#424242`) | When cropping image, determines the color of StatusBar. |
| cropperToolbarColor (android only) | string (default `#424242`) | When cropping image, determines the color of Toolbar. | | cropperToolbarColor (android only) | string (default `#424242`) | When cropping image, determines the color of Toolbar. |
| cropperCircleOverlay | bool (default false) | Enable or disable circular cropping mask. | | cropperCircleOverlay | bool (default false) | Enable or disable circular cropping mask. |
| minFiles (ios only) | number (default 1) | Min number of files to select when using `multiple` option |
| maxFiles (ios only) | number (default 5) | Max number of files to select when using `multiple` option | | maxFiles (ios only) | number (default 5) | Max number of files to select when using `multiple` option |
| waitAnimationEnd (ios only) | bool (default true) | Promise will resolve/reject once ViewController `completion` block is called | | waitAnimationEnd (ios only) | bool (default true) | Promise will resolve/reject once ViewController `completion` block is called |
| smartAlbums (ios only) | array (default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) | List of smart albums to choose from | | smartAlbums (ios only) | array (default ['UserLibrary', 'PhotoStream', 'Panoramas', 'Videos', 'Bursts']) | List of smart albums to choose from |
@ -98,16 +99,17 @@ ImagePicker.clean().then(() => {
| enableRotationGesture (android only) | bool (default false) | Whether to enable rotating the image by hand gesture | | enableRotationGesture (android only) | bool (default false) | Whether to enable rotating the image by hand gesture |
#### Response Object #### Response Object
| Property | Type | Description | | Property | Type | Description |
| --------------- | :----: | :--------------------------------------- | | ------------------------- | :----: | :--------------------------------------- |
| path | string | Selected image location | | path | string | Selected image location |
| localIdentifier | string | Selected images' localidentifier, used for PHAsset searching | | localIdentifier(ios only) | string | Selected images' localidentifier, used for PHAsset searching |
| filename | string | Selected images' filename | | sourceURL(ios only) | string | Selected images' source path, do not have write access |
| width | number | Selected image width | | filename(ios only) | string | Selected images' filename |
| height | number | Selected image height | | width | number | Selected image width |
| mime | string | Selected image MIME type (image/jpeg, image/png) | | height | number | Selected image height |
| size | number | Selected image size in bytes | | mime | string | Selected image MIME type (image/jpeg, image/png) |
| data | base64 | Optional base64 selected file representation | | size | number | Selected image size in bytes |
| data | base64 | Optional base64 selected file representation |
## Install ## Install

View File

@ -52,6 +52,7 @@ RCT_EXPORT_MODULE();
@"cropperCircleOverlay": @NO, @"cropperCircleOverlay": @NO,
@"includeBase64": @NO, @"includeBase64": @NO,
@"compressVideo": @YES, @"compressVideo": @YES,
@"minFiles": @1,
@"maxFiles": @5, @"maxFiles": @5,
@"width": @200, @"width": @200,
@"waitAnimationEnd": @YES, @"waitAnimationEnd": @YES,
@ -154,7 +155,7 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *chosenImageT = [chosenImage fixOrientation]; UIImage *chosenImageT = [chosenImage fixOrientation];
[self processSingleImagePick:chosenImageT withViewController:picker withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]]; [self processSingleImagePick:chosenImageT withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]];
} }
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
@ -233,7 +234,8 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
[QBImagePickerController new]; [QBImagePickerController new];
imagePickerController.delegate = self; imagePickerController.delegate = self;
imagePickerController.allowsMultipleSelection = [[self.options objectForKey:@"multiple"] boolValue]; imagePickerController.allowsMultipleSelection = [[self.options objectForKey:@"multiple"] boolValue];
imagePickerController.maximumNumberOfSelection = [[self.options objectForKey:@"maxFiles"] intValue]; imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]);
imagePickerController.maximumNumberOfSelection = abs([[self.options objectForKey:@"maxFiles"] intValue]);
imagePickerController.showsNumberOfSelectedAssets = [[self.options objectForKey:@"showsSelectedCount"] boolValue]; imagePickerController.showsNumberOfSelectedAssets = [[self.options objectForKey:@"showsSelectedCount"] boolValue];
if ([self.options objectForKey:@"smartAlbums"] != nil) { if ([self.options objectForKey:@"smartAlbums"] != nil) {
@ -375,8 +377,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
error:nil]; error:nil];
completion([self createAttachmentResponse:[outputURL absoluteString] completion([self createAttachmentResponse:[outputURL absoluteString]
withSourceURL:[sourceURL absoluteString]
withLocalIdentifier: forAsset.localIdentifier withLocalIdentifier: forAsset.localIdentifier
withFilename: sourceURL.lastPathComponent withFilename:[forAsset valueForKey:@"filename"]
withWidth:[NSNumber numberWithFloat:track.naturalSize.width] withWidth:[NSNumber numberWithFloat:track.naturalSize.width]
withHeight:[NSNumber numberWithFloat:track.naturalSize.height] withHeight:[NSNumber numberWithFloat:track.naturalSize.height]
withMime:@"video/mp4" withMime:@"video/mp4"
@ -389,9 +392,10 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
}]; }];
} }
- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data { - (NSDictionary*) createAttachmentResponse:(NSString*)filePath withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data {
return @{ return @{
@"path": filePath, @"path": filePath,
@"sourceURL": sourceURL,
@"localIdentifier": (localIdentifier) ? localIdentifier : @"", @"localIdentifier": (localIdentifier) ? localIdentifier : @"",
@"filename": (filename) ? filename : @"", @"filename": (filename) ? filename : @"",
@"width": width, @"width": width,
@ -475,8 +479,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
} }
[selections addObject:[self createAttachmentResponse:filePath [selections addObject:[self createAttachmentResponse:filePath
withSourceURL:[sourceURL absoluteString]
withLocalIdentifier: phAsset.localIdentifier withLocalIdentifier: phAsset.localIdentifier
withFilename: sourceURL.lastPathComponent withFilename: [phAsset valueForKey:@"filename"]
withWidth:imageResult.width withWidth:imageResult.width
withHeight:imageResult.height withHeight:imageResult.height
withMime:imageResult.mime withMime:imageResult.mime
@ -530,7 +535,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[indicatorView stopAnimating]; [indicatorView stopAnimating];
[overlayView removeFromSuperview]; [overlayView removeFromSuperview];
[self processSingleImagePick:[UIImage imageWithData:imageData] withViewController:imagePickerController withLocalIdentifier:phAsset.localIdentifier withFilename:sourceURL.lastPathComponent]; [self processSingleImagePick:[UIImage imageWithData:imageData] withViewController:imagePickerController withSourceURL:[sourceURL absoluteString] withLocalIdentifier:phAsset.localIdentifier withFilename:[phAsset valueForKey:@"filename"]];
}); });
}]; }];
} }
@ -547,7 +552,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
// when user selected single image, with camera or from photo gallery, // when user selected single image, with camera or from photo gallery,
// this method will take care of attaching image metadata, and sending image to cropping controller // this method will take care of attaching image metadata, and sending image to cropping controller
// or to user directly // or to user directly
- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename { - (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename {
if (image == nil) { if (image == nil) {
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
@ -560,6 +565,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
if ([[[self options] objectForKey:@"cropping"] boolValue]) { if ([[[self options] objectForKey:@"cropping"] boolValue]) {
self.croppingFile = [[NSMutableDictionary alloc] init]; self.croppingFile = [[NSMutableDictionary alloc] init];
self.croppingFile[@"sourceURL"] = sourceURL;
self.croppingFile[@"localIdentifier"] = localIdentifier; self.croppingFile[@"localIdentifier"] = localIdentifier;
self.croppingFile[@"filename"] = filename; self.croppingFile[@"filename"] = filename;
NSLog(@"CroppingFile %@", self.croppingFile); NSLog(@"CroppingFile %@", self.croppingFile);
@ -579,6 +585,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
// Alert.alert in the .then() handler. // Alert.alert in the .then() handler.
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
self.resolve([self createAttachmentResponse:filePath self.resolve([self createAttachmentResponse:filePath
withSourceURL:sourceURL
withLocalIdentifier:localIdentifier withLocalIdentifier:localIdentifier
withFilename:filename withFilename:filename
withWidth:imageResult.width withWidth:imageResult.width
@ -690,6 +697,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
[self dismissCropper:controller dismissAll: YES completion:[self waitAnimationEnd:^{ [self dismissCropper:controller dismissAll: YES completion:[self waitAnimationEnd:^{
self.resolve([self createAttachmentResponse:filePath self.resolve([self createAttachmentResponse:filePath
withSourceURL: self.croppingFile[@"sourceURL"]
withLocalIdentifier: self.croppingFile[@"localIdentifier"] withLocalIdentifier: self.croppingFile[@"localIdentifier"]
withFilename: self.croppingFile[@"filename"] withFilename: self.croppingFile[@"filename"]
withWidth:imageResult.width withWidth:imageResult.width