Skip to content
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down
26 changes: 15 additions & 11 deletions screen-orientation/ios/Plugin/ScreenOrientation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,19 @@ 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()
}

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 {
Expand Down Expand Up @@ -84,12 +88,13 @@ 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
Comment thread
codepip55 marked this conversation as resolved.
Outdated
case "landscape-secondary":
// UIInterfaceOrientationMask.landscapeRight is the same as UIDeviceOrientation.landscapeLeft
return UIInterfaceOrientationMask.landscapeRight
Comment thread
codepip55 marked this conversation as resolved.
case "landscape-secondary":
// UIInterfaceOrientationMask.landscapeLeft is the same as UIDeviceOrientation.landscapeRight
return UIInterfaceOrientationMask.landscapeLeft
case "portrait-secondary":
return UIInterfaceOrientationMask.portraitUpsideDown
default:
Expand All @@ -98,14 +103,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":
// UIInterfaceOrientation.landscapeRight is the same as UIDeviceOrientation.landscapeLeft
Comment thread
codepip55 marked this conversation as resolved.
// @see https://developer.apple.com/documentation/uikit/uiinterfaceorientation/landscaperight
// @see https://developer.apple.com/documentation/uikit/uideviceorientation/landscapeleft
case "landscape":
return [UIInterfaceOrientation.landscapeLeft.rawValue, UIInterfaceOrientation.landscapeRight.rawValue]
case "landscape-primary":
return UIInterfaceOrientation.landscapeRight.rawValue
case "landscape-secondary":
// UIInterfaceOrientation.landscapeLeft is the same as UIDeviceOrientation.landscapeRight
Expand Down