diff --git a/README.md b/README.md index 1193753..e6e6bb0 100644 --- a/README.md +++ b/README.md @@ -71,41 +71,43 @@ ImagePicker.clean().then(() => { #### Request Object -| Property | Type | Description | -| ------------- |:-------------:| :-----| -| cropping | bool (default false) | Enable or disable cropping | -| width | number | Width 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 | -| includeBase64 | bool (default false) | Enable or disable returning base64 data with image | -| 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. | -| cropperToolbarColor (android only) | string (default `#424242`) | When cropping image, determines the color of Toolbar. | -| 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 | -| 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 | -| 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 | -| compressImageMaxWidth | number (default none) | Compress image with maximum width | -| 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) | -| 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' | -| 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 | -| 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 | +| Property | Type | Description | +| --------------------------------------- | :--------------------------------------: | :--------------------------------------- | +| cropping | bool (default false) | Enable or disable cropping | +| width | number | Width 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 | +| includeBase64 | bool (default false) | Enable or disable returning base64 data with image | +| 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. | +| cropperToolbarColor (android only) | string (default `#424242`) | When cropping image, determines the color of Toolbar. | +| 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 | +| 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 | +| 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 | +| compressImageMaxWidth | number (default none) | Compress image with maximum width | +| 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) | +| 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' | +| 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 | +| 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 | #### Response Object -| Property | Type | Description | -| ------------- |:-------------:| :-----| -| path | string | Selected image location | -| 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 | 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 | ## Install @@ -180,7 +182,7 @@ Details for second approach: 1. Remove the pre-built frameworks from `Embedded Binaries` 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 *MIT* diff --git a/ios/ImageCropPicker.h b/ios/ImageCropPicker.h index 0a40e54..4e81d47 100644 --- a/ios/ImageCropPicker.h +++ b/ios/ImageCropPicker.h @@ -36,6 +36,7 @@ RSKImageCropViewControllerDelegate, RSKImageCropViewControllerDataSource> +@property (nonatomic, strong) NSMutableDictionary *croppingFile; @property (nonatomic, strong) NSDictionary *defaultOptions; @property (nonatomic, strong) Compression *compression; @property (nonatomic, retain) NSMutableDictionary *options; diff --git a/ios/ImageCropPicker.m b/ios/ImageCropPicker.m index 4332223..64a0254 100644 --- a/ios/ImageCropPicker.m +++ b/ios/ImageCropPicker.m @@ -153,7 +153,8 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info { UIImage *chosenImage = [info objectForKey:UIImagePickerControllerOriginalImage]; 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 { @@ -374,6 +375,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options error:nil]; completion([self createAttachmentResponse:[outputURL absoluteString] + withLocalIdentifier: forAsset.localIdentifier + withFilename: sourceURL.lastPathComponent withWidth:[NSNumber numberWithFloat:track.naturalSize.width] withHeight:[NSNumber numberWithFloat:track.naturalSize.height] 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 @{ @"path": filePath, + @"localIdentifier": localIdentifier, + @"filename": filename, @"width": width, @"height": height, @"mime": mime, @@ -448,7 +453,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options requestImageDataForAsset:phAsset options:options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { - + + NSURL *sourceURL = [info objectForKey:@"PHImageFileURLKey"]; + dispatch_async(dispatch_get_main_queue(), ^{ [lock lock]; UIImage *imgT = [UIImage imageWithData:imageData]; @@ -467,6 +474,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options } [selections addObject:[self createAttachmentResponse:filePath + withLocalIdentifier: phAsset.localIdentifier + withFilename: sourceURL.lastPathComponent withWidth:imageResult.width withHeight:imageResult.height withMime:imageResult.mime @@ -515,10 +524,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options resultHandler:^(NSData *imageData, NSString *dataUTI, UIImageOrientation orientation, NSDictionary *info) { + NSURL *sourceURL = [info objectForKey:@"PHImageFileURLKey"]; dispatch_async(dispatch_get_main_queue(), ^{ [indicatorView stopAnimating]; [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, // 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 { +- (void) processSingleImagePick:(UIImage*)image withViewController:(UIViewController*)viewController withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename { if (image == nil) { [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ @@ -543,8 +553,15 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options }]]; return; } - + + NSLog(@"id: %@ filename: %@", localIdentifier, filename); + 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]; } else { 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. [viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{ self.resolve([self createAttachmentResponse:filePath + withLocalIdentifier: localIdentifier + withFilename: filename withWidth:imageResult.width withHeight:imageResult.height withMime:imageResult.mime @@ -669,6 +688,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options [self dismissCropper:controller dismissAll: YES completion:[self waitAnimationEnd:^{ self.resolve([self createAttachmentResponse:filePath + withLocalIdentifier: self.croppingFile[@"localIdentifier"] + withFilename: self.croppingFile[@"filename"] withWidth:imageResult.width withHeight:imageResult.height withMime:imageResult.mime