mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
Rotate to specified orientation when locked
Refactor
This commit is contained in:
parent
f0c65cfee1
commit
fce44f4942
@ -52,6 +52,23 @@
|
||||
|
||||
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 {
|
||||
|
@ -57,6 +57,6 @@ module.exports = {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require("cordova/exec/proxy").add("CDVOrientation", module.exports);
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user