From 64b9e62a0518d0a5ff4ad9ea48dc73b3ba8c018b Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 13:27:07 +0800 Subject: [PATCH] Layout check: each size with its device's status bar and home indicator The windows took the insets of the simulator the check runs in (a phone with a camera island), so every picture had its top gap and home indicator whatever device it stood for. Assisted-by: LLM --- companion/App/LayoutCheck.swift | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/companion/App/LayoutCheck.swift b/companion/App/LayoutCheck.swift index c3d73f6..e5ae543 100644 --- a/companion/App/LayoutCheck.swift +++ b/companion/App/LayoutCheck.swift @@ -18,6 +18,19 @@ enum LayoutCheck { return upright + upright.map { CGSize(width: $0.height, height: $0.width) } }() + /// The status bar and home indicator of each size's device: the iPod touch, iPhone 8 + /// and the iPads with a Home button have a 20-point status bar (none on a phone on its + /// side); the iPhone XR has its notch and home indicator, the iPad Pro its rounded corners. + static func insets(_ size: CGSize) -> UIEdgeInsets { + let upright = size.height > size.width + switch (Int(min(size.width, size.height)), Int(max(size.width, size.height))) { + case (414, 896): return upright ? UIEdgeInsets(top: 48, left: 0, bottom: 34, right: 0) : UIEdgeInsets(top: 0, left: 48, bottom: 21, right: 48) + case (1024, 1366): return UIEdgeInsets(top: 24, left: 0, bottom: 20, right: 0) + case (768, _), (810, _): return UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0) + default: return upright ? UIEdgeInsets(top: 20, left: 0, bottom: 0, right: 0) : .zero + } + } + /// The problems of one screen: `make` builds its controller for a size (it may /// word the screen for the device of that size), laid out first in a tiny window, /// as a window can be before it gets its size, then at each size in turn. @@ -44,6 +57,16 @@ enum LayoutCheck { window.layoutIfNeeded() window.frame = CGRect(origin: .zero, size: size) window.layoutIfNeeded() + // The insets of the device of that size, not of the simulator the check runs in. + // Measured on the screen and corrected, as the window may report its own late. + let want = insets(size) + for _ in 0..<3 where controller.view.safeAreaInsets != want { + let have = controller.view.safeAreaInsets, extra = host.additionalSafeAreaInsets + host.additionalSafeAreaInsets = UIEdgeInsets(top: extra.top + want.top - have.top, left: extra.left + want.left - have.left, + bottom: extra.bottom + want.bottom - have.bottom, right: extra.right + want.right - have.right) + window.layoutIfNeeded() + } + if controller.view.safeAreaInsets != want { problems.append("\(screen) at \(Int(size.width))x\(Int(size.height)): the check could not set the device's insets (\(controller.view.safeAreaInsets))") } problems += check(controller.view, in: window).map { "\(screen) at \(Int(size.width))x\(Int(size.height)): \($0)" } // ORCHARD_LAYOUT_SHOTS=DIR: a picture of the screen, upright, at 2x, for review. if let dir = ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_SHOTS"], size.height > size.width {