added minFiles option, and a new response called sourceURL
This commit is contained in:
parent
2651916845
commit
296190e608
22
README.md
22
README.md
|
@ -82,6 +82,7 @@ ImagePicker.clean().then(() => {
|
|||
| 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. |
|
||||
| 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 |
|
||||
| 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 |
|
||||
|
@ -98,16 +99,17 @@ ImagePicker.clean().then(() => {
|
|||
| enableRotationGesture (android only) | bool (default false) | Whether to enable rotating the image by hand gesture |
|
||||
#### Response Object
|
||||
|
||||
| Property | Type | Description |
|
||||
| --------------- | :----: | :--------------------------------------- |
|
||||
| path | string | Selected image location |
|
||||
| localIdentifier | string | Selected images' localidentifier, used for PHAsset searching |
|
||||
| filename | string | Selected images' filename |
|
||||
| width | number | Selected image width |
|
||||
| height | number | Selected image height |
|
||||
| mime | string | Selected image MIME type (image/jpeg, image/png) |
|
||||
| size | number | Selected image size in bytes |
|
||||
| data | base64 | Optional base64 selected file representation |
|
||||
| Property | Type | Description |
|
||||
| ------------------------- | :----: | :--------------------------------------- |
|
||||
| path | string | Selected image location |
|
||||
| localIdentifier(ios only) | string | Selected images' localidentifier, used for PHAsset searching |
|
||||
| sourceURL(ios only) | string | Selected images' source path, do not have write access |
|
||||
| filename(ios only) | string | Selected images' filename |
|
||||
| width | number | Selected image width |
|
||||
| height | number | Selected image height |
|
||||
| mime | string | Selected image MIME type (image/jpeg, image/png) |
|
||||
| size | number | Selected image size in bytes |
|
||||
| data | base64 | Optional base64 selected file representation |
|
||||
|
||||
## Install
|
||||
|
||||
|
|
|
@ -52,6 +52,7 @@ RCT_EXPORT_MODULE();
|
|||
@"cropperCircleOverlay": @NO,
|
||||
@"includeBase64": @NO,
|
||||
@"compressVideo": @YES,
|
||||
@"minFiles": @1,
|
||||
@"maxFiles": @5,
|
||||
@"width": @200,
|
||||
@"waitAnimationEnd": @YES,
|
||||
|
@ -154,7 +155,7 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
|||
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
|
||||
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 {
|
||||
|
@ -233,7 +234,8 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
|||
[QBImagePickerController new];
|
||||
imagePickerController.delegate = self;
|
||||
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];
|
||||
|
||||
if ([self.options objectForKey:@"smartAlbums"] != nil) {
|
||||
|
@ -375,8 +377,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
error:nil];
|
||||
|
||||
completion([self createAttachmentResponse:[outputURL absoluteString]
|
||||
withSourceURL:[sourceURL absoluteString]
|
||||
withLocalIdentifier: forAsset.localIdentifier
|
||||
withFilename: sourceURL.lastPathComponent
|
||||
withFilename:[forAsset valueForKey:@"filename"]
|
||||
withWidth:[NSNumber numberWithFloat:track.naturalSize.width]
|
||||
withHeight:[NSNumber numberWithFloat:track.naturalSize.height]
|
||||
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 @{
|
||||
@"path": filePath,
|
||||
@"sourceURL": sourceURL,
|
||||
@"localIdentifier": (localIdentifier) ? localIdentifier : @"",
|
||||
@"filename": (filename) ? filename : @"",
|
||||
@"width": width,
|
||||
|
@ -475,8 +479,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
}
|
||||
|
||||
[selections addObject:[self createAttachmentResponse:filePath
|
||||
withSourceURL:[sourceURL absoluteString]
|
||||
withLocalIdentifier: phAsset.localIdentifier
|
||||
withFilename: sourceURL.lastPathComponent
|
||||
withFilename: [phAsset valueForKey:@"filename"]
|
||||
withWidth:imageResult.width
|
||||
withHeight:imageResult.height
|
||||
withMime:imageResult.mime
|
||||
|
@ -530,7 +535,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[indicatorView stopAnimating];
|
||||
[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,
|
||||
// this method will take care of attaching image metadata, and sending image to cropping controller
|
||||
// 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) {
|
||||
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
||||
|
@ -560,6 +565,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
|
||||
if ([[[self options] objectForKey:@"cropping"] boolValue]) {
|
||||
self.croppingFile = [[NSMutableDictionary alloc] init];
|
||||
self.croppingFile[@"sourceURL"] = sourceURL;
|
||||
self.croppingFile[@"localIdentifier"] = localIdentifier;
|
||||
self.croppingFile[@"filename"] = filename;
|
||||
NSLog(@"CroppingFile %@", self.croppingFile);
|
||||
|
@ -579,6 +585,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
// Alert.alert in the .then() handler.
|
||||
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
||||
self.resolve([self createAttachmentResponse:filePath
|
||||
withSourceURL:sourceURL
|
||||
withLocalIdentifier:localIdentifier
|
||||
withFilename:filename
|
||||
withWidth:imageResult.width
|
||||
|
@ -690,6 +697,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||
|
||||
[self dismissCropper:controller dismissAll: YES completion:[self waitAnimationEnd:^{
|
||||
self.resolve([self createAttachmentResponse:filePath
|
||||
withSourceURL: self.croppingFile[@"sourceURL"]
|
||||
withLocalIdentifier: self.croppingFile[@"localIdentifier"]
|
||||
withFilename: self.croppingFile[@"filename"]
|
||||
withWidth:imageResult.width
|
||||
|
|
Loading…
Reference in New Issue