returned localIdentifier and filename in response

localIdentifier is the unique id for each PHAsset and the filename of each file, and updated the README
This commit is contained in:
CHEN Jiajie 2017-07-25 15:30:37 +08:00
parent 18d5403771
commit 57e57c7ca6
3 changed files with 64 additions and 40 deletions

View File

@ -71,41 +71,43 @@ ImagePicker.clean().then(() => {
#### Request Object #### Request Object
| Property | Type | Description | | Property | Type | Description |
| ------------- |:-------------:| :-----| | --------------------------------------- | :--------------------------------------: | :--------------------------------------- |
| cropping | bool (default false) | Enable or disable cropping | | cropping | bool (default false) | Enable or disable cropping |
| width | number | Width of result image when used with `cropping` option | | width | number | Width of result image when used with `cropping` option |
| height | number | Height of result image when used with `cropping` option | | height | number | Height of result image when used with `cropping` option |
| multiple | bool (default false) | Enable or disable multiple image selection | | multiple | bool (default false) | Enable or disable multiple image selection |
| includeBase64 | bool (default false) | Enable or disable returning base64 data with image | | includeBase64 | bool (default false) | Enable or disable returning base64 data with image |
| cropperActiveWidgetColor (android only) | string (default `"#424242"`) | When cropping image, determines ActiveWidget color. | | cropperActiveWidgetColor (android only) | string (default `"#424242"`) | When cropping image, determines ActiveWidget color. |
| 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. |
| 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 |
| useFrontCamera (ios only) | bool (default false) | Whether to default to the front/'selfie' camera when opened | | useFrontCamera (ios only) | bool (default false) | Whether to default to the front/'selfie' camera when opened |
| compressVideoPreset (ios only) | string (default MediumQuality) | Choose which preset will be used for video compression | | compressVideoPreset (ios only) | string (default MediumQuality) | Choose which preset will be used for video compression |
| compressImageMaxWidth | number (default none) | Compress image with maximum width | | compressImageMaxWidth | number (default none) | Compress image with maximum width |
| compressImageMaxHeight | number (default none) | Compress image with maximum height | | compressImageMaxHeight | number (default none) | Compress image with maximum height |
| compressImageQuality | number (default 1) | Compress image with quality (from 0 to 1, where 1 is best quality) | | compressImageQuality | number (default 1) | Compress image with quality (from 0 to 1, where 1 is best quality) |
| loadingLabelText (ios only) | string (default "Processing assets...") | Text displayed while photo is loading in picker | | loadingLabelText (ios only) | string (default "Processing assets...") | Text displayed while photo is loading in picker |
| mediaType | string (default any) | Accepted mediaType for image selection, can be one of: 'photo', 'video', or 'any' | | mediaType | string (default any) | Accepted mediaType for image selection, can be one of: 'photo', 'video', or 'any' |
| showsSelectedCount (ios only) | bool (default true) | Whether to show the number of selected assets | | showsSelectedCount (ios only) | bool (default true) | Whether to show the number of selected assets |
| showCropGuidelines (android only) | bool (default true) | Whether to show the 3x3 grid on top of the image during cropping | | showCropGuidelines (android only) | bool (default true) | Whether to show the 3x3 grid on top of the image during cropping |
| hideBottomControls (android only) | bool (default false) | Whether to display bottom controls | | hideBottomControls (android only) | bool (default false) | Whether to display bottom controls |
| 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 |
| width | number | Selected image width | | localIdentifier | string | Selected images' localidentifier, used for PHAsset searching |
| height | number | Selected image height | | filename | string | Selected images' filename |
| mime | string | Selected image MIME type (image/jpeg, image/png) | | width | number | Selected image width |
| size | number | Selected image size in bytes | | height | number | Selected image height |
| data | base64 | Optional base64 selected file representation | | 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 ## Install
@ -180,7 +182,7 @@ Details for second approach:
1. Remove the pre-built frameworks from `Embedded Binaries` 1. Remove the pre-built frameworks from `Embedded Binaries`
2. Build for Device 2. Build for Device
4. Add the newly built binaries for both frameworks to `Embedded Binaries` (located at `Libraries/imageCropPicker/Libraries/_framework_name_.xcodeproj/Products/_framework_name_.framework`) 3. Add the newly built binaries for both frameworks to `Embedded Binaries` (located at `Libraries/imageCropPicker/Libraries/_framework_name_.xcodeproj/Products/_framework_name_.framework`)
## License ## License
*MIT* *MIT*

View File

@ -36,6 +36,7 @@
RSKImageCropViewControllerDelegate, RSKImageCropViewControllerDelegate,
RSKImageCropViewControllerDataSource> RSKImageCropViewControllerDataSource>
@property (nonatomic, strong) NSMutableDictionary *croppingFile;
@property (nonatomic, strong) NSDictionary *defaultOptions; @property (nonatomic, strong) NSDictionary *defaultOptions;
@property (nonatomic, strong) Compression *compression; @property (nonatomic, strong) Compression *compression;
@property (nonatomic, retain) NSMutableDictionary *options; @property (nonatomic, retain) NSMutableDictionary *options;

View File

@ -153,7 +153,8 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage]; UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImage *chosenImageT = [chosenImage fixOrientation]; UIImage *chosenImageT = [chosenImage fixOrientation];
[self processSingleImagePick:chosenImageT withViewController:picker];
[self processSingleImagePick:chosenImageT withViewController:picker withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]];
} }
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker { - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
@ -374,6 +375,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
error:nil]; error:nil];
completion([self createAttachmentResponse:[outputURL absoluteString] completion([self createAttachmentResponse:[outputURL absoluteString]
withLocalIdentifier: forAsset.localIdentifier
withFilename: sourceURL.lastPathComponent
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"
@ -386,9 +389,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
}]; }];
} }
- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data { - (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 {
return @{ return @{
@"path": filePath, @"path": filePath,
@"localIdentifier": localIdentifier,
@"filename": filename,
@"width": width, @"width": width,
@"height": height, @"height": height,
@"mime": mime, @"mime": mime,
@ -449,6 +454,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
options:options options:options
resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) {
NSURL *sourceURL = [info objectForKey:@"PHImageFileURLKey"];
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
[lock lock]; [lock lock];
UIImage *imgT = [UIImage imageWithData:imageData]; UIImage *imgT = [UIImage imageWithData:imageData];
@ -467,6 +474,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
} }
[selections addObject:[self createAttachmentResponse:filePath [selections addObject:[self createAttachmentResponse:filePath
withLocalIdentifier: phAsset.localIdentifier
withFilename: sourceURL.lastPathComponent
withWidth:imageResult.width withWidth:imageResult.width
withHeight:imageResult.height withHeight:imageResult.height
withMime:imageResult.mime withMime:imageResult.mime
@ -515,10 +524,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
resultHandler:^(NSData *imageData, NSString *dataUTI, resultHandler:^(NSData *imageData, NSString *dataUTI,
UIImageOrientation orientation, UIImageOrientation orientation,
NSDictionary *info) { NSDictionary *info) {
NSURL *sourceURL = [info objectForKey:@"PHImageFileURLKey"];
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]; [self processSingleImagePick:[UIImage imageWithData:imageData] withViewController:imagePickerController withLocalIdentifier:phAsset.localIdentifier withFilename:sourceURL.lastPathComponent];
}); });
}]; }];
} }
@ -535,7 +545,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 { - (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename {
if (image == nil) { if (image == nil) {
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
@ -544,7 +554,14 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
return; return;
} }
NSLog(@"id: %@ filename: %@", localIdentifier, filename);
if ([[[self options] objectForKey:@"cropping"] boolValue]) { if ([[[self options] objectForKey:@"cropping"] boolValue]) {
self.croppingFile = [[NSMutableDictionary alloc] init];
self.croppingFile[@"localIdentifier"] = localIdentifier;
self.croppingFile[@"filename"] = filename;
NSLog(@"CroppingFile %@", self.croppingFile);
[self startCropping:image]; [self startCropping:image];
} else { } else {
ImageResult *imageResult = [self.compression compressImage:image withOptions:self.options]; ImageResult *imageResult = [self.compression compressImage:image withOptions:self.options];
@ -560,6 +577,8 @@ 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
withLocalIdentifier: localIdentifier
withFilename: filename
withWidth:imageResult.width withWidth:imageResult.width
withHeight:imageResult.height withHeight:imageResult.height
withMime:imageResult.mime withMime:imageResult.mime
@ -669,6 +688,8 @@ 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
withLocalIdentifier: self.croppingFile[@"localIdentifier"]
withFilename: self.croppingFile[@"filename"]
withWidth:imageResult.width withWidth:imageResult.width
withHeight:imageResult.height withHeight:imageResult.height
withMime:imageResult.mime withMime:imageResult.mime