Merge pull request #24 from gbenvenuti/iosFlicker

Ios flicker
This commit is contained in:
Grant Benvenuti 2014-09-18 10:09:11 +10:00
commit b8a42be1be
5 changed files with 61 additions and 12 deletions

View File

@ -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.

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.2.1">
version="1.3.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,3 +30,9 @@ SOFTWARE.
- (void)screenOrientation:(CDVInvokedUrlCommand *)command;
@end
@interface ForcedViewController : UIViewController
@property (strong, nonatomic) NSString *calledWith;
@end

View File

@ -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

View File

@ -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);
}
};