|
1 | 1 | import ExpoModulesCore |
2 | 2 | import Security |
| 3 | +import UIKit |
3 | 4 |
|
4 | 5 | public final class T3NativeControlsModule: Module { |
5 | 6 | public func definition() -> ModuleDefinition { |
@@ -32,6 +33,50 @@ public final class T3NativeControlsModule: Module { |
32 | 33 | return arguments[flagIndex + 1] |
33 | 34 | } |
34 | 35 |
|
| 36 | + Function("getShowcaseOrientation") { () -> String? in |
| 37 | + let arguments = ProcessInfo.processInfo.arguments |
| 38 | + guard |
| 39 | + let flagIndex = arguments.firstIndex(of: "--showcaseOrientation"), |
| 40 | + arguments.indices.contains(flagIndex + 1) |
| 41 | + else { |
| 42 | + return nil as String? |
| 43 | + } |
| 44 | + return arguments[flagIndex + 1] |
| 45 | + } |
| 46 | + |
| 47 | + // Rotates the interface without Simulator menu UI scripting, which CI |
| 48 | + // runners cannot perform (osascript is denied Accessibility access there). |
| 49 | + AsyncFunction("applyShowcaseOrientation") { (orientation: String) in |
| 50 | + guard #available(iOS 16.0, *) else { return } |
| 51 | + let mask: UIInterfaceOrientationMask = orientation == "landscape" ? .landscapeRight : .portrait |
| 52 | + for case let windowScene as UIWindowScene in UIApplication.shared.connectedScenes { |
| 53 | + windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: mask)) { error in |
| 54 | + NSLog("T3NativeControls applyShowcaseOrientation(\(orientation)) failed: \(error)") |
| 55 | + } |
| 56 | + for window in windowScene.windows { |
| 57 | + window.rootViewController?.setNeedsUpdateOfSupportedInterfaceOrientations() |
| 58 | + } |
| 59 | + } |
| 60 | + }.runOnQueue(.main) |
| 61 | + |
| 62 | + // The geometry request above can fail transiently (for example before the |
| 63 | + // scene is foreground-active), so callers poll this until it settles. |
| 64 | + // Screen bounds — not the scene's interface orientation — decide the |
| 65 | + // answer because they match the captured framebuffer: with iPadOS |
| 66 | + // windowing active, a floating landscape window still reports a portrait |
| 67 | + // screen, and screenshots would come out portrait. |
| 68 | + AsyncFunction("getInterfaceOrientation") { () -> String in |
| 69 | + guard |
| 70 | + let windowScene = UIApplication.shared.connectedScenes |
| 71 | + .compactMap({ $0 as? UIWindowScene }) |
| 72 | + .first |
| 73 | + else { |
| 74 | + return "unknown" |
| 75 | + } |
| 76 | + let bounds = windowScene.screen.coordinateSpace.bounds |
| 77 | + return bounds.width > bounds.height ? "landscape" : "portrait" |
| 78 | + }.runOnQueue(.main) |
| 79 | + |
35 | 80 | Function("prepareShowcaseCapture") { |
36 | 81 | for itemClass in [kSecClassGenericPassword, kSecClassInternetPassword] { |
37 | 82 | SecItemDelete([kSecClass as String: itemClass] as CFDictionary) |
|
0 commit comments