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,10 +52,27 @@
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];

View File

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

View File

@ -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) {