Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

background thread for ios #54

Merged
merged 1 commit into from Aug 9, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
114 changes: 60 additions & 54 deletions src/ios/YoikScreenOrientation.m
Expand Up @@ -27,61 +27,67 @@ @implementation YoikScreenOrientation

-(void)screenOrientation:(CDVInvokedUrlCommand *)command
{
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;
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;
}

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;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// This stops us getting the black application background flash, iOS8
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
#endif

[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];
[self.commandDelegate runInBackground:^{

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

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;

#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
// This stops us getting the black application background flash, iOS8
vc.modalPresentationStyle = UIModalPresentationOverFullScreen;
#endif

dispatch_async(dispatch_get_main_queue(), ^{
[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];
});
}];
});

}];
}

Expand Down