From cd72047dfc60175fe6ddf158b1094a8ca09871b8 Mon Sep 17 00:00:00 2001 From: Ams Date: Sun, 25 Nov 2018 13:59:51 +0100 Subject: [PATCH] CB-13865: (IOS-Ipad) Making popover Window Size configurable using popoverOptions - imagePicker (#314) --- README.md | 6 ++++-- src/ios/CDVCamera.m | 13 +++++++++++++ .../CDVCameraTest/CDVCameraLibTests/CameraTest.m | 4 ++-- tests/ios/package.json | 2 +- tests/tests.js | 2 +- types/index.d.ts | 2 ++ www/CameraPopoverOptions.js | 6 +++++- www/ios/CameraPopoverHandle.js | 4 ++-- 8 files changed, 30 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 57d9a83..6c55069 100644 --- a/README.md +++ b/README.md @@ -382,6 +382,8 @@ location. | [width] | Number | 320 | width, in pixels, of the screen element onto which to anchor the popover. | | [height] | Number | 480 | height, in pixels, of the screen element onto which to anchor the popover. | | [arrowDir] | [PopoverArrowDirection](#module_Camera.PopoverArrowDirection) | ARROW_ANY | Direction the arrow on the popover should point. | +| [popoverWidth] | Number | 0 | width of the popover (0 or not specified will use apple's default width). | +| [popoverHeight] | Number | 0 | height of the popover (0 or not specified will use apple's default height). | --- @@ -400,13 +402,13 @@ navigator.camera.getPicture(onSuccess, onFail, { destinationType: Camera.DestinationType.FILE_URI, sourceType: Camera.PictureSourceType.PHOTOLIBRARY, - popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY) + popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY, 300, 600) }); // Reposition the popover if the orientation changes. window.onorientationchange = function() { var cameraPopoverHandle = new CameraPopoverHandle(); - var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY); + var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY, 400, 500); cameraPopoverHandle.setPosition(cameraPopoverOptions); } ``` diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index c71de05..6e39d23 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -291,6 +291,19 @@ static NSString* toBase64(NSData* data) { - (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { if([navigationController isKindOfClass:[UIImagePickerController class]]){ + + // If popoverWidth and popoverHeight are specified and are greater than 0, then set popover size, else use apple's default popoverSize + NSDictionary* options = self.pickerController.pictureOptions.popoverOptions; + if(options) { + NSInteger popoverWidth = [self integerValueForKey:options key:@"popoverWidth" defaultValue:0]; + NSInteger popoverHeight = [self integerValueForKey:options key:@"popoverHeight" defaultValue:0]; + if(popoverWidth > 0 && popoverHeight > 0) + { + [viewController setPreferredContentSize:CGSizeMake(popoverWidth,popoverHeight)]; + } + } + + UIImagePickerController* cameraPicker = (UIImagePickerController*)navigationController; if(![cameraPicker.mediaTypes containsObject:(NSString*)kUTTypeImage]){ diff --git a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m index b9439d1..d74cdba 100644 --- a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m +++ b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m @@ -82,7 +82,7 @@ XCTAssertEqual(options.usesGeolocation, NO); // Set each argument, check whether they are set. different from defaults - popoverOptions = @{ @"x" : @1, @"y" : @2, @"width" : @3, @"height" : @4 }; + popoverOptions = @{ @"x" : @1, @"y" : @2, @"width" : @3, @"height" : @4, @"popoverWidth": @200, @"popoverHeight": @300 }; args = @[ @(49), @@ -127,7 +127,7 @@ // Souce is Camera, and image type - popoverOptions = @{ @"x" : @1, @"y" : @2, @"width" : @3, @"height" : @4 }; + popoverOptions = @{ @"x" : @1, @"y" : @2, @"width" : @3, @"height" : @4, @"popoverWidth": @200, @"popoverHeight": @300 }; args = @[ @(49), @(DestinationTypeDataUrl), diff --git a/tests/ios/package.json b/tests/ios/package.json index 4b9486f..3905303 100644 --- a/tests/ios/package.json +++ b/tests/ios/package.json @@ -8,6 +8,6 @@ "cordova-ios": "*" }, "scripts": { - "test": "xcodebuild -scheme CordovaLib && xcodebuild test -scheme CDVCameraLibTests -destination 'platform=iOS Simulator,name=iPhone 5'" + "test": "xcodebuild -scheme CordovaLib && xcodebuild test -scheme CDVCameraLibTests -destination 'platform=iOS Simulator,name=iPhone 5s'" } } diff --git a/tests/tests.js b/tests/tests.js index f45b8b6..e4425d4 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -162,7 +162,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { // Reposition the popover if the orientation changes. window.onorientationchange = function () { - var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0); + var newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0, 300, 400); popoverHandle.setPosition(newPopoverOptions); }; } diff --git a/types/index.d.ts b/types/index.d.ts index 0ab7305..d747ee0 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -136,6 +136,8 @@ interface CameraPopoverOptions { * ARROW_ANY : 15 */ arrowDir : number; + popoverWidth: number; + popoverHeight: number; } declare class CameraPopoverOptions implements CameraPopoverOptions { diff --git a/www/CameraPopoverOptions.js b/www/CameraPopoverOptions.js index 14829fd..95ff43f 100644 --- a/www/CameraPopoverOptions.js +++ b/www/CameraPopoverOptions.js @@ -39,14 +39,18 @@ var Camera = require('./Camera'); * @param {Number} [width=320] - width, in pixels, of the screen element onto which to anchor the popover. * @param {Number} [height=480] - height, in pixels, of the screen element onto which to anchor the popover. * @param {module:Camera.PopoverArrowDirection} [arrowDir=ARROW_ANY] - Direction the arrow on the popover should point. + * @param {Number} [popoverWidth=0] - width of the popover (0 or not specified will use apple's default width). + * @param {Number} [popoverHeight=0] - height of the popover (0 or not specified will use apple's default height). */ -var CameraPopoverOptions = function (x, y, width, height, arrowDir) { +var CameraPopoverOptions = function (x, y, width, height, arrowDir, popoverWidth, popoverHeight) { // information of rectangle that popover should be anchored to this.x = x || 0; this.y = y || 32; this.width = width || 320; this.height = height || 480; this.arrowDir = arrowDir || Camera.PopoverArrowDirection.ARROW_ANY; + this.popoverWidth = popoverWidth || 0; + this.popoverHeight = popoverHeight || 0; }; module.exports = CameraPopoverOptions; diff --git a/www/ios/CameraPopoverHandle.js b/www/ios/CameraPopoverHandle.js index 6912a4e..30728d1 100644 --- a/www/ios/CameraPopoverHandle.js +++ b/www/ios/CameraPopoverHandle.js @@ -37,13 +37,13 @@ var exec = require('cordova/exec'); * { * destinationType: Camera.DestinationType.FILE_URI, * sourceType: Camera.PictureSourceType.PHOTOLIBRARY, - * popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY) + * popoverOptions: new CameraPopoverOptions(300, 300, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY, 300, 600) * }); * * // Reposition the popover if the orientation changes. * window.onorientationchange = function() { * var cameraPopoverHandle = new CameraPopoverHandle(); - * var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY); + * var cameraPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, Camera.PopoverArrowDirection.ARROW_ANY, 400, 500); * cameraPopoverHandle.setPosition(cameraPopoverOptions); * } * @module CameraPopoverHandle