From 3b7d259193134577abf68916b14211fda858969f Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Thu, 18 Sep 2014 09:42:23 +1000 Subject: [PATCH 1/2] Removed flicker in iOS8 closes #23 --- README.md | 14 +++++++++- src/ios/YoikScreenOrientation.h | 6 +++++ src/ios/YoikScreenOrientation.m | 48 +++++++++++++++++++++++++++------ www/screenorientation.ios.js | 3 +-- 4 files changed, 60 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 2ad7bd5..5f7b745 100644 --- a/README.md +++ b/README.md @@ -82,10 +82,22 @@ Issue [#1](https://github.com/yoik/cordova-yoik-screenorientation/issues/1) @dok ####iOS8 -Versions prior to 1.2.0 will cause an application crash in iOS8. +Versions prior to 1.2.0 will cause an application crash in iOS8 due to a change in presentViewController timing. ##BB10 Notes Wraps the com.blackberry.app plugin functions, auto installed as a dependancy. +#Changelog + +##1.3.0 + +* [#23](https://github.com/yoik/cordova-yoik-screenorientation/issues/23) iOS8 flicker + +##1.2.0-1.2.1 + +* [#19](https://github.com/yoik/cordova-yoik-screenorientation/issues/19) iOS8 Crash + + + Pull requests welcome. diff --git a/src/ios/YoikScreenOrientation.h b/src/ios/YoikScreenOrientation.h index 4ec730d..95da6e8 100644 --- a/src/ios/YoikScreenOrientation.h +++ b/src/ios/YoikScreenOrientation.h @@ -29,4 +29,10 @@ SOFTWARE. - (void)screenOrientation:(CDVInvokedUrlCommand *)command; +@end + +@interface ForcedViewController : UIViewController + +@property (strong, nonatomic) NSString *calledWith; + @end \ No newline at end of file diff --git a/src/ios/YoikScreenOrientation.m b/src/ios/YoikScreenOrientation.m index 3cf8eb1..17ca3db 100644 --- a/src/ios/YoikScreenOrientation.m +++ b/src/ios/YoikScreenOrientation.m @@ -27,12 +27,8 @@ SOFTWARE. -(void)screenOrientation:(CDVInvokedUrlCommand *)command { - // 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:nil]; - [self.viewController dismissViewControllerAnimated:NO completion:nil]; + NSArray* arguments = command.arguments; + NSString* orientationIn = [arguments objectAtIndex:1]; // grab the device orientation so we can pass it back to the js side. NSString *orientation; @@ -53,10 +49,46 @@ SOFTWARE. orientation = @"portait"; break; } - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK - messageAsDictionary:@{@"device":orientation}]; + if ([orientationIn isEqual: @"unlocked"]) { + orientationIn = orientation; + } + + // we send the result prior to the view controller presentation so that the JS side + // is ready for the unlock call. + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK + messageAsDictionary:@{@"device":orientation}]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; + + // 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 + // This has been changed substantially since iOS8 broke it... + ForcedViewController *vc = [[ForcedViewController alloc] init]; + vc.calledWith = orientationIn; + + // backgound should be transparent as it is briefly visible + // prior to closing. + vc.view.backgroundColor = [UIColor clearColor]; + // vc.view.alpha = 0.0; + vc.view.opaque = YES; + // This stops us getting the black application background flash, iOS8 + vc.modalPresentationStyle = UIModalPresentationOverFullScreen; + + [self.viewController presentViewController:vc animated:NO completion:nil]; + [self.viewController dismissViewControllerAnimated:NO completion:nil]; } +@end + +@implementation ForcedViewController + +- (NSUInteger) supportedInterfaceOrientations +{ + if ([self.calledWith rangeOfString:@"portrait"].location != NSNotFound) { + return UIInterfaceOrientationMaskPortrait; + } else if([self.calledWith rangeOfString:@"landscape"].location != NSNotFound) { + return UIInterfaceOrientationMaskLandscape; + } + return UIInterfaceOrientationMaskAll; +} @end \ No newline at end of file diff --git a/www/screenorientation.ios.js b/www/screenorientation.ios.js index 9cb878b..11d30f7 100644 --- a/www/screenorientation.ios.js +++ b/www/screenorientation.ios.js @@ -17,10 +17,9 @@ screenOrientation.setOrientation = function(orientation) { var success = function(res) { if (orientation === 'unlocked' && res.device) { iosOrientation = res.device; - setTimeout(function() { iosOrientation = 'unlocked'; - },0); + },300); } }; From c122649de2bc8dafaa6582c9a118fae73fc15367 Mon Sep 17 00:00:00 2001 From: Grant Benvenuti Date: Thu, 18 Sep 2014 09:45:51 +1000 Subject: [PATCH 2/2] Version bump 1.3.0 --- plugin.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugin.xml b/plugin.xml index f947ab8..f4b7472 100644 --- a/plugin.xml +++ b/plugin.xml @@ -2,7 +2,7 @@ + version="1.3.0"> Screen Orientation Adds Screen Orientation API lock and unlock functions to the global screen object in android, iOS and BB10.