Rotate to specified orientation when locked

Refactor
This commit is contained in:
Pascal Häusler 2017-03-03 15:03:09 +01:00 committed by Jesse MacFadyen
parent f0c65cfee1
commit fce44f4942
3 changed files with 28 additions and 12 deletions

View File

@ -52,6 +52,23 @@
if([vc respondsToSelector:selector]) { if([vc respondsToSelector:selector]) {
((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result); ((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]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
} }
else { else {

View File

@ -57,6 +57,6 @@ module.exports = {
} }
} }
} };
require("cordova/exec/proxy").add("CDVOrientation", module.exports); require("cordova/exec/proxy").add("CDVOrientation", module.exports);

View File

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