Merge pull request #20 from gbenvenuti/iosUpdates

Ios updates
This commit is contained in:
Grant Benvenuti 2014-09-03 14:16:02 +10:00
commit 1ca9e4e6e0
4 changed files with 64 additions and 33 deletions

View File

@ -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.
####iOS8
Versions prior to 1.2.0 will cause an application crash in iOS8.
##BB10 Notes

View File

@ -2,7 +2,7 @@
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
xmlns:android="http://schemas.android.com/apk/res/android"
id="net.yoik.cordova.plugins.screenorientation"
version="1.1.2">
version="1.2.0">
<name>Screen Orientation</name>
<description>Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS and BB10.</description>

View File

@ -30,15 +30,41 @@ SOFTWARE.
// this method does not control the orientation, it is set in the .js file.
// 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.
[self.viewController presentViewController:[UIViewController new] animated:NO completion:^{ [self.viewController dismissViewControllerAnimated:NO completion:nil]; }];
// Assume everything went ok
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
UIViewController *vc = [[UIViewController alloc] init];
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];
// ------------------
}
@end

View File

@ -1,35 +1,37 @@
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) {
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;
// ios orientation callback/hook
window.shouldRotateToOrientation = function(orientation) {
var currOrientation = cordova.plugins.screenorientation.currOrientation;
switch (currOrientation) {
case 'portrait':
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;
var currOrientation = iosOrientation,
map = orientationMap[currOrientation] || orientationMap['default'];
return map.indexOf(orientation) >= 0;
};