Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sourceRect for IOS iPad popover anchor position #166

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions src/ios/SOSPicker.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 10 additions & 2 deletions src/ios/SOSPicker.m
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

#import "SOSPicker.h"


#import "GMImagePickerController.h"
#import "GMFetchItem.h"

Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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];
Expand Down
3 changes: 2 additions & 1 deletion www/imagepicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down