From fedbff124197cd4e4ce3ec94868dbd8441e866f3 Mon Sep 17 00:00:00 2001 From: kevinwang20120702 Date: Mon, 11 Aug 2014 16:45:50 -0400 Subject: [PATCH 1/6] Update screenorientation.ios.js Remove the space --- www/screenorientation.ios.js | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/www/screenorientation.ios.js b/www/screenorientation.ios.js index 50e2c6e..eb6d6da 100644 --- a/www/screenorientation.ios.js +++ b/www/screenorientation.ios.js @@ -12,24 +12,26 @@ window.shouldRotateToOrientation = function(orientation) { var currOrientation = cordova.plugins.screenorientation.currOrientation; switch (currOrientation) { case 'portrait': + if (orientation === 0 || orientation === 180) return true; + break; case 'portrait-primary': - if (orientation === 0) return true; - break; - case 'landscape': + if (orientation === 0) return true; + break; + case 'portrait-secondary': + if (orientation === 180) return true; + break; + case 'landscape': + if (orientation === -90 || orientation === 90) return true; + break; case 'landscape-primary': - if (orientation === -90) return true; - break; - case 'landscape': + if (orientation === -90) return true; + break; 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; + if (orientation === 90) return true; + break; + default: + if (orientation === -90 || orientation === 90 || orientation === 0) return true; + break; } return false; -}; \ No newline at end of file +}; From 7c86844895fcf9f10e88733b5b9ea7b885d1919d Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Tue, 2 Sep 2014 18:30:58 +1000 Subject: [PATCH 2/6] Cleaned up messy switch/if block in iOS js file. --- www/screenorientation.ios.js | 38 ++++++++++++------------------------ 1 file changed, 13 insertions(+), 25 deletions(-) diff --git a/www/screenorientation.ios.js b/www/screenorientation.ios.js index eb6d6da..c155aa1 100644 --- a/www/screenorientation.ios.js +++ b/www/screenorientation.ios.js @@ -9,29 +9,17 @@ module.exports = screenOrientation; // ios orientation callback/hook window.shouldRotateToOrientation = function(orientation) { - var currOrientation = cordova.plugins.screenorientation.currOrientation; - switch (currOrientation) { - case 'portrait': - if (orientation === 0 || orientation === 180) return true; - break; - case 'portrait-primary': - if (orientation === 0) return true; - break; - case 'portrait-secondary': - if (orientation === 180) return true; - break; - case 'landscape': - if (orientation === -90 || orientation === 90) return true; - break; - case 'landscape-primary': - if (orientation === -90) return true; - break; - case 'landscape-secondary': - if (orientation === 90) return true; - break; - default: - if (orientation === -90 || orientation === 90 || orientation === 0) return true; - break; - } - return false; + var currOrientation = cordova.plugins.screenorientation.currOrientation, + orientationMap = { + 'portrait': [0,180], + 'portrait-primary': [0], + 'portrait-secondary': [180], + 'landscape': [-90,90], + 'landscape-primary': [-90], + 'landscape-secondary': [90], + 'default': [-90,90,0] + }, + map = orientationMap[currOrientation] || orientationMap['default']; + + return map.indexOf(orientation) >= 0; }; From e2983442cc81d1007b37f347b3c68c3bd022a6d0 Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Wed, 3 Sep 2014 11:13:54 +1000 Subject: [PATCH 3/6] Updated iOS implementation to support iOS8 beta see #19 --- src/ios/YoikScreenOrientation.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ios/YoikScreenOrientation.m b/src/ios/YoikScreenOrientation.m index 34d5fda..e6139dd 100644 --- a/src/ios/YoikScreenOrientation.m +++ b/src/ios/YoikScreenOrientation.m @@ -33,7 +33,15 @@ SOFTWARE. // ------------------ // 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]; }]; + 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]; + }); + }]; // Assume everything went ok CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; From ad5a2134e824d63334557d01fa1d5b8413d1a35c Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Wed, 3 Sep 2014 11:33:52 +1000 Subject: [PATCH 4/6] Moved orientationMap block --- www/screenorientation.ios.js | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/www/screenorientation.ios.js b/www/screenorientation.ios.js index c155aa1..99f5e4c 100644 --- a/www/screenorientation.ios.js +++ b/www/screenorientation.ios.js @@ -1,5 +1,14 @@ var exec = require('cordova/exec'), - screenOrientation = {}; + screenOrientation = {}, + 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]); @@ -10,16 +19,6 @@ module.exports = screenOrientation; // ios orientation callback/hook window.shouldRotateToOrientation = function(orientation) { var currOrientation = cordova.plugins.screenorientation.currOrientation, - orientationMap = { - 'portrait': [0,180], - 'portrait-primary': [0], - 'portrait-secondary': [180], - 'landscape': [-90,90], - 'landscape-primary': [-90], - 'landscape-secondary': [90], - 'default': [-90,90,0] - }, map = orientationMap[currOrientation] || orientationMap['default']; - return map.indexOf(orientation) >= 0; }; From efe1edede3da4472c45b5f2e850a30dd21c972eb Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Wed, 3 Sep 2014 14:09:24 +1000 Subject: [PATCH 5/6] Added fix for ios so device returns to current orientation when unlocked --- src/ios/YoikScreenOrientation.m | 28 +++++++++++++++++++++++----- www/screenorientation.ios.js | 17 +++++++++++++++-- 2 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/ios/YoikScreenOrientation.m b/src/ios/YoikScreenOrientation.m index e6139dd..e1f077b 100644 --- a/src/ios/YoikScreenOrientation.m +++ b/src/ios/YoikScreenOrientation.m @@ -30,9 +30,8 @@ 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. + UIViewController *vc = [[UIViewController alloc] init]; vc.view.alpha = 0; @@ -43,10 +42,29 @@ SOFTWARE. }); }]; - // Assume everything went ok - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + // 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 \ No newline at end of file diff --git a/www/screenorientation.ios.js b/www/screenorientation.ios.js index 99f5e4c..22ed12d 100644 --- a/www/screenorientation.ios.js +++ b/www/screenorientation.ios.js @@ -1,5 +1,6 @@ var exec = require('cordova/exec'), screenOrientation = {}, + iosOrientation = 'unlocked', orientationMap = { 'portrait': [0,180], 'portrait-primary': [0], @@ -11,14 +12,26 @@ var exec = require('cordova/exec'), }; 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, + var currOrientation = iosOrientation, map = orientationMap[currOrientation] || orientationMap['default']; return map.indexOf(orientation) >= 0; }; From 8f69814dac6d397a1b186aa39bbf95bc121e67b5 Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Wed, 3 Sep 2014 14:14:10 +1000 Subject: [PATCH 6/6] Version bump and readme update --- README.md | 3 +++ plugin.xml | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 05117dd..2ad7bd5 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/plugin.xml b/plugin.xml index d710d69..33a7849 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.2.0"> Screen Orientation Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS and BB10.