Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
24 changes: 18 additions & 6 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 All @@ -41,7 +45,11 @@ public class ScreenOrientation: NSObject {
completion(ScreenOrientationError.noWindowScene)
}
} else {
self.lockLegacy(orientation)
if let orientation = orientation as? [Int] {
self.lockLegacy(orientation[1])
} else {
self.lockLegacy(orientation as! Int)
}
}
completion(nil)
}
Expand Down Expand Up @@ -84,7 +92,9 @@ public class ScreenOrientation: NSObject {
switch orientationType {
case "any":
return UIInterfaceOrientationMask.all
case "landscape", "landscape-primary":
case "landscape":
return UIInterfaceOrientationMask.landscape
case "landscape-primary":
// UIInterfaceOrientationMask.landscapeRight is the same as UIDeviceOrientation.landscapeLeft
return UIInterfaceOrientationMask.landscapeRight
case "landscape-secondary":
Expand All @@ -98,11 +108,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":
// 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
Expand Down