From a1f43db8cc3d99384d91b6cd8a048bd14609e404 Mon Sep 17 00:00:00 2001 From: Pip <92968130+codepip55@users.noreply.github.com> Date: Mon, 26 Feb 2024 10:46:04 +0100 Subject: [PATCH 1/5] Add separate statements for landscape option, fixes #2039 --- .../plugins/screenorientation/ScreenOrientation.java | 1 + screen-orientation/ios/Plugin/ScreenOrientation.swift | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/screen-orientation/android/src/main/java/com/capacitorjs/plugins/screenorientation/ScreenOrientation.java b/screen-orientation/android/src/main/java/com/capacitorjs/plugins/screenorientation/ScreenOrientation.java index 220db7077..5ab13215f 100644 --- a/screen-orientation/android/src/main/java/com/capacitorjs/plugins/screenorientation/ScreenOrientation.java +++ b/screen-orientation/android/src/main/java/com/capacitorjs/plugins/screenorientation/ScreenOrientation.java @@ -60,6 +60,7 @@ private int fromOrientationTypeToEnum(String orientationType) { case "any": return ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED; case "landscape": + return ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE; case "landscape-primary": return ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; case "landscape-secondary": diff --git a/screen-orientation/ios/Plugin/ScreenOrientation.swift b/screen-orientation/ios/Plugin/ScreenOrientation.swift index 149aa88d7..ba4f4e5de 100644 --- a/screen-orientation/ios/Plugin/ScreenOrientation.swift +++ b/screen-orientation/ios/Plugin/ScreenOrientation.swift @@ -84,7 +84,9 @@ public class ScreenOrientation: NSObject { switch orientationType { case "any": return UIInterfaceOrientationMask.all - case "landscape", "landscape-primary": + case "landscape": + return UIInterfaceOrientationMask.landscape + case "landscape-primary": return UIInterfaceOrientationMask.landscapeLeft case "landscape-secondary": return UIInterfaceOrientationMask.landscapeRight From ae1c1f0aeb0621520d7331098844ca0970d2ee2c Mon Sep 17 00:00:00 2001 From: Pip <92968130+codepip55@users.noreply.github.com> Date: Mon, 26 Feb 2024 14:51:17 +0100 Subject: [PATCH 2/5] Fix iOS Screen Orientation Types --- .../ios/Plugin/ScreenOrientation.swift | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/screen-orientation/ios/Plugin/ScreenOrientation.swift b/screen-orientation/ios/Plugin/ScreenOrientation.swift index ba4f4e5de..930b27af8 100644 --- a/screen-orientation/ios/Plugin/ScreenOrientation.swift +++ b/screen-orientation/ios/Plugin/ScreenOrientation.swift @@ -21,7 +21,7 @@ public class ScreenOrientation: NSObject { return fromDeviceOrientationToOrientationType(currentOrientation) } - private func lockLegacy(_ orientation: Int) { + private func lockLegacy(_ orientation: Any) { UIDevice.current.setValue(orientation, forKey: "orientation") UINavigationController.attemptRotationToDeviceOrientation() } @@ -29,7 +29,11 @@ public class ScreenOrientation: NSObject { public func lock(_ orientationType: String, completion: @escaping (Error?) -> Void) { DispatchQueue.main.async { let orientation = self.fromOrientationTypeToInt(orientationType) - self.capViewController?.supportedOrientations = [orientation] + if let orientation = orientation as? Int { + self.capViewController?.supportedOrientations = [orientation] + } else { + self.capViewController?.supportedOrientations = orientation as! [Int] + } let mask = self.fromOrientationTypeToMask(orientationType) if #available(iOS 16.0, *) { if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene { @@ -98,11 +102,13 @@ public class ScreenOrientation: NSObject { } } - private func fromOrientationTypeToInt(_ orientationType: String) -> Int { + private func fromOrientationTypeToInt(_ orientationType: String) -> Any { switch orientationType { case "any": return UIInterfaceOrientation.unknown.rawValue - case "landscape", "landscape-primary": + case "landscape": + return [UIInterfaceOrientation.landscapeLeft.rawValue, UIInterfaceOrientation.landscapeRight.rawValue] + case "landscape-primary": return UIInterfaceOrientation.landscapeLeft.rawValue case "landscape-secondary": return UIInterfaceOrientation.landscapeRight.rawValue From 523c7675c9b4774085a9b9ecca3ec18443112739 Mon Sep 17 00:00:00 2001 From: Pip <92968130+codepip55@users.noreply.github.com> Date: Thu, 18 Apr 2024 19:41:49 +0200 Subject: [PATCH 3/5] Fix overwritten changes --- screen-orientation/ios/Plugin/ScreenOrientation.swift | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/screen-orientation/ios/Plugin/ScreenOrientation.swift b/screen-orientation/ios/Plugin/ScreenOrientation.swift index 410de0137..bc777af3c 100644 --- a/screen-orientation/ios/Plugin/ScreenOrientation.swift +++ b/screen-orientation/ios/Plugin/ScreenOrientation.swift @@ -91,10 +91,11 @@ public class ScreenOrientation: NSObject { case "landscape": return UIInterfaceOrientationMask.landscape case "landscape-primary": - return UIInterfaceOrientationMask.landscapeLeft - case "landscape-secondary": // UIInterfaceOrientationMask.landscapeRight is the same as UIDeviceOrientation.landscapeLeft return UIInterfaceOrientationMask.landscapeRight + case "landscape-secondary": + // UIInterfaceOrientationMask.landscapeLeft is the same as UIDeviceOrientation.landscapeRight + return UIInterfaceOrientationMask.landscapeLeft case "portrait-secondary": return UIInterfaceOrientationMask.portraitUpsideDown default: @@ -110,6 +111,9 @@ public class ScreenOrientation: NSObject { case "landscape": return [UIInterfaceOrientation.landscapeLeft.rawValue, UIInterfaceOrientation.landscapeRight.rawValue] case "landscape-primary": + // UIInterfaceOrientation.landscapeRight is the same as UIDeviceOrientation.landscapeLeft + // @see https://developer.apple.com/documentation/uikit/uiinterfaceorientation/landscaperight + // @see https://developer.apple.com/documentation/uikit/uideviceorientation/landscapeleft return UIInterfaceOrientation.landscapeRight.rawValue case "landscape-secondary": // UIInterfaceOrientation.landscapeLeft is the same as UIDeviceOrientation.landscapeRight From adfe6252da78432a6de46f99fb4d312fd73eb0ed Mon Sep 17 00:00:00 2001 From: Pip <92968130+codepip55@users.noreply.github.com> Date: Mon, 17 Jun 2024 17:13:29 +0200 Subject: [PATCH 4/5] Check type on lockLegacy --- screen-orientation/ios/Plugin/ScreenOrientation.swift | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/screen-orientation/ios/Plugin/ScreenOrientation.swift b/screen-orientation/ios/Plugin/ScreenOrientation.swift index bc777af3c..ef1c440e3 100644 --- a/screen-orientation/ios/Plugin/ScreenOrientation.swift +++ b/screen-orientation/ios/Plugin/ScreenOrientation.swift @@ -45,7 +45,11 @@ public class ScreenOrientation: NSObject { completion(ScreenOrientationError.noWindowScene) } } else { - self.lockLegacy(orientation) + if let orientation = orientation as? [Int] { + self.lockLegacy(orientation[0]) + } else { + self.lockLegacy(orientation as! Int) + } } completion(nil) } From c6f9b30be51c6b67d7c2dfdf567386d0d9133476 Mon Sep 17 00:00:00 2001 From: Pip <92968130+codepip55@users.noreply.github.com> Date: Tue, 9 Jul 2024 15:23:47 +0200 Subject: [PATCH 5/5] Get landscape-primary on iOS versions under 16 --- screen-orientation/ios/Plugin/ScreenOrientation.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/screen-orientation/ios/Plugin/ScreenOrientation.swift b/screen-orientation/ios/Plugin/ScreenOrientation.swift index ef1c440e3..ad0c4ab06 100644 --- a/screen-orientation/ios/Plugin/ScreenOrientation.swift +++ b/screen-orientation/ios/Plugin/ScreenOrientation.swift @@ -46,7 +46,7 @@ public class ScreenOrientation: NSObject { } } else { if let orientation = orientation as? [Int] { - self.lockLegacy(orientation[0]) + self.lockLegacy(orientation[1]) } else { self.lockLegacy(orientation as! Int) }