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