mirror of
https://github.com/status-im/react-native-image-crop-picker.git
synced 2025-02-23 10:58:16 +00:00
Add creation and modification date to response (#530)
* added creationDate and modificationDate to response object added modificationDate to Android response * Update Compression.m (#529) Addition of passthrough preset option Update README to include dates in response
This commit is contained in:
parent
a4a2247fef
commit
b59db6bffa
@ -129,6 +129,8 @@ ImagePicker.clean().then(() => {
|
|||||||
| size | number | Selected image size in bytes |
|
| size | number | Selected image size in bytes |
|
||||||
| data | base64 | Optional base64 selected file representation |
|
| data | base64 | Optional base64 selected file representation |
|
||||||
| exif | object | Extracted exif data from image. Response format is platform specific |
|
| exif | object | Extracted exif data from image. Response format is platform specific |
|
||||||
|
| creationDate (ios only) | string | UNIX timestamp when image was created |
|
||||||
|
| modificationDate | string | UNIX timestamp when image was last modified |
|
||||||
|
|
||||||
# Install
|
# Install
|
||||||
|
|
||||||
|
@ -463,6 +463,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Bitmap bmp = validateVideo(videoPath);
|
Bitmap bmp = validateVideo(videoPath);
|
||||||
|
long modificationDate = new File(videoPath).lastModified();
|
||||||
|
|
||||||
WritableMap video = new WritableNativeMap();
|
WritableMap video = new WritableNativeMap();
|
||||||
video.putInt("width", bmp.getWidth());
|
video.putInt("width", bmp.getWidth());
|
||||||
@ -470,6 +471,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
video.putString("mime", mime);
|
video.putString("mime", mime);
|
||||||
video.putInt("size", (int) new File(videoPath).length());
|
video.putInt("size", (int) new File(videoPath).length());
|
||||||
video.putString("path", "file://" + videoPath);
|
video.putString("path", "file://" + videoPath);
|
||||||
|
video.putString("modificationDate", String.valueOf(modificationDate));
|
||||||
|
|
||||||
resultCollector.notifySuccess(video);
|
resultCollector.notifySuccess(video);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -532,12 +534,14 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
File compressedImage = compression.compressImage(activity, options, path);
|
File compressedImage = compression.compressImage(activity, options, path);
|
||||||
String compressedImagePath = compressedImage.getPath();
|
String compressedImagePath = compressedImage.getPath();
|
||||||
BitmapFactory.Options options = validateImage(compressedImagePath);
|
BitmapFactory.Options options = validateImage(compressedImagePath);
|
||||||
|
long modificationDate = new File(path).lastModified();
|
||||||
|
|
||||||
image.putString("path", "file://" + compressedImagePath);
|
image.putString("path", "file://" + compressedImagePath);
|
||||||
image.putInt("width", options.outWidth);
|
image.putInt("width", options.outWidth);
|
||||||
image.putInt("height", options.outHeight);
|
image.putInt("height", options.outHeight);
|
||||||
image.putString("mime", options.outMimeType);
|
image.putString("mime", options.outMimeType);
|
||||||
image.putInt("size", (int) new File(compressedImagePath).length());
|
image.putInt("size", (int) new File(compressedImagePath).length());
|
||||||
|
image.putString("modificationDate", String.valueOf(modificationDate));
|
||||||
|
|
||||||
if (includeBase64) {
|
if (includeBase64) {
|
||||||
image.putString("data", getBase64StringFromFile(compressedImagePath));
|
image.putString("data", getBase64StringFromFile(compressedImagePath));
|
||||||
@ -581,7 +585,7 @@ class PickerModule extends ReactContextBaseJavaModule implements ActivityEventLi
|
|||||||
options.setShowCropGrid(showCropGuidelines);
|
options.setShowCropGrid(showCropGuidelines);
|
||||||
options.setHideBottomControls(hideBottomControls);
|
options.setHideBottomControls(hideBottomControls);
|
||||||
if (cropperToolbarTitle != null) {
|
if (cropperToolbarTitle != null) {
|
||||||
options.setToolbarTitle(cropperToolbarTitle);
|
options.setToolbarTitle(cropperToolbarTitle);
|
||||||
}
|
}
|
||||||
if (enableRotationGesture) {
|
if (enableRotationGesture) {
|
||||||
// UCropActivity.ALL = enable both rotation & scaling
|
// UCropActivity.ALL = enable both rotation & scaling
|
||||||
|
@ -67,7 +67,7 @@ RCT_EXPORT_MODULE();
|
|||||||
};
|
};
|
||||||
self.compression = [[Compression alloc] init];
|
self.compression = [[Compression alloc] init];
|
||||||
}
|
}
|
||||||
|
|
||||||
return self;
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,11 +79,11 @@ RCT_EXPORT_MODULE();
|
|||||||
if ([[self.options objectForKey:@"waitAnimationEnd"] boolValue]) {
|
if ([[self.options objectForKey:@"waitAnimationEnd"] boolValue]) {
|
||||||
return completion;
|
return completion;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (completion != nil) {
|
if (completion != nil) {
|
||||||
completion();
|
completion();
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -106,7 +106,7 @@ RCT_EXPORT_MODULE();
|
|||||||
- (void) setConfiguration:(NSDictionary *)options
|
- (void) setConfiguration:(NSDictionary *)options
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
resolver:(RCTPromiseResolveBlock)resolve
|
||||||
rejecter:(RCTPromiseRejectBlock)reject {
|
rejecter:(RCTPromiseRejectBlock)reject {
|
||||||
|
|
||||||
self.resolve = resolve;
|
self.resolve = resolve;
|
||||||
self.reject = reject;
|
self.reject = reject;
|
||||||
self.options = [NSMutableDictionary dictionaryWithDictionary:self.defaultOptions];
|
self.options = [NSMutableDictionary dictionaryWithDictionary:self.defaultOptions];
|
||||||
@ -120,17 +120,17 @@ RCT_EXPORT_MODULE();
|
|||||||
while (root.presentedViewController != nil) {
|
while (root.presentedViewController != nil) {
|
||||||
root = root.presentedViewController;
|
root = root.presentedViewController;
|
||||||
}
|
}
|
||||||
|
|
||||||
return root;
|
return root;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
resolver:(RCTPromiseResolveBlock)resolve
|
||||||
rejecter:(RCTPromiseRejectBlock)reject) {
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
|
||||||
[self setConfiguration:options resolver:resolve rejecter:reject];
|
[self setConfiguration:options resolver:resolve rejecter:reject];
|
||||||
self.currentSelectionMode = CAMERA;
|
self.currentSelectionMode = CAMERA;
|
||||||
|
|
||||||
#if TARGET_IPHONE_SIMULATOR
|
#if TARGET_IPHONE_SIMULATOR
|
||||||
self.reject(ERROR_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR_KEY, ERROR_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR_MSG, nil);
|
self.reject(ERROR_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR_KEY, ERROR_PICKER_CANNOT_RUN_CAMERA_ON_SIMULATOR_MSG, nil);
|
||||||
return;
|
return;
|
||||||
@ -140,7 +140,7 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
|||||||
self.reject(ERROR_PICKER_NO_CAMERA_PERMISSION_KEY, ERROR_PICKER_NO_CAMERA_PERMISSION_MSG, nil);
|
self.reject(ERROR_PICKER_NO_CAMERA_PERMISSION_KEY, ERROR_PICKER_NO_CAMERA_PERMISSION_MSG, nil);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
|
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
|
||||||
picker.delegate = self;
|
picker.delegate = self;
|
||||||
picker.allowsEditing = NO;
|
picker.allowsEditing = NO;
|
||||||
@ -148,7 +148,7 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
|||||||
if ([[self.options objectForKey:@"useFrontCamera"] boolValue]) {
|
if ([[self.options objectForKey:@"useFrontCamera"] boolValue]) {
|
||||||
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
|
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[self getRootVC] presentViewController:picker animated:YES completion:nil];
|
[[self getRootVC] presentViewController:picker animated:YES completion:nil];
|
||||||
});
|
});
|
||||||
@ -163,13 +163,13 @@ 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];
|
||||||
|
|
||||||
NSDictionary *exif;
|
NSDictionary *exif;
|
||||||
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
||||||
exif = [info objectForKey:UIImagePickerControllerMediaMetadata];
|
exif = [info objectForKey:UIImagePickerControllerMediaMetadata];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self processSingleImagePick:chosenImageT withExif:exif withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"]];
|
[self processSingleImagePick:chosenImageT withExif:exif withViewController:picker withSourceURL:self.croppingFile[@"sourceURL"] withLocalIdentifier:self.croppingFile[@"localIdentifier"] withFilename:self.croppingFile[@"filename"] withCreationDate:self.croppingFile[@"creationDate"] withModificationDate:self.croppingFile[@"modificationDate"]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
|
||||||
@ -181,38 +181,38 @@ RCT_EXPORT_METHOD(openCamera:(NSDictionary *)options
|
|||||||
- (NSString*) getTmpDirectory {
|
- (NSString*) getTmpDirectory {
|
||||||
NSString *TMP_DIRECTORY = @"react-native-image-crop-picker/";
|
NSString *TMP_DIRECTORY = @"react-native-image-crop-picker/";
|
||||||
NSString *tmpFullPath = [NSTemporaryDirectory() stringByAppendingString:TMP_DIRECTORY];
|
NSString *tmpFullPath = [NSTemporaryDirectory() stringByAppendingString:TMP_DIRECTORY];
|
||||||
|
|
||||||
BOOL isDir;
|
BOOL isDir;
|
||||||
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:tmpFullPath isDirectory:&isDir];
|
BOOL exists = [[NSFileManager defaultManager] fileExistsAtPath:tmpFullPath isDirectory:&isDir];
|
||||||
if (!exists) {
|
if (!exists) {
|
||||||
[[NSFileManager defaultManager] createDirectoryAtPath: tmpFullPath
|
[[NSFileManager defaultManager] createDirectoryAtPath: tmpFullPath
|
||||||
withIntermediateDirectories:YES attributes:nil error:nil];
|
withIntermediateDirectories:YES attributes:nil error:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
return tmpFullPath;
|
return tmpFullPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)cleanTmpDirectory {
|
- (BOOL)cleanTmpDirectory {
|
||||||
NSString* tmpDirectoryPath = [self getTmpDirectory];
|
NSString* tmpDirectoryPath = [self getTmpDirectory];
|
||||||
NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpDirectoryPath error:NULL];
|
NSArray* tmpDirectory = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:tmpDirectoryPath error:NULL];
|
||||||
|
|
||||||
for (NSString *file in tmpDirectory) {
|
for (NSString *file in tmpDirectory) {
|
||||||
BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", tmpDirectoryPath, file] error:NULL];
|
BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:[NSString stringWithFormat:@"%@%@", tmpDirectoryPath, file] error:NULL];
|
||||||
|
|
||||||
if (!deleted) {
|
if (!deleted) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
RCT_EXPORT_METHOD(cleanSingle:(NSString *) path
|
RCT_EXPORT_METHOD(cleanSingle:(NSString *) path
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
resolver:(RCTPromiseResolveBlock)resolve
|
||||||
rejecter:(RCTPromiseRejectBlock)reject) {
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
|
||||||
BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
|
BOOL deleted = [[NSFileManager defaultManager] removeItemAtPath:path error:NULL];
|
||||||
|
|
||||||
if (!deleted) {
|
if (!deleted) {
|
||||||
reject(ERROR_CLEANUP_ERROR_KEY, ERROR_CLEANUP_ERROR_MSG, nil);
|
reject(ERROR_CLEANUP_ERROR_KEY, ERROR_CLEANUP_ERROR_MSG, nil);
|
||||||
} else {
|
} else {
|
||||||
@ -232,16 +232,16 @@ RCT_REMAP_METHOD(clean, resolver:(RCTPromiseResolveBlock)resolve
|
|||||||
RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
resolver:(RCTPromiseResolveBlock)resolve
|
||||||
rejecter:(RCTPromiseRejectBlock)reject) {
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
|
||||||
[self setConfiguration:options resolver:resolve rejecter:reject];
|
[self setConfiguration:options resolver:resolve rejecter:reject];
|
||||||
self.currentSelectionMode = PICKER;
|
self.currentSelectionMode = PICKER;
|
||||||
|
|
||||||
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
|
[PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
|
||||||
if (status != PHAuthorizationStatusAuthorized) {
|
if (status != PHAuthorizationStatusAuthorized) {
|
||||||
self.reject(ERROR_PICKER_UNAUTHORIZED_KEY, ERROR_PICKER_UNAUTHORIZED_MSG, nil);
|
self.reject(ERROR_PICKER_UNAUTHORIZED_KEY, ERROR_PICKER_UNAUTHORIZED_MSG, nil);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
// init picker
|
// init picker
|
||||||
QBImagePickerController *imagePickerController =
|
QBImagePickerController *imagePickerController =
|
||||||
@ -251,7 +251,7 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
|||||||
imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]);
|
imagePickerController.minimumNumberOfSelection = abs([[self.options objectForKey:@"minFiles"] intValue]);
|
||||||
imagePickerController.maximumNumberOfSelection = abs([[self.options objectForKey:@"maxFiles"] 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) {
|
||||||
NSDictionary *smartAlbums = @{
|
NSDictionary *smartAlbums = @{
|
||||||
@"UserLibrary" : @(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
|
@"UserLibrary" : @(PHAssetCollectionSubtypeSmartAlbumUserLibrary),
|
||||||
@ -268,12 +268,12 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
|||||||
}
|
}
|
||||||
imagePickerController.assetCollectionSubtypes = albumsToShow;
|
imagePickerController.assetCollectionSubtypes = albumsToShow;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ([[self.options objectForKey:@"cropping"] boolValue]) {
|
if ([[self.options objectForKey:@"cropping"] boolValue]) {
|
||||||
imagePickerController.mediaType = QBImagePickerMediaTypeImage;
|
imagePickerController.mediaType = QBImagePickerMediaTypeImage;
|
||||||
} else {
|
} else {
|
||||||
NSString *mediaType = [self.options objectForKey:@"mediaType"];
|
NSString *mediaType = [self.options objectForKey:@"mediaType"];
|
||||||
|
|
||||||
if ([mediaType isEqualToString:@"any"]) {
|
if ([mediaType isEqualToString:@"any"]) {
|
||||||
imagePickerController.mediaType = QBImagePickerMediaTypeAny;
|
imagePickerController.mediaType = QBImagePickerMediaTypeAny;
|
||||||
} else if ([mediaType isEqualToString:@"photo"]) {
|
} else if ([mediaType isEqualToString:@"photo"]) {
|
||||||
@ -281,9 +281,9 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
|||||||
} else {
|
} else {
|
||||||
imagePickerController.mediaType = QBImagePickerMediaTypeVideo;
|
imagePickerController.mediaType = QBImagePickerMediaTypeVideo;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[[self getRootVC] presentViewController:imagePickerController animated:YES completion:nil];
|
[[self getRootVC] presentViewController:imagePickerController animated:YES completion:nil];
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
@ -292,12 +292,12 @@ RCT_EXPORT_METHOD(openPicker:(NSDictionary *)options
|
|||||||
RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
||||||
resolver:(RCTPromiseResolveBlock)resolve
|
resolver:(RCTPromiseResolveBlock)resolve
|
||||||
rejecter:(RCTPromiseRejectBlock)reject) {
|
rejecter:(RCTPromiseRejectBlock)reject) {
|
||||||
|
|
||||||
[self setConfiguration:options resolver:resolve rejecter:reject];
|
[self setConfiguration:options resolver:resolve rejecter:reject];
|
||||||
self.currentSelectionMode = CROPPING;
|
self.currentSelectionMode = CROPPING;
|
||||||
|
|
||||||
NSString *path = [options objectForKey:@"path"];
|
NSString *path = [options objectForKey:@"path"];
|
||||||
|
|
||||||
[self.bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:path] callback:^(NSError *error, UIImage *image) {
|
[self.bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:path] callback:^(NSError *error, UIImage *image) {
|
||||||
if (error) {
|
if (error) {
|
||||||
self.reject(ERROR_CROPPER_IMAGE_NOT_FOUND_KEY, ERROR_CROPPER_IMAGE_NOT_FOUND_MSG, nil);
|
self.reject(ERROR_CROPPER_IMAGE_NOT_FOUND_KEY, ERROR_CROPPER_IMAGE_NOT_FOUND_MSG, nil);
|
||||||
@ -319,7 +319,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
imageCropVC.delegate = self;
|
imageCropVC.delegate = self;
|
||||||
[imageCropVC setModalPresentationStyle:UIModalPresentationCustom];
|
[imageCropVC setModalPresentationStyle:UIModalPresentationCustom];
|
||||||
[imageCropVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
|
[imageCropVC setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[[self getRootVC] presentViewController:imageCropVC animated:YES completion:nil];
|
[[self getRootVC] presentViewController:imageCropVC animated:YES completion:nil];
|
||||||
});
|
});
|
||||||
@ -328,18 +328,18 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
- (void)showActivityIndicator:(void (^)(UIActivityIndicatorView*, UIView*))handler {
|
- (void)showActivityIndicator:(void (^)(UIActivityIndicatorView*, UIView*))handler {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
UIView *mainView = [[self getRootVC] view];
|
UIView *mainView = [[self getRootVC] view];
|
||||||
|
|
||||||
// create overlay
|
// create overlay
|
||||||
UIView *loadingView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
UIView *loadingView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
|
||||||
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
loadingView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
|
||||||
loadingView.clipsToBounds = YES;
|
loadingView.clipsToBounds = YES;
|
||||||
|
|
||||||
// create loading spinner
|
// create loading spinner
|
||||||
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
UIActivityIndicatorView *activityView = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
|
||||||
activityView.frame = CGRectMake(65, 40, activityView.bounds.size.width, activityView.bounds.size.height);
|
activityView.frame = CGRectMake(65, 40, activityView.bounds.size.width, activityView.bounds.size.height);
|
||||||
activityView.center = loadingView.center;
|
activityView.center = loadingView.center;
|
||||||
[loadingView addSubview:activityView];
|
[loadingView addSubview:activityView];
|
||||||
|
|
||||||
// create message
|
// create message
|
||||||
UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
|
UILabel *loadingLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 115, 130, 22)];
|
||||||
loadingLabel.backgroundColor = [UIColor clearColor];
|
loadingLabel.backgroundColor = [UIColor clearColor];
|
||||||
@ -352,11 +352,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
loadingLabel.text = [self.options objectForKey:@"loadingLabelText"];
|
loadingLabel.text = [self.options objectForKey:@"loadingLabelText"];
|
||||||
[loadingLabel setFont:[UIFont boldSystemFontOfSize:18]];
|
[loadingLabel setFont:[UIFont boldSystemFontOfSize:18]];
|
||||||
[loadingView addSubview:loadingLabel];
|
[loadingView addSubview:loadingLabel];
|
||||||
|
|
||||||
// show all
|
// show all
|
||||||
[mainView addSubview:loadingView];
|
[mainView addSubview:loadingView];
|
||||||
[activityView startAnimating];
|
[activityView startAnimating];
|
||||||
|
|
||||||
handler(activityView, loadingView);
|
handler(activityView, loadingView);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -366,30 +366,30 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
PHImageManager *manager = [PHImageManager defaultManager];
|
PHImageManager *manager = [PHImageManager defaultManager];
|
||||||
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
|
PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
|
||||||
options.version = PHVideoRequestOptionsVersionOriginal;
|
options.version = PHVideoRequestOptionsVersionOriginal;
|
||||||
|
|
||||||
[manager
|
[manager
|
||||||
requestAVAssetForVideo:forAsset
|
requestAVAssetForVideo:forAsset
|
||||||
options:options
|
options:options
|
||||||
resultHandler:^(AVAsset * asset, AVAudioMix * audioMix,
|
resultHandler:^(AVAsset * asset, AVAudioMix * audioMix,
|
||||||
NSDictionary *info) {
|
NSDictionary *info) {
|
||||||
NSURL *sourceURL = [(AVURLAsset *)asset URL];
|
NSURL *sourceURL = [(AVURLAsset *)asset URL];
|
||||||
|
|
||||||
// create temp file
|
// create temp file
|
||||||
NSString *tmpDirFullPath = [self getTmpDirectory];
|
NSString *tmpDirFullPath = [self getTmpDirectory];
|
||||||
NSString *filePath = [tmpDirFullPath stringByAppendingString:[[NSUUID UUID] UUIDString]];
|
NSString *filePath = [tmpDirFullPath stringByAppendingString:[[NSUUID UUID] UUIDString]];
|
||||||
filePath = [filePath stringByAppendingString:@".mp4"];
|
filePath = [filePath stringByAppendingString:@".mp4"];
|
||||||
NSURL *outputURL = [NSURL fileURLWithPath:filePath];
|
NSURL *outputURL = [NSURL fileURLWithPath:filePath];
|
||||||
|
|
||||||
[self.compression compressVideo:sourceURL outputURL:outputURL withOptions:self.options handler:^(AVAssetExportSession *exportSession) {
|
[self.compression compressVideo:sourceURL outputURL:outputURL withOptions:self.options handler:^(AVAssetExportSession *exportSession) {
|
||||||
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
|
if (exportSession.status == AVAssetExportSessionStatusCompleted) {
|
||||||
AVAsset *compressedAsset = [AVAsset assetWithURL:outputURL];
|
AVAsset *compressedAsset = [AVAsset assetWithURL:outputURL];
|
||||||
AVAssetTrack *track = [[compressedAsset tracksWithMediaType:AVMediaTypeVideo] firstObject];
|
AVAssetTrack *track = [[compressedAsset tracksWithMediaType:AVMediaTypeVideo] firstObject];
|
||||||
|
|
||||||
NSNumber *fileSizeValue = nil;
|
NSNumber *fileSizeValue = nil;
|
||||||
[outputURL getResourceValue:&fileSizeValue
|
[outputURL getResourceValue:&fileSizeValue
|
||||||
forKey:NSURLFileSizeKey
|
forKey:NSURLFileSizeKey
|
||||||
error:nil];
|
error:nil];
|
||||||
|
|
||||||
completion([self createAttachmentResponse:[outputURL absoluteString]
|
completion([self createAttachmentResponse:[outputURL absoluteString]
|
||||||
withExif:nil
|
withExif:nil
|
||||||
withSourceURL:[sourceURL absoluteString]
|
withSourceURL:[sourceURL absoluteString]
|
||||||
@ -399,7 +399,10 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withHeight:[NSNumber numberWithFloat:track.naturalSize.height]
|
withHeight:[NSNumber numberWithFloat:track.naturalSize.height]
|
||||||
withMime:@"video/mp4"
|
withMime:@"video/mp4"
|
||||||
withSize:fileSizeValue
|
withSize:fileSizeValue
|
||||||
withData:nil]);
|
withData:nil
|
||||||
|
withCreationDate:forAsset.creationDate
|
||||||
|
withModificationDate:forAsset.modificationDate
|
||||||
|
]);
|
||||||
} else {
|
} else {
|
||||||
completion(nil);
|
completion(nil);
|
||||||
}
|
}
|
||||||
@ -407,7 +410,8 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSDictionary*) createAttachmentResponse:(NSString*)filePath withExif:(NSDictionary*) exif withSourceURL:(NSString*)sourceURL 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 withExif:(NSDictionary*) exif withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withWidth:(NSNumber*)width withHeight:(NSNumber*)height withMime:(NSString*)mime withSize:(NSNumber*)size withData:(NSString*)data withCreationDate:(NSDate*)creationDate withModificationDate:(NSDate*)modificationDate
|
||||||
|
{
|
||||||
return @{
|
return @{
|
||||||
@"path": filePath,
|
@"path": filePath,
|
||||||
@"sourceURL": (sourceURL) ? sourceURL : [NSNull null],
|
@"sourceURL": (sourceURL) ? sourceURL : [NSNull null],
|
||||||
@ -419,32 +423,34 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
@"size": size,
|
@"size": size,
|
||||||
@"data": (data) ? data : [NSNull null],
|
@"data": (data) ? data : [NSNull null],
|
||||||
@"exif": (exif) ? exif : [NSNull null],
|
@"exif": (exif) ? exif : [NSNull null],
|
||||||
|
@"creationDate:": (creationDate) ? [NSString stringWithFormat:@"%.0f", [creationDate timeIntervalSince1970]] : [NSNull null],
|
||||||
|
@"modificationDate": (modificationDate) ? [NSString stringWithFormat:@"%.0f", [modificationDate timeIntervalSince1970]] : [NSNull null],
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)qb_imagePickerController:
|
- (void)qb_imagePickerController:
|
||||||
(QBImagePickerController *)imagePickerController
|
(QBImagePickerController *)imagePickerController
|
||||||
didFinishPickingAssets:(NSArray *)assets {
|
didFinishPickingAssets:(NSArray *)assets {
|
||||||
|
|
||||||
PHImageManager *manager = [PHImageManager defaultManager];
|
PHImageManager *manager = [PHImageManager defaultManager];
|
||||||
PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
|
PHImageRequestOptions* options = [[PHImageRequestOptions alloc] init];
|
||||||
options.synchronous = NO;
|
options.synchronous = NO;
|
||||||
options.networkAccessAllowed = YES;
|
options.networkAccessAllowed = YES;
|
||||||
|
|
||||||
if ([[[self options] objectForKey:@"multiple"] boolValue]) {
|
if ([[[self options] objectForKey:@"multiple"] boolValue]) {
|
||||||
NSMutableArray *selections = [[NSMutableArray alloc] init];
|
NSMutableArray *selections = [[NSMutableArray alloc] init];
|
||||||
|
|
||||||
[self showActivityIndicator:^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
|
[self showActivityIndicator:^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
|
||||||
NSLock *lock = [[NSLock alloc] init];
|
NSLock *lock = [[NSLock alloc] init];
|
||||||
__block int processed = 0;
|
__block int processed = 0;
|
||||||
|
|
||||||
for (PHAsset *phAsset in assets) {
|
for (PHAsset *phAsset in assets) {
|
||||||
|
|
||||||
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
|
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
|
||||||
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
|
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[lock lock];
|
[lock lock];
|
||||||
|
|
||||||
if (video == nil) {
|
if (video == nil) {
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
@ -453,11 +459,11 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}]];
|
}]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
[selections addObject:video];
|
[selections addObject:video];
|
||||||
processed++;
|
processed++;
|
||||||
[lock unlock];
|
[lock unlock];
|
||||||
|
|
||||||
if (processed == [assets count]) {
|
if (processed == [assets count]) {
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
@ -473,18 +479,18 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
requestImageDataForAsset:phAsset
|
requestImageDataForAsset:phAsset
|
||||||
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"];
|
NSURL *sourceURL = [info objectForKey:@"PHImageFileURLKey"];
|
||||||
|
|
||||||
dispatch_async(dispatch_get_main_queue(), ^{
|
dispatch_async(dispatch_get_main_queue(), ^{
|
||||||
[lock lock];
|
[lock lock];
|
||||||
@autoreleasepool {
|
@autoreleasepool {
|
||||||
UIImage *imgT = [UIImage imageWithData:imageData];
|
UIImage *imgT = [UIImage imageWithData:imageData];
|
||||||
UIImage *imageT = [imgT fixOrientation];
|
UIImage *imageT = [imgT fixOrientation];
|
||||||
|
|
||||||
ImageResult *imageResult = [self.compression compressImage:imageT withOptions:self.options];
|
ImageResult *imageResult = [self.compression compressImage:imageT withOptions:self.options];
|
||||||
NSString *filePath = [self persistFile:imageResult.data];
|
NSString *filePath = [self persistFile:imageResult.data];
|
||||||
|
|
||||||
if (filePath == nil) {
|
if (filePath == nil) {
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
@ -493,12 +499,12 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}]];
|
}]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary* exif = nil;
|
NSDictionary* exif = nil;
|
||||||
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
||||||
exif = [[CIImage imageWithData:imageData] properties];
|
exif = [[CIImage imageWithData:imageData] properties];
|
||||||
}
|
}
|
||||||
|
|
||||||
[selections addObject:[self createAttachmentResponse:filePath
|
[selections addObject:[self createAttachmentResponse:filePath
|
||||||
withExif: exif
|
withExif: exif
|
||||||
withSourceURL:[sourceURL absoluteString]
|
withSourceURL:[sourceURL absoluteString]
|
||||||
@ -509,13 +515,15 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0]: nil
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0]: nil
|
||||||
|
withCreationDate:phAsset.creationDate
|
||||||
|
withModificationDate:phAsset.modificationDate
|
||||||
]];
|
]];
|
||||||
}
|
}
|
||||||
processed++;
|
processed++;
|
||||||
[lock unlock];
|
[lock unlock];
|
||||||
|
|
||||||
if (processed == [assets count]) {
|
if (processed == [assets count]) {
|
||||||
|
|
||||||
[indicatorView stopAnimating];
|
[indicatorView stopAnimating];
|
||||||
[overlayView removeFromSuperview];
|
[overlayView removeFromSuperview];
|
||||||
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
[imagePickerController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
||||||
@ -530,7 +538,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}];
|
}];
|
||||||
} else {
|
} else {
|
||||||
PHAsset *phAsset = [assets objectAtIndex:0];
|
PHAsset *phAsset = [assets objectAtIndex:0];
|
||||||
|
|
||||||
[self showActivityIndicator:^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
|
[self showActivityIndicator:^(UIActivityIndicatorView *indicatorView, UIView *overlayView) {
|
||||||
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
|
if (phAsset.mediaType == PHAssetMediaTypeVideo) {
|
||||||
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
|
[self getVideoAsset:phAsset completion:^(NSDictionary* video) {
|
||||||
@ -558,17 +566,19 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
||||||
exif = [[CIImage imageWithData:imageData] properties];
|
exif = [[CIImage imageWithData:imageData] properties];
|
||||||
}
|
}
|
||||||
|
|
||||||
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]
|
[self processSingleImagePick:[UIImage imageWithData:imageData]
|
||||||
withExif: exif
|
withExif: exif
|
||||||
withViewController:imagePickerController
|
withViewController:imagePickerController
|
||||||
withSourceURL:[sourceURL absoluteString]
|
withSourceURL:[sourceURL absoluteString]
|
||||||
withLocalIdentifier:phAsset.localIdentifier
|
withLocalIdentifier:phAsset.localIdentifier
|
||||||
withFilename:[phAsset valueForKey:@"filename"]];
|
withFilename:[phAsset valueForKey:@"filename"]
|
||||||
|
withCreationDate:phAsset.creationDate
|
||||||
|
withModificationDate:phAsset.modificationDate];
|
||||||
});
|
});
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
@ -585,24 +595,26 @@ 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 withExif:(NSDictionary*) exif withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename {
|
- (void) processSingleImagePick:(UIImage*)image withExif:(NSDictionary*) exif withViewController:(UIViewController*)viewController withSourceURL:(NSString*)sourceURL withLocalIdentifier:(NSString*)localIdentifier withFilename:(NSString*)filename withCreationDate:(NSDate*)creationDate withModificationDate:(NSDate*)modificationDate {
|
||||||
|
|
||||||
if (image == nil) {
|
if (image == nil) {
|
||||||
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
||||||
self.reject(ERROR_PICKER_NO_DATA_KEY, ERROR_PICKER_NO_DATA_MSG, nil);
|
self.reject(ERROR_PICKER_NO_DATA_KEY, ERROR_PICKER_NO_DATA_MSG, nil);
|
||||||
}]];
|
}]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSLog(@"id: %@ filename: %@", localIdentifier, filename);
|
NSLog(@"id: %@ filename: %@", localIdentifier, filename);
|
||||||
|
|
||||||
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[@"sourceURL"] = sourceURL;
|
||||||
self.croppingFile[@"localIdentifier"] = localIdentifier;
|
self.croppingFile[@"localIdentifier"] = localIdentifier;
|
||||||
self.croppingFile[@"filename"] = filename;
|
self.croppingFile[@"filename"] = filename;
|
||||||
|
self.croppingFile[@"creationDate"] = creationDate;
|
||||||
|
self.croppingFile[@"modifcationDate"] = modificationDate;
|
||||||
NSLog(@"CroppingFile %@", self.croppingFile);
|
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];
|
||||||
@ -613,7 +625,7 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}]];
|
}]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wait for viewController to dismiss before resolving, or we lose the ability to display
|
// Wait for viewController to dismiss before resolving, or we lose the ability to display
|
||||||
// Alert.alert in the .then() handler.
|
// Alert.alert in the .then() handler.
|
||||||
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
[viewController dismissViewControllerAnimated:YES completion:[self waitAnimationEnd:^{
|
||||||
@ -626,7 +638,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withHeight:imageResult.height
|
withHeight:imageResult.height
|
||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil]);
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil
|
||||||
|
withCreationDate:creationDate
|
||||||
|
withModificationDate:modificationDate]);
|
||||||
}]];
|
}]];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -639,14 +653,14 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
CGSize maskSize = CGSizeMake(
|
CGSize maskSize = CGSizeMake(
|
||||||
[[self.options objectForKey:@"width"] intValue],
|
[[self.options objectForKey:@"width"] intValue],
|
||||||
[[self.options objectForKey:@"height"] intValue]);
|
[[self.options objectForKey:@"height"] intValue]);
|
||||||
|
|
||||||
CGFloat viewWidth = CGRectGetWidth(controller.view.frame);
|
CGFloat viewWidth = CGRectGetWidth(controller.view.frame);
|
||||||
CGFloat viewHeight = CGRectGetHeight(controller.view.frame);
|
CGFloat viewHeight = CGRectGetHeight(controller.view.frame);
|
||||||
|
|
||||||
CGRect maskRect = CGRectMake((viewWidth - maskSize.width) * 0.5f,
|
CGRect maskRect = CGRectMake((viewWidth - maskSize.width) * 0.5f,
|
||||||
(viewHeight - maskSize.height) * 0.5f,
|
(viewHeight - maskSize.height) * 0.5f,
|
||||||
maskSize.width, maskSize.height);
|
maskSize.width, maskSize.height);
|
||||||
|
|
||||||
return maskRect;
|
return maskRect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -656,13 +670,13 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
CGRect rect = controller.maskRect;
|
CGRect rect = controller.maskRect;
|
||||||
CGFloat viewWidth = CGRectGetWidth(controller.view.frame);
|
CGFloat viewWidth = CGRectGetWidth(controller.view.frame);
|
||||||
CGFloat viewHeight = CGRectGetHeight(controller.view.frame);
|
CGFloat viewHeight = CGRectGetHeight(controller.view.frame);
|
||||||
|
|
||||||
double scaleFactor = fmin(viewWidth / rect.size.width, viewHeight / rect.size.height);
|
double scaleFactor = fmin(viewWidth / rect.size.width, viewHeight / rect.size.height);
|
||||||
rect.size.width *= scaleFactor;
|
rect.size.width *= scaleFactor;
|
||||||
rect.size.height *= scaleFactor;
|
rect.size.height *= scaleFactor;
|
||||||
rect.origin.x = (viewWidth - rect.size.width) / 2;
|
rect.origin.x = (viewWidth - rect.size.width) / 2;
|
||||||
rect.origin.y = (viewHeight - rect.size.height) / 2;
|
rect.origin.y = (viewHeight - rect.size.height) / 2;
|
||||||
|
|
||||||
return rect;
|
return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -718,13 +732,13 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
- (void)imageCropViewController:(RSKImageCropViewController *)controller
|
- (void)imageCropViewController:(RSKImageCropViewController *)controller
|
||||||
didCropImage:(UIImage *)croppedImage
|
didCropImage:(UIImage *)croppedImage
|
||||||
usingCropRect:(CGRect)cropRect {
|
usingCropRect:(CGRect)cropRect {
|
||||||
|
|
||||||
// we have correct rect, but not correct dimensions
|
// we have correct rect, but not correct dimensions
|
||||||
// so resize image
|
// so resize image
|
||||||
CGSize resizedImageSize = CGSizeMake([[[self options] objectForKey:@"width"] intValue], [[[self options] objectForKey:@"height"] intValue]);
|
CGSize resizedImageSize = CGSizeMake([[[self options] objectForKey:@"width"] intValue], [[[self options] objectForKey:@"height"] intValue]);
|
||||||
UIImage *resizedImage = [croppedImage resizedImageToFitInSize:resizedImageSize scaleIfSmaller:YES];
|
UIImage *resizedImage = [croppedImage resizedImageToFitInSize:resizedImageSize scaleIfSmaller:YES];
|
||||||
ImageResult *imageResult = [self.compression compressImage:resizedImage withOptions:self.options];
|
ImageResult *imageResult = [self.compression compressImage:resizedImage withOptions:self.options];
|
||||||
|
|
||||||
NSString *filePath = [self persistFile:imageResult.data];
|
NSString *filePath = [self persistFile:imageResult.data];
|
||||||
if (filePath == nil) {
|
if (filePath == nil) {
|
||||||
[self dismissCropper:controller selectionDone:YES completion:[self waitAnimationEnd:^{
|
[self dismissCropper:controller selectionDone:YES completion:[self waitAnimationEnd:^{
|
||||||
@ -732,12 +746,12 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
}]];
|
}]];
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
NSDictionary* exif = nil;
|
NSDictionary* exif = nil;
|
||||||
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
if([[self.options objectForKey:@"includeExif"] boolValue]) {
|
||||||
exif = [[CIImage imageWithData:imageResult.data] properties];
|
exif = [[CIImage imageWithData:imageResult.data] properties];
|
||||||
}
|
}
|
||||||
|
|
||||||
[self dismissCropper:controller selectionDone:YES completion:[self waitAnimationEnd:^{
|
[self dismissCropper:controller selectionDone:YES completion:[self waitAnimationEnd:^{
|
||||||
self.resolve([self createAttachmentResponse:filePath
|
self.resolve([self createAttachmentResponse:filePath
|
||||||
withExif: exif
|
withExif: exif
|
||||||
@ -748,7 +762,9 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
withHeight:imageResult.height
|
withHeight:imageResult.height
|
||||||
withMime:imageResult.mime
|
withMime:imageResult.mime
|
||||||
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
withSize:[NSNumber numberWithUnsignedInteger:imageResult.data.length]
|
||||||
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil]);
|
withData:[[self.options objectForKey:@"includeBase64"] boolValue] ? [imageResult.data base64EncodedStringWithOptions:0] : nil
|
||||||
|
withCreationDate:self.croppingFile[@"creationDate"]
|
||||||
|
withModificationDate:self.croppingFile[@"modificationDate"]]);
|
||||||
}]];
|
}]];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,13 +775,13 @@ RCT_EXPORT_METHOD(openCropper:(NSDictionary *)options
|
|||||||
NSString *tmpDirFullPath = [self getTmpDirectory];
|
NSString *tmpDirFullPath = [self getTmpDirectory];
|
||||||
NSString *filePath = [tmpDirFullPath stringByAppendingString:[[NSUUID UUID] UUIDString]];
|
NSString *filePath = [tmpDirFullPath stringByAppendingString:[[NSUUID UUID] UUIDString]];
|
||||||
filePath = [filePath stringByAppendingString:@".jpg"];
|
filePath = [filePath stringByAppendingString:@".jpg"];
|
||||||
|
|
||||||
// save cropped file
|
// save cropped file
|
||||||
BOOL status = [data writeToFile:filePath atomically:YES];
|
BOOL status = [data writeToFile:filePath atomically:YES];
|
||||||
if (!status) {
|
if (!status) {
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user