Skip to content

Commit

Permalink
Merge pull request #54 from orlando-antonino/master
Browse files Browse the repository at this point in the history
background thread for ios
  • Loading branch information
gbenvenuti committed Aug 9, 2015
2 parents 0eb6d35 + f3d451c commit c7e3cf4
Showing 1 changed file with 60 additions and 54 deletions.
114 changes: 60 additions & 54 deletions src/ios/YoikScreenOrientation.m
Original file line number Diff line number Diff line change
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

0 comments on commit c7e3cf4

Please sign in to comment.