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..9a3840e6 100644 --- a/www/imagepicker.js +++ b/www/imagepicker.js @@ -62,7 +62,8 @@ 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]);