From fce44f4942adf20cff6769f4c7b53715584f6b31 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pascal=20H=C3=A4usler?=
Date: Fri, 3 Mar 2017 15:03:09 +0100
Subject: [PATCH] Rotate to specified orientation when locked
Refactor
---
src/ios/CDVOrientation.m | 21 +++++++++++++++++++--
src/windows/CDVOrientationProxy.js | 2 +-
www/screenorientation.js | 17 ++++++++---------
3 files changed, 28 insertions(+), 12 deletions(-)
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/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) {