Skip to content
Merged
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
23 changes: 23 additions & 0 deletions companion/App/LayoutCheck.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 {
Expand Down
Loading