mirror of
https://github.com/status-im/react-native-image-crop-picker.git
synced 2025-02-24 03:18:17 +00:00
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:
parent
18d5403771
commit
57e57c7ca6
@ -72,7 +72,7 @@ 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 |
|
||||||
@ -99,8 +99,10 @@ ImagePicker.clean().then(() => {
|
|||||||
#### 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 |
|
||||||
|
| filename | string | Selected images' filename |
|
||||||
| width | number | Selected image width |
|
| width | number | Selected image width |
|
||||||
| height | number | Selected image height |
|
| height | number | Selected image height |
|
||||||
| mime | string | Selected image MIME type (image/jpeg, image/png) |
|
| mime | string | Selected image MIME type (image/jpeg, image/png) |
|
||||||
@ -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*
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
Loading…
x
Reference in New Issue
Block a user