This is an automated email from the ASF dual-hosted git repository. manuelbeck pushed a commit to branch pr-ipados-remove-popover-code in repository https://gitbox.apache.org/repos/asf/cordova-plugin-camera.git
commit 29a8bf917d15599118f3ce243013d54122d00e3a Author: Manuel Beck <[email protected]> AuthorDate: Tue Jan 13 09:51:36 2026 +0100 fix(ios): remove iPadOS popover code - On iPadOS it was possible to configure a popover for setting the position, width and arrow position of the popover. The code used the deprecated `UIPopoverController`, which would have to be fixed. To keep the plugin also maintainable, this was removed. - The popover could repositioned with a `CameraPopoverHandle` on a `window.onorientationchange`. This was removed also. - Removed documentation for popover from `README.md` --- README.md | 77 +----------- plugin.xml | 12 -- src/ios/CDVCamera.h | 6 - src/ios/CDVCamera.m | 129 +++------------------ .../CDVCameraTest/CDVCameraLibTests/CameraTest.m | 20 +--- tests/tests.js | 10 +- types/index.d.ts | 53 --------- www/Camera.js | 13 +-- www/CameraConstants.js | 11 -- www/CameraPopoverHandle.js | 32 ----- www/CameraPopoverOptions.js | 56 --------- www/ios/CameraPopoverHandle.js | 66 ----------- 12 files changed, 27 insertions(+), 458 deletions(-) diff --git a/README.md b/README.md index ddf0dff..1eba25f 100644 --- a/README.md +++ b/README.md @@ -118,12 +118,8 @@ To add these entries into the `info.plist`, you can use the `edit-config` tag in * [.EncodingType](#module_Camera.EncodingType) : <code>enum</code> * [.MediaType](#module_Camera.MediaType) : <code>enum</code> * [.PictureSourceType](#module_Camera.PictureSourceType) : <code>enum</code> - * [.PopoverArrowDirection](#module_Camera.PopoverArrowDirection) : <code>enum</code> * [.Direction](#module_Camera.Direction) : <code>enum</code> -* [CameraPopoverHandle](#module_CameraPopoverHandle) -* [CameraPopoverOptions](#module_CameraPopoverOptions) - --- <a name="module_camera"></a> @@ -312,7 +308,6 @@ Optional parameters to customize the camera settings. | mediaType | <code>[MediaType](#module_Camera.MediaType)</code> | <code>PICTURE</code> | Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`. | | correctOrientation | <code>Boolean</code> | | Rotate the image to correct for the orientation of the device during capture. | | saveToPhotoAlbum | <code>Boolean</code> | | Save the image to the photo album on the device after capture.<br />See [Android Quirks](#cameragetpicturesuccesscallback-errorcallback-options). | -| popoverOptions | <code>[CameraPopoverOptions](#module_CameraPopoverOptions)</code> | | iOS-only options that specify popover location in iPad. | | cameraDirection | <code>[Direction](#module_Camera.Direction)</code> | <code>BACK</code> | Choose the camera to use (front- or back-facing). | --- @@ -370,24 +365,6 @@ Defines the output format of `Camera.getPicture` call. | CAMERA | <code>number</code> | <code>1</code> | Take picture from camera | | SAVEDPHOTOALBUM | <code>number</code> | <code>2</code> | Same as `PHOTOLIBRARY`, when running on Android or iOS 14+. On iOS older than 14, an image can only be chosen from the device's Camera Roll album with this setting. | - - -<a name="module_Camera.PopoverArrowDirection"></a> - -### Camera.PopoverArrowDirection : <code>enum</code> -Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover. - -**Kind**: static enum property of <code>[Camera](#module_Camera)</code> -**Properties** - -| Name | Type | Default | -| --- | --- | --- | -| ARROW_UP | <code>number</code> | <code>1</code> | -| ARROW_DOWN | <code>number</code> | <code>2</code> | -| ARROW_LEFT | <code>number</code> | <code>4</code> | -| ARROW_RIGHT | <code>number</code> | <code>8</code> | -| ARROW_ANY | <code>number</code> | <code>15</code> | - <a name="module_Camera.Direction"></a> ### Camera.Direction : <code>enum</code> @@ -401,58 +378,6 @@ Matches iOS UIPopoverArrowDirection constants to specify arrow location on popov --- -<a name="module_CameraPopoverOptions"></a> - -## CameraPopoverOptions -iOS-only parameters that specify the anchor element location and arrow -direction of the popover when selecting images from an iPad's library -or album. -Note that the size of the popover may change to adjust to the -direction of the arrow and orientation of the screen. Make sure to -account for orientation changes when specifying the anchor element -location. - - -| Param | Type | Default | Description | -| --- | --- | --- | --- | -| [x] | <code>Number</code> | <code>0</code> | x pixel coordinate of screen element onto which to anchor the popover. | -| [y] | <code>Number</code> | <code>32</code> | y pixel coordinate of screen element onto which to anchor the popover. | -| [width] | <code>Number</code> | <code>320</code> | width, in pixels, of the screen element onto which to anchor the popover. | -| [height] | <code>Number</code> | <code>480</code> | height, in pixels, of the screen element onto which to anchor the popover. | -| [arrowDir] | <code>[PopoverArrowDirection](#module_Camera.PopoverArrowDirection)</code> | <code>ARROW_ANY</code> | Direction the arrow on the popover should point. | -| [popoverWidth] | <code>Number</code> | <code>0</code> | width of the popover (0 or not specified will use apple's default width). | -| [popoverHeight] | <code>Number</code> | <code>0</code> | height of the popover (0 or not specified will use apple's default height). | - ---- - -<a name="module_CameraPopoverHandle"></a> - -## CameraPopoverHandle -A handle to an image picker popover. - -__Supported Platforms__ - -- iOS - -**Example** -```js -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, 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, 400, 500); - cameraPopoverHandle.setPosition(cameraPopoverOptions); -} -``` ---- - - ## `camera.getPicture` Errata #### Example <a name="camera-getPicture-examples"></a> @@ -525,7 +450,7 @@ Can only return photos as data URI image. Including a JavaScript `alert()` in either of the callback functions can cause problems. Wrap the alert within a `setTimeout()` to allow -the iOS image picker or popover to fully close before the alert +the iOS image picker to fully close before the alert displays: ```javascript diff --git a/plugin.xml b/plugin.xml index acfc9ff..b0ac236 100644 --- a/plugin.xml +++ b/plugin.xml @@ -39,10 +39,6 @@ <clobbers target="Camera" /> </js-module> - <js-module src="www/CameraPopoverOptions.js" name="CameraPopoverOptions"> - <clobbers target="CameraPopoverOptions" /> - </js-module> - <js-module src="www/Camera.js" name="camera"> <clobbers target="navigator.camera" /> </js-module> @@ -91,10 +87,6 @@ <preference name="ANDROIDX_CORE_VERSION" default="1.6.+"/> <framework src="androidx.core:core:$ANDROIDX_CORE_VERSION" /> - - <js-module src="www/CameraPopoverHandle.js" name="CameraPopoverHandle"> - <clobbers target="CameraPopoverHandle" /> - </js-module> </platform> <!-- ios --> @@ -106,10 +98,6 @@ <preference name="CameraUsesGeolocation" value="false" /> </config-file> - <js-module src="www/ios/CameraPopoverHandle.js" name="CameraPopoverHandle"> - <clobbers target="CameraPopoverHandle" /> - </js-module> - <header-file src="src/ios/UIImage+CropScaleOrientation.h" /> <source-file src="src/ios/UIImage+CropScaleOrientation.m" /> <header-file src="src/ios/CDVCamera.h" /> diff --git a/src/ios/CDVCamera.h b/src/ios/CDVCamera.h index 1bbc167..37f4fcf 100644 --- a/src/ios/CDVCamera.h +++ b/src/ios/CDVCamera.h @@ -72,10 +72,8 @@ typedef NSUInteger CDVMediaType; @property (assign) BOOL allowsEditing; @property (assign) BOOL correctOrientation; @property (assign) BOOL saveToPhotoAlbum; -@property (strong) NSDictionary* popoverOptions; @property (assign) UIImagePickerControllerCameraDevice cameraDirection; -@property (assign) BOOL popoverSupported; @property (assign) BOOL usesGeolocation; @property (assign) BOOL cropToSize; @@ -89,7 +87,6 @@ typedef NSUInteger CDVMediaType; @property (copy) NSString* callbackId; @property (copy) NSString* postUrl; -@property (strong) UIPopoverController* pickerPopoverController; @property (assign) BOOL cropToSize; @property (strong) UIView* webView; @@ -103,14 +100,12 @@ typedef NSUInteger CDVMediaType; #if __IPHONE_OS_VERSION_MAX_ALLOWED >= 140000 // Always true on XCode12+ @interface CDVCamera : CDVPlugin <UIImagePickerControllerDelegate, UINavigationControllerDelegate, - UIPopoverControllerDelegate, CLLocationManagerDelegate, PHPickerViewControllerDelegate> {} #else @interface CDVCamera : CDVPlugin <UIImagePickerControllerDelegate, UINavigationControllerDelegate, - UIPopoverControllerDelegate, CLLocationManagerDelegate> {} #endif @@ -122,7 +117,6 @@ typedef NSUInteger CDVMediaType; - (void)takePicture:(CDVInvokedUrlCommand*)command; - (void)cleanup:(CDVInvokedUrlCommand*)command; -- (void)repositionPopover:(CDVInvokedUrlCommand*)command; // UIImagePickerControllerDelegate methods - (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info; diff --git a/src/ios/CDVCamera.m b/src/ios/CDVCamera.m index d1c417d..17e862e 100644 --- a/src/ios/CDVCamera.m +++ b/src/ios/CDVCamera.m @@ -84,10 +84,8 @@ static NSString* MIME_JPEG = @"image/jpeg"; pictureOptions.allowsEditing = [[command argumentAtIndex:7 withDefault:@(NO)] boolValue]; pictureOptions.correctOrientation = [[command argumentAtIndex:8 withDefault:@(NO)] boolValue]; pictureOptions.saveToPhotoAlbum = [[command argumentAtIndex:9 withDefault:@(NO)] boolValue]; - pictureOptions.popoverOptions = [command argumentAtIndex:10 withDefault:nil]; pictureOptions.cameraDirection = [[command argumentAtIndex:11 withDefault:@(UIImagePickerControllerCameraDeviceRear)] unsignedIntegerValue]; - pictureOptions.popoverSupported = NO; pictureOptions.usesGeolocation = NO; return pictureOptions; @@ -104,11 +102,6 @@ static NSString* MIME_JPEG = @"image/jpeg"; @implementation CDVCamera -+ (void)initialize -{ - org_apache_cordova_validArrowDirections = [[NSSet alloc] initWithObjects:[NSNumber numberWithInt:UIPopoverArrowDirectionUp], [NSNumber numberWithInt:UIPopoverArrowDirectionDown], [NSNumber numberWithInt:UIPopoverArrowDirectionLeft], [NSNumber numberWithInt:UIPopoverArrowDirectionRight], [NSNumber numberWithInt:UIPopoverArrowDirectionAny], nil]; -} - @synthesize hasPendingOperation, pickerController, locationManager; - (NSURL*)urlTransformer:(NSURL*)url @@ -135,12 +128,6 @@ static NSString* MIME_JPEG = @"image/jpeg"; return [(NSNumber*)useGeo boolValue]; } -- (BOOL)popoverSupported -{ - return (NSClassFromString(@"UIPopoverController") != nil) && - (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad); -} - /** Called by JS function navigator.camera.getPicture(cameraSuccess, cameraError, cameraOptions) which will invoke the camera or photo picker to capture or select an image or video. @@ -156,7 +143,7 @@ static NSString* MIME_JPEG = @"image/jpeg"; - index 7 (allowsEditing): NSNumber(BOOL). Allow user to crop/edit. Default: NO. - index 8 (correctOrientation): NSNumber(BOOL). Fix EXIF orientation. Default: NO. - index 9 (saveToPhotoAlbum): NSNumber(BOOL). Save captured image to Photos. Default: NO. - - index 10 (popoverOptions): NSDictionary (iPad only). Popover positioning and sizing. + - index 10 (popoverOptions): NSDictionary (iPad only). Popover positioning and sizing. - Not used anymore - index 11 (cameraDirection): NSNumber (UIImagePickerControllerCameraDevice). Front/Rear. Default: Rear. @discussion @@ -171,7 +158,6 @@ static NSString* MIME_JPEG = @"image/jpeg"; [self.commandDelegate runInBackground:^{ CDVPictureOptions* pictureOptions = [CDVPictureOptions createFromTakePictureArguments:command]; - pictureOptions.popoverSupported = [weakSelf popoverSupported]; pictureOptions.usesGeolocation = [weakSelf usesGeolocation]; pictureOptions.cropToSize = NO; @@ -279,12 +265,11 @@ static NSString* MIME_JPEG = @"image/jpeg"; - Ensures presentation occurs on the main thread. Behavior: - - Dismisses any visible popover before presenting a new picker (iPad). - - Configures delegates, media types, and popover presentation as needed. + - Configures delegates and media types - Updates `hasPendingOperation` to reflect plugin activity state. @param callbackId The Cordova callback identifier used to deliver results back to JavaScript. - @param pictureOptions Parsed camera options (sourceType, mediaType, allowsEditing, popoverOptions, etc.). + @param pictureOptions Parsed camera options (sourceType, mediaType, allowsEditing, etc.). */ - (void)showCameraPicker:(NSString*)callbackId withOptions:(CDVPictureOptions*)pictureOptions { @@ -309,28 +294,12 @@ static NSString* MIME_JPEG = @"image/jpeg"; cameraPicker.callbackId = callbackId; // we need to capture this state for memory warnings that dealloc this object cameraPicker.webView = self.webView; - - // If a popover is already open, close it; we only want one at a time. - if (([[self pickerController] pickerPopoverController] != nil) && [[[self pickerController] pickerPopoverController] isPopoverVisible]) { - [[[self pickerController] pickerPopoverController] dismissPopoverAnimated:YES]; - [[[self pickerController] pickerPopoverController] setDelegate:nil]; - [[self pickerController] setPickerPopoverController:nil]; - } - - if ([self popoverSupported] && (pictureOptions.sourceType != UIImagePickerControllerSourceTypeCamera)) { - if (cameraPicker.pickerPopoverController == nil) { - cameraPicker.pickerPopoverController = [[NSClassFromString(@"UIPopoverController") alloc] initWithContentViewController:cameraPicker]; - } - [self displayPopover:pictureOptions.popoverOptions]; + cameraPicker.modalPresentationStyle = UIModalPresentationCurrentContext; + [self.viewController presentViewController:cameraPicker + animated:YES + completion:^{ self.hasPendingOperation = NO; - } else { - cameraPicker.modalPresentationStyle = UIModalPresentationCurrentContext; - [self.viewController presentViewController:cameraPicker - animated:YES - completion:^{ - self.hasPendingOperation = NO; - }]; - } + }]; }); } @@ -526,17 +495,6 @@ static NSString* MIME_JPEG = @"image/jpeg"; } #endif -- (void)repositionPopover:(CDVInvokedUrlCommand*)command -{ - if (([[self pickerController] pickerPopoverController] != nil) && [[[self pickerController] pickerPopoverController] isPopoverVisible]) { - - [[[self pickerController] pickerPopoverController] dismissPopoverAnimated:NO]; - - NSDictionary* options = [command argumentAtIndex:0 withDefault:nil]; - [self displayPopover:options]; - } -} - - (NSInteger)integerValueForKey:(NSDictionary*)dict key:(NSString*)key defaultValue:(NSInteger)defaultValue { NSInteger value = defaultValue; @@ -549,55 +507,18 @@ static NSString* MIME_JPEG = @"image/jpeg"; return value; } -- (void)displayPopover:(NSDictionary*)options -{ - NSInteger x = 0; - NSInteger y = 32; - NSInteger width = 320; - NSInteger height = 480; - UIPopoverArrowDirection arrowDirection = UIPopoverArrowDirectionAny; - - if (options) { - x = [self integerValueForKey:options key:@"x" defaultValue:0]; - y = [self integerValueForKey:options key:@"y" defaultValue:32]; - width = [self integerValueForKey:options key:@"width" defaultValue:320]; - height = [self integerValueForKey:options key:@"height" defaultValue:480]; - arrowDirection = [self integerValueForKey:options key:@"arrowDir" defaultValue:UIPopoverArrowDirectionAny]; - if (![org_apache_cordova_validArrowDirections containsObject:[NSNumber numberWithUnsignedInteger:arrowDirection]]) { - arrowDirection = UIPopoverArrowDirectionAny; - } - } - - [[[self pickerController] pickerPopoverController] setDelegate:self]; - [[[self pickerController] pickerPopoverController] presentPopoverFromRect:CGRectMake(x, y, width, height) - inView:[self.webView superview] - permittedArrowDirections:arrowDirection - animated:YES]; -} - // UINavigationControllerDelegate method - (void)navigationController:(UINavigationController*)navigationController willShowViewController:(UIViewController*)viewController animated:(BOOL)animated { + // Backward compatibility for iOS < 14 + // Set title "Videos", when picking videos with the legacy UIImagePickerController 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* imagePicker = (UIImagePickerController*)navigationController; + UIImagePickerController* imagePickerController = (UIImagePickerController*)navigationController; - // Set "Videos" title if mediaType is not for images - if(![imagePicker.mediaTypes containsObject:(NSString*)kUTTypeImage]) { + // Set title "Videos" when picking not images + if(![imagePickerController.mediaTypes containsObject:(NSString*)kUTTypeImage]) { [viewController.navigationItem setTitle:NSLocalizedString(@"Videos", nil)]; } } @@ -638,21 +559,6 @@ static NSString* MIME_JPEG = @"image/jpeg"; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } -- (void)popoverControllerDidDismissPopover:(id)popoverController -{ - UIPopoverController* pc = (UIPopoverController*)popoverController; - - [pc dismissPopoverAnimated:YES]; - pc.delegate = nil; - if (self.pickerController && self.pickerController.callbackId && self.pickerController.pickerPopoverController) { - self.pickerController.pickerPopoverController = nil; - NSString* callbackId = self.pickerController.callbackId; - CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsString:@"no image selected"]; // error callback expects string ATM - [self.commandDelegate sendPluginResult:result callbackId:callbackId]; - } - self.hasPendingOperation = NO; -} - - (NSString*)getMimeForEncoding:(CDVEncodingType)encoding { switch (encoding) { @@ -1007,14 +913,7 @@ static NSString* MIME_JPEG = @"image/jpeg"; } }; - if (cameraPicker.pictureOptions.popoverSupported && (cameraPicker.pickerPopoverController != nil)) { - [cameraPicker.pickerPopoverController dismissPopoverAnimated:YES]; - cameraPicker.pickerPopoverController.delegate = nil; - cameraPicker.pickerPopoverController = nil; - invoke(); - } else { - [[cameraPicker presentingViewController] dismissViewControllerAnimated:YES completion:invoke]; - } + [[cameraPicker presentingViewController] dismissViewControllerAnimated:YES completion:invoke]; } // older api calls newer didFinishPickingMediaWithInfo diff --git a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m index 13a71ad..a2a00c7 100644 --- a/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m +++ b/tests/ios/CDVCameraTest/CDVCameraLibTests/CameraTest.m @@ -61,7 +61,6 @@ { NSArray* args; CDVPictureOptions* options; - NSDictionary* popoverOptions; // No arguments, check whether the defaults are set args = @[]; @@ -79,14 +78,10 @@ XCTAssertEqual(options.allowsEditing, NO); XCTAssertEqual(options.correctOrientation, NO); XCTAssertEqual(options.saveToPhotoAlbum, NO); - XCTAssertEqualObjects(options.popoverOptions, nil); XCTAssertEqual(options.cameraDirection, (int)UIImagePickerControllerCameraDeviceRear); - XCTAssertEqual(options.popoverSupported, NO); XCTAssertEqual(options.usesGeolocation, NO); // Set each argument, check whether they are set. different from defaults - popoverOptions = @{ @"x" : @1, @"y" : @2, @"width" : @3, @"height" : @4, @"popoverWidth": @200, @"popoverHeight": @300 }; - args = @[ @(49), @(DestinationTypeDataUrl), @@ -98,7 +93,7 @@ @YES, @YES, @YES, - popoverOptions, + nil, // popoverOptions - iPadOS only, not used anymore @(UIImagePickerControllerCameraDeviceFront), ]; @@ -115,22 +110,17 @@ XCTAssertEqual(options.allowsEditing, YES); XCTAssertEqual(options.correctOrientation, YES); XCTAssertEqual(options.saveToPhotoAlbum, YES); - XCTAssertEqualObjects(options.popoverOptions, popoverOptions); XCTAssertEqual(options.cameraDirection, (int)UIImagePickerControllerCameraDeviceFront); - XCTAssertEqual(options.popoverSupported, NO); XCTAssertEqual(options.usesGeolocation, NO); } - (void)testCameraPickerCreate { - NSDictionary* popoverOptions; NSArray* args; CDVPictureOptions* pictureOptions; CDVCameraPicker* picker; - // Source is Camera, and image type - Camera always uses UIImagePickerController - - popoverOptions = @{ @"x" : @1, @"y" : @2, @"width" : @3, @"height" : @4, @"popoverWidth": @200, @"popoverHeight": @300 }; + // Source is Camera, uses always UIImagePickerController args = @[ @(49), @(DestinationTypeDataUrl), @@ -142,7 +132,7 @@ @YES, @YES, @YES, - popoverOptions, + nil, // popoverOptions - iPadOS only, not used anymore @(UIImagePickerControllerCameraDeviceFront), ]; @@ -173,7 +163,7 @@ @YES, @YES, @YES, - popoverOptions, + nil, // popoverOptions - iPadOS only, not used anymore @(UIImagePickerControllerCameraDeviceFront), ]; @@ -203,7 +193,7 @@ @YES, @YES, @YES, - popoverOptions, + nil, // popoverOptions - iPadOS only, not used anymore @(UIImagePickerControllerCameraDeviceFront), ]; diff --git a/tests/tests.js b/tests/tests.js index 721d412..ae65111 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -19,7 +19,7 @@ * */ -/* globals Camera, resolveLocalFileSystemURL, FileEntry, CameraPopoverOptions, LocalFileSystem */ +/* globals Camera, resolveLocalFileSystemURL, FileEntry, LocalFileSystem */ /* eslint-env jasmine */ exports.defineAutoTests = function () { @@ -156,13 +156,7 @@ exports.defineManualTests = function (contentEl, createActionButton) { clearStatus(); const options = extractOptions(); log('Getting picture with options: ' + JSON.stringify(options)); - const popoverHandle = navigator.camera.getPicture(getPictureWin, onGetPictureError, options); - - // Reposition the popover if the orientation changes. - window.onorientationchange = function () { - const newPopoverOptions = new CameraPopoverOptions(0, 0, 100, 100, 0, 300, 400); - popoverHandle.setPosition(newPopoverOptions); - }; + navigator.camera.getPicture(getPictureWin, onGetPictureError, options); } function logCallback (apiName, success) { diff --git a/types/index.d.ts b/types/index.d.ts index cbf62e2..4fe7788 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -36,11 +36,6 @@ interface Camera { cameraSuccess: (data: string) => void, cameraError: (message: string) => void, cameraOptions?: CameraOptions): void; - // Next will work only on iOS - //getPicture( - // cameraSuccess: (data: string) => void, - // cameraError: (message: string) => void, - // cameraOptions?: CameraOptions): CameraPopoverHandle; } interface CameraOptions { @@ -100,46 +95,6 @@ interface CameraOptions { * BACK: 1 */ cameraDirection?: number; - /** iOS-only options that specify popover location in iPad. Defined in CameraPopoverOptions. */ - popoverOptions?: CameraPopoverOptions; -} - -/** - * A handle to the popover dialog created by navigator.camera.getPicture. Used on iOS only. - */ -interface CameraPopoverHandle { - /** - * Set the position of the popover. - * @param popoverOptions the CameraPopoverOptions that specify the new position. - */ - setPosition(popoverOptions: CameraPopoverOptions): void; -} - -/** - * iOS-only parameters that specify the anchor element location and arrow direction - * of the popover when selecting images from an iPad's library or album. - */ -interface CameraPopoverOptions { - x: number; - y: number; - width: number; - height: number; - /** - * Direction the arrow on the popover should point. Defined in Camera.PopoverArrowDirection - * Matches iOS UIPopoverArrowDirection constants. - * ARROW_UP : 1, - * ARROW_DOWN : 2, - * ARROW_LEFT : 4, - * ARROW_RIGHT : 8, - * ARROW_ANY : 15 - */ - arrowDir : number; - popoverWidth: number; - popoverHeight: number; -} - -declare class CameraPopoverOptions implements CameraPopoverOptions { - constructor(x?: number, y?: number, width?: number, height?: number, arrowDir?: number); } declare var Camera: { @@ -166,12 +121,4 @@ declare var Camera: { CAMERA: number; SAVEDPHOTOALBUM: number; } - // Used only on iOS - PopoverArrowDirection: { - ARROW_UP: number; - ARROW_DOWN: number; - ARROW_LEFT: number; - ARROW_RIGHT: number; - ARROW_ANY: number; - } }; diff --git a/www/Camera.js b/www/Camera.js index 1e6b5ca..c722a77 100644 --- a/www/Camera.js +++ b/www/Camera.js @@ -22,8 +22,6 @@ const argscheck = require('cordova/argscheck'); const exec = require('cordova/exec'); const Camera = require('./Camera'); -// XXX: commented out -// CameraPopoverHandle = require('./CameraPopoverHandle'); /** * @namespace navigator @@ -73,7 +71,6 @@ for (const key in Camera) { * @property {module:Camera.MediaType} [mediaType=PICTURE] - Set the type of media to select from. Only works when `PictureSourceType` is `PHOTOLIBRARY` or `SAVEDPHOTOALBUM`. * @property {Boolean} [correctOrientation] - Rotate the image to correct for the orientation of the device during capture. * @property {Boolean} [saveToPhotoAlbum] - Save the image to the photo album on the device after capture. - * @property {module:CameraPopoverOptions} [popoverOptions] - iOS-only options that specify popover location in iPad. * @property {module:Camera.Direction} [cameraDirection=BACK] - Choose the camera to use (front- or back-facing). */ @@ -140,19 +137,19 @@ cameraExport.getPicture = function (successCallback, errorCallback, options) { const allowEdit = !!options.allowEdit; const correctOrientation = !!options.correctOrientation; const saveToPhotoAlbum = !!options.saveToPhotoAlbum; - const popoverOptions = getValue(options.popoverOptions, null); const cameraDirection = getValue(options.cameraDirection, Camera.Direction.BACK); if (allowEdit) { console.warn('allowEdit is deprecated. It does not work reliably on all platforms. Utilise a dedicated image editing library instead. allowEdit functionality is scheduled to be removed in a future release.'); } - const args = [quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, - mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, popoverOptions, cameraDirection]; + const args = [ + quality, destinationType, sourceType, targetWidth, targetHeight, encodingType, + mediaType, allowEdit, correctOrientation, saveToPhotoAlbum, + null, // popoverOptions, iPadOS only, not used anymore + cameraDirection]; exec(successCallback, errorCallback, 'Camera', 'takePicture', args); - // XXX: commented out - // return new CameraPopoverHandle(); }; /** diff --git a/www/CameraConstants.js b/www/CameraConstants.js index bd1adfc..c6cb07d 100644 --- a/www/CameraConstants.js +++ b/www/CameraConstants.js @@ -75,17 +75,6 @@ module.exports = { **/ SAVEDPHOTOALBUM: 2 }, - /** - * Matches iOS UIPopoverArrowDirection constants to specify arrow location on popover. - * @enum {number} - */ - PopoverArrowDirection: { - ARROW_UP: 1, - ARROW_DOWN: 2, - ARROW_LEFT: 4, - ARROW_RIGHT: 8, - ARROW_ANY: 15 - }, /** * @enum {number} */ diff --git a/www/CameraPopoverHandle.js b/www/CameraPopoverHandle.js deleted file mode 100644 index f7252d4..0000000 --- a/www/CameraPopoverHandle.js +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ - -/** - * @ignore in favour of iOS' one - * A handle to an image picker popover. - */ -const CameraPopoverHandle = function () { - this.setPosition = function (popoverOptions) { - console.log('CameraPopoverHandle.setPosition is only supported on iOS.'); - }; -}; - -module.exports = CameraPopoverHandle; diff --git a/www/CameraPopoverOptions.js b/www/CameraPopoverOptions.js deleted file mode 100644 index 68e8ae1..0000000 --- a/www/CameraPopoverOptions.js +++ /dev/null @@ -1,56 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ - -const Camera = require('./Camera'); - -/** - * @namespace navigator - */ - -/** - * iOS-only parameters that specify the anchor element location and arrow - * direction of the popover when selecting images from an iPad's library - * or album. - * Note that the size of the popover may change to adjust to the - * direction of the arrow and orientation of the screen. Make sure to - * account for orientation changes when specifying the anchor element - * location. - * @module CameraPopoverOptions - * @param {Number} [x=0] - x pixel coordinate of screen element onto which to anchor the popover. - * @param {Number} [y=32] - y pixel coordinate of screen element onto which to anchor the popover. - * @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). - */ -const 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 deleted file mode 100644 index b3ac04f..0000000 --- a/www/ios/CameraPopoverHandle.js +++ /dev/null @@ -1,66 +0,0 @@ -/* - * - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * -*/ - -const exec = require('cordova/exec'); - -/** - * @namespace navigator - */ - -/** - * A handle to an image picker popover. - * - * __Supported Platforms__ - * - * - iOS - * - * @example - * 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, 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, 400, 500); - * cameraPopoverHandle.setPosition(cameraPopoverOptions); - * } - * @module CameraPopoverHandle - */ -const CameraPopoverHandle = function () { - /** - * Can be used to reposition the image selection dialog, - * for example, when the device orientation changes. - * @memberof CameraPopoverHandle - * @instance - * @method setPosition - * @param {module:CameraPopoverOptions} popoverOptions - */ - this.setPosition = function (popoverOptions) { - const args = [popoverOptions]; - exec(null, null, 'Camera', 'repositionPopover', args); - }; -}; - -module.exports = CameraPopoverHandle; --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
