diff --git a/README.md b/README.md index 9f296c1..4764519 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ # under the License. --> -|Android 4.4|Android 5.1|iOS 9.3|iOS 10.0|Windows 10 Store| -|:-:|:-:|:-:|:-:|:-:| -|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-screen-orientation/)| +|Android 4.4|Android 5.1|Android 6.0|iOS 9.3|iOS 10.0|Windows 10 Store| +|:-:|:-:|:-:|:-:|:-:|:-:| +|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-4.4,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-5.1,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=android-6.0,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=android-6.0,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-9.3,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=ios-10.0,PLUGIN=cordova-plugin-screen-orientation/)|[![Build Status](http://cordova-ci.cloudapp.net:8080/buildStatus/icon?job=cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-screen-orientation)](http://cordova-ci.cloudapp.net:8080/job/cordova-periodic-build/PLATFORM=windows-10-store,PLUGIN=cordova-plugin-screen-orientation/)| # Cordova Screen Orientation Plugin diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 5c21e55..06b376f 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -22,6 +22,12 @@ # Release Notes +### 2.0.1 (Apr 27, 2017) +* [CB-12622](https://issues.apache.org/jira/browse/CB-12622) Added **Android 6.0** build badge to `README` +* [CB-12543](https://issues.apache.org/jira/browse/CB-12543) (iOS) Rotate to specified orientation when locked +* [CB-12685](https://issues.apache.org/jira/browse/CB-12685) added `package.json` to tests folder +* [CB-12588](https://issues.apache.org/jira/browse/CB-12588) add manual tests in cordova-plugin-test-framework style + ### 2.0.0 (Mar 14, 2017) * [CB-11628](https://issues.apache.org/jira/browse/CB-11628) - w3c spec compliance https://www.w3.org/TR/screen-orientation/ diff --git a/package.json b/package.json index 75d03ba..453caba 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-screen-orientation", - "version": "2.0.0", + "version": "2.0.1", "description": "Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS, WP8, W8.1, and BB10.", "repository": { "type": "git", @@ -33,10 +33,10 @@ "jshint": "^2.9.4" }, "engines": { - "cordovaDependencies": { - "3.0.0": { - "cordova": ">100" - } + "cordovaDependencies": { + "3.0.0": { + "cordova": ">100" } } + } } diff --git a/plugin.xml b/plugin.xml index 0880ec1..8517756 100644 --- a/plugin.xml +++ b/plugin.xml @@ -18,7 +18,7 @@ + version="2.0.1"> Screen Orientation Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS, WP8, W8.1, and BB10. Apache 2.0 diff --git a/src/ios/CDVOrientation.m b/src/ios/CDVOrientation.m index b38a55d..c7704e4 100644 --- a/src/ios/CDVOrientation.m +++ b/src/ios/CDVOrientation.m @@ -52,14 +52,31 @@ if([vc respondsToSelector:selector]) { ((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result); + + if ([UIDevice currentDevice] != nil){ + NSNumber *value = nil; + if(orientationMask == 8 || orientationMask == 12) { + value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight]; + } else if (orientationMask == 4){ + value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft]; + } else if (orientationMask == 1 || orientationMask == 3) { + value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait]; + } else if (orientationMask == 2) { + value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown]; + } + if (value != nil) { + [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; + } + } + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; } else { - pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_INVALID_ACTION messageAsString:@"Error calling to set supported orientations"]; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_INVALID_ACTION messageAsString:@"Error calling to set supported orientations"]; } [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } -@end \ No newline at end of file +@end diff --git a/src/windows/CDVOrientationProxy.js b/src/windows/CDVOrientationProxy.js index 214994a..7f36b49 100644 --- a/src/windows/CDVOrientationProxy.js +++ b/src/windows/CDVOrientationProxy.js @@ -57,6 +57,6 @@ module.exports = { } } -} +}; require("cordova/exec/proxy").add("CDVOrientation", module.exports); diff --git a/tests/package.json b/tests/package.json new file mode 100644 index 0000000..f4bfbc4 --- /dev/null +++ b/tests/package.json @@ -0,0 +1,14 @@ +{ + "name": "cordova-plugin-screen-orientation-tests", + "version": "2.0.1-dev", + "description": "", + "cordova": { + "id": "cordova-plugin-screen-orientation-tests", + "platforms": [] + }, + "keywords": [ + "ecosystem:cordova" + ], + "author": "", + "license": "Apache 2.0" +} diff --git a/tests/plugin.xml b/tests/plugin.xml index ffddc59..127650f 100644 --- a/tests/plugin.xml +++ b/tests/plugin.xml @@ -22,7 +22,7 @@ xmlns:rim="http://www.blackberry.com/ns/widgets" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-screen-orientation-tests" - version="2.0.0"> + version="2.0.1"> Cordova Screen Orientation Plugin Tests Apache 2.0 diff --git a/tests/tests.js b/tests/tests.js index b91f81a..42b5aff 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -139,3 +139,23 @@ exports.defineAutoTests = function() { }); }); }; +exports.defineManualTests = function(contentEl, createActionButton) { + + createActionButton('Listen to orientationchange events', function() { + window.addEventListener("orientationchange", function(){ + contentEl.innerHTML += '

Orientation changed! ' + screen.orientation.type + '

'; + }); + }); + createActionButton('Unlock orientation', function() { + screen.orientation.unlock(); + contentEl.innerHTML += '

Orientation unlocked.

'; + }); + createActionButton('Lock to portrait', function() { + screen.orientation.lock('portrait'); + contentEl.innerHTML += '

Orientation locked to portrait.

'; + }); + createActionButton('Lock to landscape', function() { + screen.orientation.lock('landscape'); + contentEl.innerHTML += '

Orientation locked to landscape.

'; + }); +}; diff --git a/www/screenorientation.js b/www/screenorientation.js index 0bdb814..ef2eb49 100644 --- a/www/screenorientation.js +++ b/www/screenorientation.js @@ -59,7 +59,7 @@ function addScreenOrientationApi(screenObject) { screenObject.lock = function(orientation) { var promiseLock; var p = new Promise(function(resolve, reject) { - if (screenObject.nativeLock != null) { + if (screenObject.nativeLock) { promiseLock = screenObject.nativeLock(orientation); promiseLock.then(function success(res) { resolve(); @@ -70,14 +70,12 @@ function addScreenOrientationApi(screenObject) { } else { resolveOrientation(orientation, resolve, reject); } - }) + }); return p; - } - + }; screenObject.unlock = function() { screenOrientation.setOrientation('any'); }; - } function resolveOrientation(orientation, resolve, reject) { @@ -99,11 +97,11 @@ var onChangeListener = null; Object.defineProperty(screen.orientation, 'onchange', { set: function(listener) { - if (onChangeListener != null) { + if (onChangeListener) { screen.orientation.removeEventListener('change', onChangeListener); } onChangeListener = listener; - if (onChangeListener != null) { + if (onChangeListener) { screen.orientation.addEventListener('change', onChangeListener); } }, @@ -124,10 +122,11 @@ var orientationchange = function() { screen.orientation.addEventListener = function(a,b,c) { return evtTarget.addEventListener(a,b,c); -} +}; + screen.orientation.removeEventListener = function(a,b,c) { return evtTarget.removeEventListener(a,b,c); -} +}; function setOrientationProperties() { switch (window.orientation) {