| 1 | import ExpoModulesCore |
| 2 | import UIKit |
| 3 | |
| 4 | /// Keep ordinary phones portrait-only while allowing a hinge-backed scene to rotate. |
| 5 | public final class T3WorkspaceOrientationSubscriber: ExpoAppDelegateSubscriber { |
| 6 | private static let hingeWindows = NSHashTable<UIWindow>.weakObjects() |
| 7 | |
| 8 | static func allowHingeOrientations(in window: UIWindow) { |
| 9 | guard !hingeWindows.contains(window) else { return } |
| 10 | hingeWindows.add(window) |
| 11 | window.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations() |
| 12 | } |
| 13 | |
| 14 | public func application(_ application: UIApplication, supportedInterfaceOrientationsFor window: UIWindow?) -> UIInterfaceOrientationMask { |
| 15 | if UIDevice.current.userInterfaceIdiom == .pad { |
| 16 | // Keep iPad orientation policy, including portrait-only showcase captures. |
| 17 | let orientations = Bundle.main.object(forInfoDictionaryKey: "UISupportedInterfaceOrientations~ipad") as? [String] ?? [] |
| 18 | return orientations == ["UIInterfaceOrientationPortrait"] ? .portrait : .all |
| 19 | } |
| 20 | return window.map { Self.hingeWindows.contains($0) } == true ? .allButUpsideDown : .portrait |
| 21 | } |
| 22 | } |