mirror of
https://github.com/apache/cordova-plugin-screen-orientation.git
synced 2025-05-05 01:32:59 +08:00
commit
1ca9e4e6e0
@ -80,6 +80,9 @@ Issue [#1](https://github.com/yoik/cordova-yoik-screenorientation/issues/1) @dok
|
|||||||
|
|
||||||
>It seems to be related to having width=device-width, height=device-height in the meta viewport (which is part of the boilerplate phonegap/cordova app). It can be solved by updating the viewport with width=device-height, height=device-width or simply removing width and height altogether.
|
>It seems to be related to having width=device-width, height=device-height in the meta viewport (which is part of the boilerplate phonegap/cordova app). It can be solved by updating the viewport with width=device-height, height=device-width or simply removing width and height altogether.
|
||||||
|
|
||||||
|
####iOS8
|
||||||
|
|
||||||
|
Versions prior to 1.2.0 will cause an application crash in iOS8.
|
||||||
|
|
||||||
##BB10 Notes
|
##BB10 Notes
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
id="net.yoik.cordova.plugins.screenorientation"
|
id="net.yoik.cordova.plugins.screenorientation"
|
||||||
version="1.1.2">
|
version="1.2.0">
|
||||||
|
|
||||||
<name>Screen Orientation</name>
|
<name>Screen Orientation</name>
|
||||||
<description>Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS and BB10.</description>
|
<description>Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS and BB10.</description>
|
||||||
|
@ -30,15 +30,41 @@ SOFTWARE.
|
|||||||
// this method does not control the orientation, it is set in the .js file.
|
// this method does not control the orientation, it is set in the .js file.
|
||||||
|
|
||||||
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
|
// SEE https://github.com/Adlotto/cordova-plugin-recheck-screen-orientation
|
||||||
// ------------------
|
|
||||||
|
|
||||||
// HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately.
|
// HACK: Force rotate by changing the view hierarchy. Present modal view then dismiss it immediately.
|
||||||
[self.viewController presentViewController:[UIViewController new] animated:NO completion:^{ [self.viewController dismissViewControllerAnimated:NO completion:nil]; }];
|
|
||||||
|
|
||||||
// Assume everything went ok
|
UIViewController *vc = [[UIViewController alloc] init];
|
||||||
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
vc.view.alpha = 0;
|
||||||
|
|
||||||
|
[self.viewController presentViewController:vc animated:NO completion:^{
|
||||||
|
// added to support iOS8 beta 5, @see issue #19
|
||||||
|
dispatch_after(0, dispatch_get_main_queue(), ^{
|
||||||
|
[self.viewController dismissViewControllerAnimated:NO completion:nil];
|
||||||
|
});
|
||||||
|
}];
|
||||||
|
|
||||||
|
// grab the device orientation so we can pass it back to the js side.
|
||||||
|
NSString *orientation;
|
||||||
|
switch ([[UIDevice currentDevice] orientation]) {
|
||||||
|
case UIDeviceOrientationLandscapeLeft:
|
||||||
|
orientation = @"landscape-secondary";
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationLandscapeRight:
|
||||||
|
orientation = @"landscape-primary";
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationPortrait:
|
||||||
|
orientation = @"portrait-primary";
|
||||||
|
break;
|
||||||
|
case UIDeviceOrientationPortraitUpsideDown:
|
||||||
|
orientation = @"portrait-secondary";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
orientation = @"portait";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
|
||||||
|
messageAsDictionary:@{@"device":orientation}];
|
||||||
|
|
||||||
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||||
// ------------------
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
@ -1,35 +1,37 @@
|
|||||||
var exec = require('cordova/exec'),
|
var exec = require('cordova/exec'),
|
||||||
screenOrientation = {};
|
screenOrientation = {},
|
||||||
|
iosOrientation = 'unlocked',
|
||||||
|
orientationMap = {
|
||||||
|
'portrait': [0,180],
|
||||||
|
'portrait-primary': [0],
|
||||||
|
'portrait-secondary': [180],
|
||||||
|
'landscape': [-90,90],
|
||||||
|
'landscape-primary': [-90],
|
||||||
|
'landscape-secondary': [90],
|
||||||
|
'default': [-90,90,0]
|
||||||
|
};
|
||||||
|
|
||||||
screenOrientation.setOrientation = function(orientation) {
|
screenOrientation.setOrientation = function(orientation) {
|
||||||
exec(null, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
iosOrientation = orientation;
|
||||||
|
|
||||||
|
var success = function(res) {
|
||||||
|
if (orientation === 'unlocked' && res.device) {
|
||||||
|
iosOrientation = res.device;
|
||||||
|
|
||||||
|
setTimeout(function() {
|
||||||
|
iosOrientation = 'unlocked';
|
||||||
|
},0);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
exec(success, null, "YoikScreenOrientation", "screenOrientation", ['set', orientation]);
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = screenOrientation;
|
module.exports = screenOrientation;
|
||||||
|
|
||||||
// ios orientation callback/hook
|
// ios orientation callback/hook
|
||||||
window.shouldRotateToOrientation = function(orientation) {
|
window.shouldRotateToOrientation = function(orientation) {
|
||||||
var currOrientation = cordova.plugins.screenorientation.currOrientation;
|
var currOrientation = iosOrientation,
|
||||||
switch (currOrientation) {
|
map = orientationMap[currOrientation] || orientationMap['default'];
|
||||||
case 'portrait':
|
return map.indexOf(orientation) >= 0;
|
||||||
case 'portrait-primary':
|
};
|
||||||
if (orientation === 0) return true;
|
|
||||||
break;
|
|
||||||
case 'landscape':
|
|
||||||
case 'landscape-primary':
|
|
||||||
if (orientation === -90) return true;
|
|
||||||
break;
|
|
||||||
case 'landscape':
|
|
||||||
case 'landscape-secondary':
|
|
||||||
if (orientation === 90) return true;
|
|
||||||
break;
|
|
||||||
case 'portrait':
|
|
||||||
case 'portrait-secondary':
|
|
||||||
if (orientation === 180) return true;
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
if (orientation === -90 || orientation === 90 || orientation === 0) return true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user