From 857d657781f98a047d363afcf10159beb4ac713e Mon Sep 17 00:00:00 2001 From: TaDaa Date: Tue, 17 Sep 2019 12:39:11 -0400 Subject: [PATCH 1/2] Implement sourceRect for popover anchor/arrow position --- README.md | 7 ++++++- src/ios/SOSPicker.h | 1 + src/ios/SOSPicker.m | 12 ++++++++++-- www/imagepicker.js | 6 +++++- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 9612d299..099f2131 100644 --- a/README.md +++ b/README.md @@ -73,7 +73,12 @@ window.imagePicker.getPictures( // available options are // window.imagePicker.OutputType.FILE_URI (0) or // window.imagePicker.OutputType.BASE64_STRING (1) - outputType: int + outputType: int, + + // sourceRect, defaults to {x: 0, y: 0, width: 0, height: 0} + // sets the popover arrow anchor position + // IOS only + sourceRect: {x: int, y: int, width: int, height: int} }; ### Note for Android Use diff --git a/src/ios/SOSPicker.h b/src/ios/SOSPicker.h index 6c9894ab..47797956 100644 --- a/src/ios/SOSPicker.h +++ b/src/ios/SOSPicker.h @@ -23,5 +23,6 @@ @property (nonatomic, assign) NSInteger height; @property (nonatomic, assign) NSInteger quality; @property (nonatomic, assign) NSInteger outputType; +@property (nonatomic, assign) CGRect sourceRect; @end diff --git a/src/ios/SOSPicker.m b/src/ios/SOSPicker.m index 0e2e00e7..4a680b4d 100644 --- a/src/ios/SOSPicker.m +++ b/src/ios/SOSPicker.m @@ -8,7 +8,6 @@ #import "SOSPicker.h" - #import "GMImagePickerController.h" #import "GMFetchItem.h" @@ -67,6 +66,15 @@ - (void) getPictures:(CDVInvokedUrlCommand *)command { NSDictionary *options = [command.arguments objectAtIndex: 0]; + NSDictionary * sourceRect = [options objectForKey:@"sourceRect"]; + + self.sourceRect = CGRectMake( + (int)[[sourceRect objectForKey:@"x"] integerValue], + (int)[[sourceRect objectForKey:@"y"] integerValue], + (int)[[sourceRect objectForKey:@"width"] integerValue], + (int)[[sourceRect objectForKey:@"height"] integerValue] + ); + self.outputType = [[options objectForKey:@"outputType"] integerValue]; BOOL allow_video = [[options objectForKey:@"allow_video" ] boolValue ]; NSInteger maximumImagesCount = [[options objectForKey:@"maximumImagesCount"] integerValue]; @@ -101,7 +109,7 @@ - (void)launchGMImagePicker:(bool)allow_video title:(NSString *)title message:(N UIPopoverPresentationController *popPC = picker.popoverPresentationController; popPC.permittedArrowDirections = UIPopoverArrowDirectionAny; popPC.sourceView = picker.view; - //popPC.sourceRect = nil; + popPC.sourceRect = self.sourceRect; } [self.viewController showViewController:picker sender:nil]; diff --git a/www/imagepicker.js b/www/imagepicker.js index 4dd3650c..fa4a38a9 100644 --- a/www/imagepicker.js +++ b/www/imagepicker.js @@ -1,3 +1,4 @@ +cordova.define("cordova-plugin-telerik-imagepicker.ImagePicker", function(require, exports, module) { /*global cordova,window,console*/ /** * An Image Picker plugin for Cordova @@ -62,10 +63,13 @@ ImagePicker.prototype.getPictures = function(success, fail, options) { title: options.title ? options.title : 'Select an Album', // the default is the message of the old plugin impl message: options.message ? options.message : null, // the old plugin impl didn't have it, so passing null by default outputType: options.outputType ? options.outputType : this.OutputType.FILE_URI, - disable_popover: options.disable_popover ? options.disable_popover : false // Disable the iOS popover as seen on iPad + disable_popover: options.disable_popover ? options.disable_popover : false, // Disable the iOS popover as seen on iPad + sourceRect: {x: options.sourceRect && options.sourceRect.x || 0, y: options.sourceRect && options.sourceRect.y || 0, width: options.sourceRect && options.sourceRect.width || 0, height: options.sourceRect && options.sourceRect.height || 0} }; return cordova.exec(success, fail, "ImagePicker", "getPictures", [params]); }; window.imagePicker = new ImagePicker(); + +}); From 26259454e2c9a280bad52927d4ccfe0b1488dda8 Mon Sep 17 00:00:00 2001 From: TaDaa Date: Tue, 17 Sep 2019 14:28:32 -0400 Subject: [PATCH 2/2] Remove define wrapped --- www/imagepicker.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/www/imagepicker.js b/www/imagepicker.js index fa4a38a9..9a3840e6 100644 --- a/www/imagepicker.js +++ b/www/imagepicker.js @@ -1,4 +1,3 @@ -cordova.define("cordova-plugin-telerik-imagepicker.ImagePicker", function(require, exports, module) { /*global cordova,window,console*/ /** * An Image Picker plugin for Cordova @@ -71,5 +70,3 @@ ImagePicker.prototype.getPictures = function(success, fail, options) { }; window.imagePicker = new ImagePicker(); - -});