You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2017/12/12 18:41:09 UTC

[GitHub] maverickmishra closed pull request #24: CB-13405: (ios) Go to last used orientation before locking when unlocking screen on iOS

maverickmishra closed pull request #24: CB-13405: (ios) Go to last used orientation before locking when unlocking screen on iOS
URL: https://github.com/apache/cordova-plugin-screen-orientation/pull/24
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/ios/CDVOrientation.h b/src/ios/CDVOrientation.h
index 48166a3..6bdd4d4 100644
--- a/src/ios/CDVOrientation.h
+++ b/src/ios/CDVOrientation.h
@@ -24,7 +24,11 @@
 #import <Cordova/CDVViewController.h>
 
 @interface CDVOrientation : CDVPlugin
-{}
+{
+@protected
+    BOOL _isLocked;
+    UIInterfaceOrientation _lastOrientation;
+}
 
 - (void)screenOrientation:(CDVInvokedUrlCommand *)command;
 
diff --git a/src/ios/CDVOrientation.m b/src/ios/CDVOrientation.m
index c7704e4..0152680 100644
--- a/src/ios/CDVOrientation.m
+++ b/src/ios/CDVOrientation.m
@@ -51,21 +51,37 @@ -(void)screenOrientation:(CDVInvokedUrlCommand *)command
     SEL selector = NSSelectorFromString(@"setSupportedOrientations:");
     
     if([vc respondsToSelector:selector]) {
-        ((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
+        if (orientationMask != 15 || [UIDevice currentDevice] == nil) {
+            ((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
+        }
         
         if ([UIDevice currentDevice] != nil){
             NSNumber *value = nil;
-            if(orientationMask == 8 || orientationMask == 12) {
-                value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
-            } else if (orientationMask == 4){
-                value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
-            } else if (orientationMask == 1 || orientationMask == 3) {
-                value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
-            } else if (orientationMask == 2) {
-                value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
+            if (orientationMask != 15) {
+                if (!_isLocked) {
+                    _lastOrientation = [UIApplication sharedApplication].statusBarOrientation;
+                }
+                if(orientationMask == 8 || orientationMask == 12) {
+                    value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
+                } else if (orientationMask == 4){
+                    value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeLeft];
+                } else if (orientationMask == 1 || orientationMask == 3) {
+                    value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
+                } else if (orientationMask == 2) {
+                    value = [NSNumber numberWithInt:UIInterfaceOrientationPortraitUpsideDown];
+                }
+            } else {
+                if (_lastOrientation != UIInterfaceOrientationUnknown) {
+                    [[UIDevice currentDevice] setValue:[NSNumber numberWithInt:_lastOrientation] forKey:@"orientation"];
+                    ((void (*)(CDVViewController*, SEL, NSMutableArray*))objc_msgSend)(vc,selector,result);
+                    [UINavigationController attemptRotationToDeviceOrientation];
+                }
             }
             if (value != nil) {
+                _isLocked = true;
                 [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
+            } else {
+                _isLocked = false;
             }
         }
         


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org