From 183c2dc163f0e92149d5df1ab9ca6a2b9be0a342 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 12:37:59 +0800 Subject: [PATCH 1/4] iOS apps: every screen laid out with no width left to iOS, and checked On iOS 12 the companion's Storage access page drew its text a few letters wide and pushed Continue off the screen: the steps and the notice were 500 points wide only by a preference that tied with the text's own wish to be narrow, and iOS 12 broke the tie the other way from iOS 18. The companion's screens are now a column of blocks exactly as wide as the column (500 points, or what the margins leave), screens taller than the window scroll, and the margin follows the window rather than the screen. The in-app installer's scroll height, its Install button beside the offline line (iPad) and its dialogs on a phone on its side get the same. companion/App/LayoutCheck.swift lays every screen of both apps out at every iPhone, iPod touch and iPad size, upright and on its side, and fails on a wrapping text whose width moves when its own preference does (what broke on iOS 12, found on any iOS), on text broken inside a word or cut off, and on anything off the screen. companion/build.sh --check-layout and ios-installer/build-simulator.sh --check-layout run it; pull requests that change either app run both. Assisted-by: LLM --- .github/workflows/release.yml | 46 +++++++ CHANGELOG.md | 10 ++ companion/App/App.swift | 135 ++++++++++++++------- companion/App/AppDelegate.swift | 26 +++- companion/App/LayoutCheck.swift | 130 ++++++++++++++++++++ companion/build.sh | 12 +- companion/check-layout.sh | 20 +++ ios-installer/App/AppDelegate.swift | 13 ++ ios-installer/App/Components.swift | 4 +- ios-installer/App/Dialog.swift | 19 ++- ios-installer/App/Mock.swift | 7 ++ ios-installer/App/RootViewController.swift | 4 + ios-installer/build-simulator.sh | 8 +- 13 files changed, 378 insertions(+), 56 deletions(-) create mode 100644 companion/App/LayoutCheck.swift create mode 100755 companion/check-layout.sh diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0e67236b..148bde75 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -270,6 +270,52 @@ jobs: test -s "$RUNNER_TEMP/payload/out/apple-16k/linux.bin" grep -q 'apple-16k kernel: its source key matches' build.log + # Every screen of the companion and the in-app installer at the size of every + # iPhone, iPod touch and iPad (companion/App/LayoutCheck.swift): fails on a + # width the layout leaves to iOS (iOS 12 drew such a page two letters wide), + # broken or cut-off text and anything off the screen. Only when their code or + # the fonts change. + ios-layout: + name: Check the iOS screens' layout + if: github.event_name == 'pull_request' + runs-on: macos-15-intel + timeout-minutes: 20 + steps: + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + with: + persist-credentials: false + fetch-depth: 0 + + - name: See whether the screens changed + id: changed + env: + BASE: ${{ github.event.pull_request.base.sha }} + run: | + if git diff --quiet "$BASE" HEAD -- companion ios-installer crates/app/assets/fonts; then + echo "run=false" >> "$GITHUB_OUTPUT" + else + echo "run=true" >> "$GITHUB_OUTPUT" + echo "commit=$(sed -n 's/^RESIZE_APFS_COMMIT=//p' ios-installer/build.sh)" >> "$GITHUB_OUTPUT" + fi + + - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6 + if: steps.changed.outputs.run == 'true' + with: + repository: OrchardLinux/resize-apfs + ref: ${{ steps.changed.outputs.commit }} + path: resize-apfs + persist-credentials: false + + - name: The companion + if: steps.changed.outputs.run == 'true' + run: companion/build.sh --check-layout + + - name: The in-app installer + if: steps.changed.outputs.run == 'true' + env: + RESIZE_APFS: ${{ github.workspace }}/resize-apfs + run: ios-installer/build-simulator.sh --check-layout + companion: name: Build the iPad companion needs: plan diff --git a/CHANGELOG.md b/CHANGELOG.md index 47c5e04f..21f5b2f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,16 @@ program it changes. To release, rename `[Unreleased]` to the version and date and raise the version in Cargo.toml, in the same pull request: once it is on main, the release is published with that section as its notes (AGENTS.md, Releasing). +## [Unreleased] + +### Installer and launcher + +- On iOS 12 the app on the iPad or iPhone shows its Storage access page as + designed: its text was a column a few letters wide that pushed Continue + off the screen. Every screen of the app on the device and of the in-app + installer now fits every iPhone, iPod touch and iPad upright and on its + side, scrolling where a screen is taller than the display. + ## [0.3.19] - 2026-12-05 ### Installer and launcher diff --git a/companion/App/App.swift b/companion/App/App.swift index 953144ac..6cc38284 100644 --- a/companion/App/App.swift +++ b/companion/App/App.swift @@ -126,10 +126,8 @@ private func heading(_ title: String, _ text: String) -> UIView { label(text, sans(17), .body, lineSpacing: 8.5, center: true), ]) stack.axis = .vertical - stack.alignment = .center + stack.alignment = .fill stack.spacing = 12 - stack.translatesAutoresizingMaskIntoConstraints = false - stack.widthAnchor.constraint(lessThanOrEqualToConstant: 500).isActive = true return stack } @@ -157,30 +155,54 @@ private func row(_ views: [UIView], spacing: CGFloat) -> UIStackView { return stack } -/// The note under 2.7 and 2.7b. +/// The note under 2.7 and 2.7b: as wide as its line, or the column where that is less. private func keepNote() -> UIView { - framed(row([icon("plug", 16), label("Keep this app open and the cable connected.", sans(15), .body)], spacing: 10), - UIColor(0x1d1f2b), UIColor(0x292e42), vertical: 10, horizontal: 16) + let text = label("Keep this app open and the cable connected.", sans(15), .body) + let line = ceil(text.attributedText!.size().width) + let box = framed(row([icon("plug", 16), text], spacing: 10), UIColor(0x1d1f2b), UIColor(0x292e42), vertical: 10, horizontal: 16) + box.translatesAutoresizingMaskIntoConstraints = false + let natural = box.widthAnchor.constraint(equalToConstant: line + 16 + 10 + 2 * 16) + natural.priority = .required - 1 + natural.isActive = true + return centered(box) +} + +/// `view` in the middle of a block as wide as the column; never wider than it. +private func centered(_ view: UIView) -> UIView { + let block = UIView() + view.translatesAutoresizingMaskIntoConstraints = false + block.addSubview(view) + NSLayoutConstraint.activate([ + view.topAnchor.constraint(equalTo: block.topAnchor), + view.bottomAnchor.constraint(equalTo: block.bottomAnchor), + view.centerXAnchor.constraint(equalTo: block.centerXAnchor), + view.leadingAnchor.constraint(greaterThanOrEqualTo: block.leadingAnchor), + ]) + return block } +/// A screen's blocks, each exactly as wide as the column (StatusController gives it its +/// width): no text is left to pick its own width, which iOS versions pick differently +/// (iOS 12 made the Storage access page two letters wide). Blocks narrower than the +/// column go through `centered`. LayoutCheck.swift holds every screen to this. private func column(_ views: [UIView]) -> UIStackView { let stack = UIStackView(arrangedSubviews: views) stack.axis = .vertical - stack.alignment = .center + stack.alignment = .fill stack.spacing = 28 return stack } /// 2.7b: the computer hasn't connected yet. private func waiting() -> UIView { - column([badge(.accent, 0.08, fixed(Spinner(), 40, 40)), + column([centered(badge(.accent, 0.08, fixed(Spinner(), 40, 40))), heading("Waiting for your computer", "Orchard Installer continues once it reaches this iPad."), keepNote()]) } /// 2.7: the computer is connected and the split hasn't started. private func before(system: String) -> UIView { - column([badge(.accent, 0.12, icon("laptop", 38)), + column([centered(badge(.accent, 0.12, icon("laptop", 38))), heading("Continue on your computer", "Your iPad is connected to Orchard Installer. Choose how much space \(system) gets there."), keepNote()]) } @@ -195,22 +217,18 @@ private func splitting(minutes: UILabel) -> UIView { label("Your iPad may freeze or look idle for a while. That's normal, and it doesn't mean anything went wrong.", sans(14), .body, lineSpacing: 7), ]) rules.axis = .vertical - rules.alignment = .leading + rules.alignment = .fill rules.spacing = 16 let box = framed(rules, UIColor.amber.withAlphaComponent(0.05), UIColor.amber.withAlphaComponent(0.32), vertical: 24, horizontal: 24) - box.translatesAutoresizingMaskIntoConstraints = false - // 500 wide where the screen has the room. - let width = box.widthAnchor.constraint(equalToConstant: 500) - width.priority = .defaultHigh - width.isActive = true - return column([badge(.accent, 0.08, fixed(Spinner(), 40, 40)), + minutes.textAlignment = .center + return column([centered(badge(.accent, 0.08, fixed(Spinner(), 40, 40))), heading("Splitting the storage", "This can take around 30 minutes. Your computer shows how it's going."), minutes, box]) } /// 2.9: done. private func done() -> UIView { - column([badge(.ok, 0.12, icon("check", 38)), + column([centered(badge(.ok, 0.12, icon("check", 38))), heading("Done on your iPad", "The storage is split. Continue on your computer.")]) } @@ -231,15 +249,6 @@ private final class ActionButton: UIButton { @objc private func tapped() { action() } } -/// The width of the Storage access page's steps and notice (9.1): 500, or what a -/// narrower screen leaves. -private func wide(_ view: UIView) { - view.widthAnchor.constraint(lessThanOrEqualToConstant: 500).isActive = true - let wanted = view.widthAnchor.constraint(equalToConstant: 500) - wanted.priority = .defaultHigh - wanted.isActive = true -} - /// Some devices restart their screen once before access; nothing can open the app again /// then, and what that restart was for holds only about 20 seconds. In Amethyst (iOS 12 /// and 13) the first run restarts the whole device instead, and the app is opened again @@ -250,10 +259,7 @@ private func reopenNotice(_ restartsDevice: Bool) -> UIView { let text = label(line, sans(16, semibold: true), .rule, lineSpacing: 4) text.numberOfLines = 0 let content = row([icon("timer", 18), text], spacing: 14) - let box = framed(content, UIColor.amber.withAlphaComponent(0.05), UIColor.amber.withAlphaComponent(0.32), vertical: 18, horizontal: 24) - box.translatesAutoresizingMaskIntoConstraints = false - wide(box) - return box + return framed(content, UIColor.amber.withAlphaComponent(0.05), UIColor.amber.withAlphaComponent(0.32), vertical: 18, horizontal: 24) } /// Storage access (the app inside Dopamine, 9.1 and 9.2): with Continue, then with the @@ -264,22 +270,20 @@ private func storageAccess(working: Bool, restartsDevice: Bool, proceed: @escapi row([icon("arrow-right", 18), label($0, sans(16), .rule)], spacing: 14) }) steps.axis = .vertical - steps.alignment = .leading + steps.alignment = .fill steps.spacing = 12 - steps.translatesAutoresizingMaskIntoConstraints = false - wide(steps) - var views = [working ? badge(.accent, 0.08, fixed(Spinner(), 40, 40)) : badge(.accent, 0.12, icon("hard-drive", 38)), + var views = [centered(working ? badge(.accent, 0.08, fixed(Spinner(), 40, 40)) : badge(.accent, 0.12, icon("hard-drive", 38))), heading("Storage access", "Orchard Installer needs access to your device’s storage. This takes about a minute."), steps, reopenNotice(restartsDevice)] - if !working { views.append(ActionButton("Continue", action: proceed)) } + if !working { views.append(centered(ActionButton("Continue", action: proceed))) } return column(views) } /// 9.3. private func accessFailed(restartsDevice: Bool, retry: @escaping () -> Void) -> UIView { - column([badge(.red, 0.12, icon("x", 38)), + column([centered(badge(.red, 0.12, icon("x", 38))), heading("Couldn’t get storage access", "Your storage was not changed."), - reopenNotice(restartsDevice), ActionButton("Try again", action: retry)]) + reopenNotice(restartsDevice), centered(ActionButton("Try again", action: retry))]) } /// Shows the screen for the helper's status, read every second. Inside the Dopamine app @@ -306,7 +310,10 @@ final class StatusController: UIViewController { private let reading = DispatchQueue(label: "org.orchardlinux.companion.status") private var status: Status? private var shown: String? + /// The screen, in a scroll view for screens taller than the window (phones on their side). + private let scroll = UIScrollView() private let content = UIView() + private var margins: [NSLayoutConstraint] = [] private let minutes = label("", mono(14), .faint) private var timer: Timer? @@ -323,14 +330,28 @@ final class StatusController: UIViewController { super.viewDidLoad() view.backgroundColor = .background let footer = label("Orchard Installer", mono(12), .faint, center: true) - // A phone's screen has no room for the iPad's margin. - let margin: CGFloat = min(UIScreen.main.bounds.width, UIScreen.main.bounds.height) < 600 ? 24 : 72 - for v in [content, footer] { v.translatesAutoresizingMaskIntoConstraints = false; view.addSubview(v) } + footer.numberOfLines = 1 + scroll.contentInsetAdjustmentBehavior = .never + scroll.alwaysBounceVertical = false + scroll.showsHorizontalScrollIndicator = false + for v in [scroll, footer] { v.translatesAutoresizingMaskIntoConstraints = false; view.addSubview(v) } + content.translatesAutoresizingMaskIntoConstraints = false + scroll.addSubview(content) + // The content is as wide as the window and at least as high; higher scrolls. + let fit = content.heightAnchor.constraint(equalTo: scroll.frameLayoutGuide.heightAnchor) + fit.priority = .defaultLow NSLayoutConstraint.activate([ - content.topAnchor.constraint(equalTo: view.topAnchor), - content.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: margin), - content.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -margin), - content.bottomAnchor.constraint(equalTo: footer.topAnchor), + scroll.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), + scroll.leadingAnchor.constraint(equalTo: view.leadingAnchor), + scroll.trailingAnchor.constraint(equalTo: view.trailingAnchor), + scroll.bottomAnchor.constraint(equalTo: footer.topAnchor), + content.topAnchor.constraint(equalTo: scroll.contentLayoutGuide.topAnchor), + content.bottomAnchor.constraint(equalTo: scroll.contentLayoutGuide.bottomAnchor), + content.leadingAnchor.constraint(equalTo: scroll.contentLayoutGuide.leadingAnchor), + content.trailingAnchor.constraint(equalTo: scroll.contentLayoutGuide.trailingAnchor), + content.widthAnchor.constraint(equalTo: scroll.frameLayoutGuide.widthAnchor), + content.heightAnchor.constraint(greaterThanOrEqualTo: scroll.frameLayoutGuide.heightAnchor), + fit, footer.centerXAnchor.constraint(equalTo: view.centerXAnchor), footer.heightAnchor.constraint(equalToConstant: 72), footer.bottomAnchor.constraint(equalTo: view.bottomAnchor), @@ -343,6 +364,13 @@ final class StatusController: UIViewController { } } + /// A phone's screen has no room for the iPad's margin. + override func viewWillLayoutSubviews() { + super.viewWillLayoutSubviews() + let margin: CGFloat = min(view.bounds.width, view.bounds.height) < 600 ? 24 : 72 + for m in margins { m.constant = margin } + } + /// Reads the status and shows its screen when it changed. private func refresh() { guard gate == .open else { return } @@ -375,6 +403,13 @@ final class StatusController: UIViewController { case (.open, "idle"?, true?), (.open, "failed"?, true?): screen = "before" default: screen = "waiting" } + show(screen) + } + + /// The screens `show` knows (the layout check goes through all of them). + static let screens = ["access", "access-working", "access-failed", "waiting", "before", "splitting", "done"] + + func show(_ screen: String) { guard screen != shown else { return } shown = screen content.subviews.forEach { $0.removeFromSuperview() } @@ -390,11 +425,17 @@ final class StatusController: UIViewController { } view.translatesAutoresizingMaskIntoConstraints = false content.addSubview(view) - NSLayoutConstraint.activate([ + // The column: 500 wide, or what the margins leave. + let wanted = view.widthAnchor.constraint(equalTo: content.widthAnchor) + wanted.priority = .required - 1 + let margin: CGFloat = min(self.view.bounds.width, self.view.bounds.height) < 600 ? 24 : 72 + margins = [view.leadingAnchor.constraint(greaterThanOrEqualTo: content.leadingAnchor, constant: margin), + view.topAnchor.constraint(greaterThanOrEqualTo: content.topAnchor, constant: margin)] + NSLayoutConstraint.activate(margins + [ view.centerXAnchor.constraint(equalTo: content.centerXAnchor), view.centerYAnchor.constraint(equalTo: content.centerYAnchor), - view.leadingAnchor.constraint(greaterThanOrEqualTo: content.leadingAnchor), - view.trailingAnchor.constraint(lessThanOrEqualTo: content.trailingAnchor), + view.widthAnchor.constraint(lessThanOrEqualToConstant: 500), + wanted, ]) } } diff --git a/companion/App/AppDelegate.swift b/companion/App/AppDelegate.swift index 6218d3ee..1bd78a0c 100644 --- a/companion/App/AppDelegate.swift +++ b/companion/App/AppDelegate.swift @@ -2,7 +2,16 @@ import UIKit private func makeWindow(_ window: UIWindow) -> UIWindow { - let window = companionWindow(window, StatusController()) + #if targetEnvironment(simulator) + // The simulator shows the Storage access pages too, to check them. + let gates: [String: StatusController.Gate] = ["ask": .ask, "working": .working, "failed": .failed, "checking": .checking] + let env = ProcessInfo.processInfo.environment + let controller = StatusController(gate: env["ORCHARD_COMPANION_GATE"].flatMap { gates[$0] } ?? .open) + controller.restartsDevice = env["ORCHARD_COMPANION_RESTARTS"] != nil + #else + let controller = StatusController() + #endif + let window = companionWindow(window, controller) window.makeKeyAndVisible() return window } @@ -23,6 +32,21 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + #if targetEnvironment(simulator) + if ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_CHECK"] != nil { + LayoutCheck.finish([false, true].flatMap { restarts in + StatusController.screens.flatMap { screen in + LayoutCheck.problems(screen + (restarts ? " (restarts)" : "")) { _ in + let controller = StatusController(gate: .open) { nil } + controller.restartsDevice = restarts + controller.loadViewIfNeeded() + controller.show(screen) + return controller + } + } + }) + } + #endif application.isIdleTimerDisabled = true // iOS 12 has no scenes: the window is the app's own. if #available(iOS 13, *) {} else { window = makeWindow(UIWindow(frame: UIScreen.main.bounds)) } diff --git a/companion/App/LayoutCheck.swift b/companion/App/LayoutCheck.swift new file mode 100644 index 00000000..f590dc3c --- /dev/null +++ b/companion/App/LayoutCheck.swift @@ -0,0 +1,130 @@ +// The layout check of the companion and the in-app installer (companion/build.sh +// --check-layout, ios-installer/build-simulator.sh --check-layout): every screen at +// the size of every iPhone, iPod touch and iPad, upright and on its side. It fails +// on what went wrong on devices before: a width Auto Layout has to pick by itself +// (iOS 12 picked about two letters for the Storage access page), text broken inside +// a word or cut off, anything outside the screen. Simulator only; each app's +// AppDelegate.swift lists its screens. +#if targetEnvironment(simulator) +import UIKit + +enum LayoutCheck { + /// Points: iPhone SE (1st) and iPod touch (6th), iPhone 8, iPhone XR, iPad mini + /// and iPad 9.7", iPad 10.2", iPad Pro 12.9"; upright and on their side. + static let sizes: [CGSize] = { + let upright = [CGSize(width: 320, height: 568), CGSize(width: 375, height: 667), + CGSize(width: 414, height: 896), CGSize(width: 768, height: 1024), + CGSize(width: 810, height: 1080), CGSize(width: 1024, height: 1366)] + return upright + upright.map { CGSize(width: $0.height, height: $0.width) } + }() + + /// 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. + static func problems(_ screen: String, sizes: [CGSize] = sizes, _ make: (CGSize) -> UIViewController) -> [String] { + var problems: [String] = [] + for size in sizes { + let controller = make(size) + let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) + window.rootViewController = controller + window.isHidden = false + window.layoutIfNeeded() + window.frame = CGRect(origin: .zero, size: size) + window.layoutIfNeeded() + problems += check(controller.view, in: window).map { "\(screen) at \(Int(size.width))x\(Int(size.height)): \($0)" } + window.isHidden = true + } + return problems + } + + /// Prints the problems and ends the app: status 0 without any. + static func finish(_ problems: [String]) -> Never { + problems.forEach { print("LAYOUT: \($0)") } + print(problems.isEmpty ? "LAYOUT OK" : "LAYOUT FAILED: \(problems.count) problems") + exit(problems.isEmpty ? 0 : 1) + } + + private static func describe(_ view: UIView) -> String { + if let label = view as? UILabel { return "label \"\(label.text ?? "")\"" } + return String(describing: type(of: view)) + } + + private static func labels(_ view: UIView) -> [UILabel] { + (view as? UILabel).map { [$0] } ?? view.subviews.flatMap(labels) + } + + /// Text that wraps must get its width from the layout, never from its own wish + /// to be narrow or wide: where that wish decides, iOS versions decide differently + /// (iOS 12 made the Storage access page's text about two letters wide). So each + /// such label is laid out wanting no width, then all it can get, and must not move. + private static func undecided(_ root: UIView, in window: UIWindow) -> [String] { + let wrapping = labels(root).filter { $0.numberOfLines != 1 && !($0.text ?? "").isEmpty } + let saved = wrapping.map { ($0.contentHuggingPriority(for: .horizontal), $0.contentCompressionResistancePriority(for: .horizontal)) } + func widths(hug: UILayoutPriority, resist: UILayoutPriority) -> [CGFloat] { + for label in wrapping { + label.setContentHuggingPriority(hug, for: .horizontal) + label.setContentCompressionResistancePriority(resist, for: .horizontal) + label.invalidateIntrinsicContentSize() + } + root.setNeedsLayout() + window.layoutIfNeeded() + return wrapping.map { $0.bounds.width } + } + // 990: far above the system's own 750 and 250, below the 999 a screen + // decides a width with (StatusController's column, keepNote). + let narrow = widths(hug: UILayoutPriority(990), resist: UILayoutPriority(1)) + let wide = widths(hug: UILayoutPriority(1), resist: UILayoutPriority(990)) + for (label, (hug, resist)) in zip(wrapping, saved) { + label.setContentHuggingPriority(hug, for: .horizontal) + label.setContentCompressionResistancePriority(resist, for: .horizontal) + } + root.setNeedsLayout() + window.layoutIfNeeded() + return zip(wrapping, zip(narrow, wide)).compactMap { label, w in + abs(w.0 - w.1) > 0.5 ? "\(describe(label)) has no width of its own: \(Int(w.0)) to \(Int(w.1)), as the system picks" : nil + } + } + + private static func check(_ root: UIView, in window: UIWindow) -> [String] { + var problems = undecided(root, in: window) + func visit(_ view: UIView, clip: CGRect) { + guard !view.isHidden, view.alpha > 0 else { return } + let frame = view.convert(view.bounds, to: window) + if view.hasAmbiguousLayout { problems.append("\(describe(view)) has no definite size or place") } + if frame.minX < clip.minX - 0.5 || frame.maxX > clip.maxX + 0.5 || frame.minY < clip.minY - 0.5 || frame.maxY > clip.maxY + 0.5 { + problems.append("\(describe(view)) at \(frame) is outside \(clip)") + } + if let label = view as? UILabel, let text = label.attributedText, text.length > 0 { + // Each word as the label draws it: its own attributes, on one line. + let string = text.string as NSString + var at = 0 + while at < string.length { + let space = string.rangeOfCharacter(from: .whitespacesAndNewlines, options: [], range: NSRange(location: at, length: string.length - at)) + let end = space.location == NSNotFound ? string.length : space.location + if end > at { + let word = text.attributedSubstring(from: NSRange(location: at, length: end - at)) + let width = word.boundingRect(with: CGSize(width: CGFloat.greatestFiniteMagnitude, height: .greatestFiniteMagnitude), + options: [.usesLineFragmentOrigin], context: nil).width + if width > label.bounds.width + 0.5 { + problems.append("\(describe(view)) is \(Int(label.bounds.width)) wide, which breaks \"\(word.string)\" (\(Int(ceil(width))) wide)") + break + } + } + at = end + 1 + } + let needed = label.sizeThatFits(CGSize(width: label.bounds.width, height: .greatestFiniteMagnitude)).height + if needed > label.bounds.height + 1 { problems.append("\(describe(view)) is cut off (\(Int(label.bounds.height)) of \(Int(needed)) high)") } + } + // A scroll view's content may go past its frame, vertically only. + var inner = clip + if let scroll = view as? UIScrollView { + if scroll.contentSize.width > scroll.bounds.width + 0.5 { problems.append("scrolls sideways (\(scroll.contentSize.width) in \(scroll.bounds.width))") } + inner = CGRect(x: frame.minX, y: -.greatestFiniteMagnitude / 2, width: frame.width, height: .greatestFiniteMagnitude) + } + view.subviews.forEach { visit($0, clip: inner) } + } + visit(root, clip: window.bounds) + return problems + } +} +#endif diff --git a/companion/build.sh b/companion/build.sh index cee7d16e..8ec5a956 100755 --- a/companion/build.sh +++ b/companion/build.sh @@ -19,16 +19,20 @@ set -euo pipefail cd "$(dirname "$0")" # --simulator: only the app, for the iOS simulator, to check the screens. -if [ "${1:-}" = "--simulator" ]; then +# --check-layout: that app's layout check (App/LayoutCheck.swift) in a simulator: +# every screen at every device size; fails on any problem it prints. +if [ "${1:-}" = "--simulator" ] || [ "${1:-}" = "--check-layout" ]; then app=$PWD/out-simulator/OrchardCompanion.app rm -rf "$app" && mkdir -p "$app/Fonts" "$app/Icons" - xcrun --sdk iphonesimulator swiftc -target arm64-apple-ios15.0-simulator -sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" \ - -swift-version 5 -O -parse-as-library App/App.swift App/AppDelegate.swift -o "$app/OrchardCompanion" + arch=$(uname -m) + xcrun --sdk iphonesimulator swiftc -target "$arch-apple-ios15.0-simulator" -sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" \ + -swift-version 5 -O -parse-as-library App/App.swift App/AppDelegate.swift App/LayoutCheck.swift -o "$app/OrchardCompanion" cp App/Info.plist "$app/" && plutil -replace CFBundleSupportedPlatforms -json '["iPhoneSimulator"]' "$app/Info.plist" cp ../crates/app/assets/fonts/*.ttf "$app/Fonts/" && cp App/Icons/*.png "$app/Icons/" codesign --force --sign - --timestamp=none "$app" echo "Built $app" - exit 0 + [ "$1" = "--check-layout" ] || exit 0 + exec ./check-layout.sh "$app" org.orchardlinux.companion fi RESIZE_APFS_COMMIT=ade540a2dd457173d85e11e73cfe4293cc5b4696 resize=${RESIZE_APFS:-$PWD/../../worktrees/resize-shared-access} diff --git a/companion/check-layout.sh b/companion/check-layout.sh new file mode 100755 index 00000000..55be9f11 --- /dev/null +++ b/companion/check-layout.sh @@ -0,0 +1,20 @@ +#!/bin/bash +# Runs the layout check (App/LayoutCheck.swift) of a simulator build of the +# companion or the in-app installer: check-layout.sh APP BUNDLE-ID. Any simulator +# does, as the check sets every size itself; one already booted is used as it is. +# Prints every problem; fails on any. +set -euo pipefail +app=$1 id=$2 +udid() { plutil -extract devices json -o - - | grep -o '"udid" *: *"[^"]*"' | head -1 | cut -d'"' -f4; } +device=$(xcrun simctl list devices booted -j | udid) +if [ -z "$device" ]; then + device=$(xcrun simctl list devices available -j | udid) + [ -n "$device" ] || { echo 'No iOS simulator available' >&2; exit 1; } + xcrun simctl boot "$device" + trap 'xcrun simctl shutdown "$device"' EXIT +fi +xcrun simctl bootstatus "$device" -b >/dev/null +xcrun simctl install "$device" "$app" +log=$(SIMCTL_CHILD_ORCHARD_LAYOUT_CHECK=1 xcrun simctl launch --console --terminate-running-process "$device" "$id" 2>&1) +echo "$log" | grep '^LAYOUT' || { echo "$log" | tail -20; exit 1; } +echo "$log" | grep -qx 'LAYOUT OK' diff --git a/ios-installer/App/AppDelegate.swift b/ios-installer/App/AppDelegate.swift index 450f36d5..52f05b72 100644 --- a/ios-installer/App/AppDelegate.swift +++ b/ios-installer/App/AppDelegate.swift @@ -28,6 +28,19 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { + #if targetEnvironment(simulator) + // build-simulator.sh --check-layout: every frame at every size (LayoutCheck.swift in companion/App). + if ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_CHECK"] != nil { + LayoutCheck.finish(Mock.frames.flatMap { frame in + LayoutCheck.problems(frame) { size in + Mock.kindOverride = min(size.width, size.height) >= 600 ? "iPad" : size.width == 320 || size.height == 320 ? "iPod touch" : "iPhone" + let controller = RootViewController(mock: frame) + controller.loadViewIfNeeded() + return controller + } + }) + } + #endif // iOS 12 has no scenes: the window is the app's own. if #available(iOS 13, *) {} else { window = makeWindow(UIWindow(frame: UIScreen.main.bounds)) } return true diff --git a/ios-installer/App/Components.swift b/ios-installer/App/Components.swift index 4133579f..708e7a80 100644 --- a/ios-installer/App/Components.swift +++ b/ios-installer/App/Components.swift @@ -40,8 +40,10 @@ final class ActionButton: UIControl { label.leadingAnchor.constraint(greaterThanOrEqualTo: leadingAnchor, constant: padding), ]) if hug { + // Exactly as wide as its title: a line beside it (I3.3 on iPad) gets the rest. label.leadingAnchor.constraint(equalTo: leadingAnchor, constant: padding).isActive = true - setContentHuggingPriority(.required, for: .horizontal) + label.setContentHuggingPriority(.required, for: .horizontal) + label.setContentCompressionResistancePriority(.required, for: .horizontal) } addTarget(self, action: #selector(tapped), for: .touchUpInside) isAccessibilityElement = true diff --git a/ios-installer/App/Dialog.swift b/ios-installer/App/Dialog.swift index 5591da85..99cbee62 100644 --- a/ios-installer/App/Dialog.swift +++ b/ios-installer/App/Dialog.swift @@ -46,12 +46,29 @@ final class DialogView: UIView { eraseAlert(m, partitions), approve, buttons]) column.setCustomSpacing(24, after: approve) let padding: CGFloat = m.pick(28, 20, 20) - embed(column, in: box, UIEdgeInsets(top: padding, left: padding, bottom: padding, right: padding)) + // Where the screen is lower than the dialog (a phone on its side), the dialog scrolls. + let scroll = UIScrollView() + scroll.alwaysBounceVertical = false + scroll.indicatorStyle = .white + scroll.contentInsetAdjustmentBehavior = .never + embed(scroll, in: box, .zero) + column.translatesAutoresizingMaskIntoConstraints = false + scroll.addSubview(column) + let fit = scroll.frameLayoutGuide.heightAnchor.constraint(equalTo: scroll.contentLayoutGuide.heightAnchor) + // Below the text's own height (750): the dialog never squeezes its text, it scrolls. + fit.priority = UILayoutPriority(500) box.translatesAutoresizingMaskIntoConstraints = false addSubview(box) NSLayoutConstraint.activate([ + column.topAnchor.constraint(equalTo: scroll.contentLayoutGuide.topAnchor, constant: padding), + column.bottomAnchor.constraint(equalTo: scroll.contentLayoutGuide.bottomAnchor, constant: -padding), + column.leadingAnchor.constraint(equalTo: scroll.contentLayoutGuide.leadingAnchor, constant: padding), + column.trailingAnchor.constraint(equalTo: scroll.contentLayoutGuide.trailingAnchor, constant: -padding), + column.widthAnchor.constraint(equalTo: scroll.frameLayoutGuide.widthAnchor, constant: -2 * padding), + fit, box.centerXAnchor.constraint(equalTo: centerXAnchor), box.centerYAnchor.constraint(equalTo: centerYAnchor), box.widthAnchor.constraint(equalToConstant: m.pick(480, m.screenWidth - 32, m.screenWidth - 16)), + box.heightAnchor.constraint(lessThanOrEqualTo: heightAnchor, constant: -16), ]) } required init?(coder: NSCoder) { fatalError() } diff --git a/ios-installer/App/Mock.swift b/ios-installer/App/Mock.swift index 8c4bb44d..e3d0ddfa 100644 --- a/ios-installer/App/Mock.swift +++ b/ios-installer/App/Mock.swift @@ -18,8 +18,15 @@ enum Mock { return parts.count == 2 ? CGSize(width: parts[0], height: parts[1]) : nil } + /// The frames, in the design's order. + static let frames = ["A0.1", "A0.2", "A0.3", "I0.1", "I0.2"] + (1...8).map { "I1.\($0)" } + (1...3).map { "I2.\($0)" } + (1...8).map { "I3.\($0)" } + + /// The device the layout check words the frames for, at each size. + static var kindOverride: String? + /// `--mock-kind "iPod touch"`: the device the frames are worded for. private static var kind: String { + if let kind = kindOverride { return kind } let arguments = ProcessInfo.processInfo.arguments if let index = arguments.firstIndex(of: "--mock-kind"), index + 1 < arguments.count { return arguments[index + 1] } return UIDevice.current.userInterfaceIdiom == .pad ? "iPad" : "iPhone" diff --git a/ios-installer/App/RootViewController.swift b/ios-installer/App/RootViewController.swift index 18813951..84e3922a 100644 --- a/ios-installer/App/RootViewController.swift +++ b/ios-installer/App/RootViewController.swift @@ -70,6 +70,9 @@ final class RootViewController: UIViewController { for child in [scroll, footer] { child.translatesAutoresizingMaskIntoConstraints = false; view.addSubview(child) } content.translatesAutoresizingMaskIntoConstraints = false scroll.addSubview(content) + // As high as the screen, unless the column needs more: then it scrolls. + let fit = content.heightAnchor.constraint(equalTo: scroll.frameLayoutGuide.heightAnchor) + fit.priority = .defaultLow footerHeight = scroll.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -72) footerCenter = footer.centerYAnchor.constraint(equalTo: view.bottomAnchor, constant: -36) NSLayoutConstraint.activate([ @@ -82,6 +85,7 @@ final class RootViewController: UIViewController { content.trailingAnchor.constraint(equalTo: scroll.contentLayoutGuide.trailingAnchor), content.widthAnchor.constraint(equalTo: scroll.frameLayoutGuide.widthAnchor), content.heightAnchor.constraint(greaterThanOrEqualTo: scroll.frameLayoutGuide.heightAnchor), + fit, ]) let tap = UITapGestureRecognizer(target: self, action: #selector(backgroundTapped)) tap.cancelsTouchesInView = false diff --git a/ios-installer/build-simulator.sh b/ios-installer/build-simulator.sh index 909ecbae..e963d98d 100755 --- a/ios-installer/build-simulator.sh +++ b/ios-installer/build-simulator.sh @@ -4,6 +4,8 @@ # then `xcrun simctl launch booted org.orchardlinux.installer --mock I1.2`. # First the sources are compiled for arm64 iOS 12.0 as the device build does # (nothing is kept), so an API newer than iOS 12 fails here too. +# --check-layout: then the layout check (../companion/App/LayoutCheck.swift): +# every frame at every device size; fails on any problem it prints. set -euo pipefail cd "$(dirname "$0")" # resize-apfs's code for the app inside Dopamine, which the screens name (see build.sh). @@ -14,8 +16,8 @@ xcrun --sdk iphoneos swiftc -target arm64-apple-ios12.0 -sdk "$(xcrun --sdk ipho app=$PWD/out-simulator/OrchardInstaller.app rm -rf "$app" && mkdir -p "$app/Fonts" -xcrun --sdk iphonesimulator swiftc -target arm64-apple-ios15.0-simulator -sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" \ - -swift-version 5 -O -parse-as-library App/*.swift "$access" -o "$app/OrchardInstaller" +xcrun --sdk iphonesimulator swiftc -target "$(uname -m)-apple-ios15.0-simulator" -sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" \ + -swift-version 5 -O -parse-as-library App/*.swift ../companion/App/LayoutCheck.swift "$access" -o "$app/OrchardInstaller" cp App/Info.plist "$app/" && plutil -replace CFBundleSupportedPlatforms -json '["iPhoneSimulator"]' "$app/Info.plist" cp ../crates/app/assets/fonts/*.ttf "$app/Fonts/" # The wordmark of what an unstamped installer installs. @@ -25,3 +27,5 @@ xcrun ibtool --minimum-deployment-target 12.0 --target-device iphone --target-de --compile "$app/LaunchScreen.storyboardc" App/Launch/LaunchScreen.storyboard >/dev/null codesign --force --sign - --timestamp=none "$app" echo "Built $app" +[ "${1:-}" = "--check-layout" ] || exit 0 +exec ../companion/check-layout.sh "$app" org.orchardlinux.installer From 7b8d9f6cfd807e0bba004372c1c34c777e876387 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 12:44:21 +0800 Subject: [PATCH 2/4] Layout check: boot a simulator where none runs, and save pictures on request Without a booted simulator the device lookup ended the script silently (grep found nothing under pipefail), as on the CI's Mac. ORCHARD_LAYOUT_SHOTS=DIR saves every screen at every upright size. Assisted-by: LLM --- companion/App/LayoutCheck.swift | 8 ++++++++ companion/check-layout.sh | 5 ++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/companion/App/LayoutCheck.swift b/companion/App/LayoutCheck.swift index f590dc3c..885c35fb 100644 --- a/companion/App/LayoutCheck.swift +++ b/companion/App/LayoutCheck.swift @@ -32,6 +32,14 @@ enum LayoutCheck { window.frame = CGRect(origin: .zero, size: size) window.layoutIfNeeded() 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 { + let format = UIGraphicsImageRendererFormat() + format.scale = 2 + let image = UIGraphicsImageRenderer(bounds: window.bounds, format: format).image { window.layer.render(in: $0.cgContext) } + let name = screen.replacingOccurrences(of: " ", with: "_").replacingOccurrences(of: "(", with: "").replacingOccurrences(of: ")", with: "") + try? image.pngData()?.write(to: URL(fileURLWithPath: "\(dir)/\(name)@\(Int(size.width))x\(Int(size.height)).png")) + } window.isHidden = true } return problems diff --git a/companion/check-layout.sh b/companion/check-layout.sh index 55be9f11..ea86375f 100755 --- a/companion/check-layout.sh +++ b/companion/check-layout.sh @@ -5,16 +5,19 @@ # Prints every problem; fails on any. set -euo pipefail app=$1 id=$2 -udid() { plutil -extract devices json -o - - | grep -o '"udid" *: *"[^"]*"' | head -1 | cut -d'"' -f4; } +udid() { plutil -extract devices json -o - - | { grep -o '"udid" *: *"[^"]*"' || true; } | head -1 | cut -d'"' -f4; } device=$(xcrun simctl list devices booted -j | udid) if [ -z "$device" ]; then device=$(xcrun simctl list devices available -j | udid) [ -n "$device" ] || { echo 'No iOS simulator available' >&2; exit 1; } + echo "Booting simulator $device" xcrun simctl boot "$device" trap 'xcrun simctl shutdown "$device"' EXIT fi xcrun simctl bootstatus "$device" -b >/dev/null xcrun simctl install "$device" "$app" +# ORCHARD_LAYOUT_SHOTS=DIR: also a picture of every screen at every upright size there. +[ -z "${ORCHARD_LAYOUT_SHOTS:-}" ] || { mkdir -p "$ORCHARD_LAYOUT_SHOTS"; export SIMCTL_CHILD_ORCHARD_LAYOUT_SHOTS=$ORCHARD_LAYOUT_SHOTS; } log=$(SIMCTL_CHILD_ORCHARD_LAYOUT_CHECK=1 xcrun simctl launch --console --terminate-running-process "$device" "$id" 2>&1) echo "$log" | grep '^LAYOUT' || { echo "$log" | tail -20; exit 1; } echo "$log" | grep -qx 'LAYOUT OK' From 2db4236b5e4f6126b80dab24c4dca2d1d66d4c13 Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 12:51:49 +0800 Subject: [PATCH 3/4] Layout check: each size with its device's size classes An iPad is regular both ways, a phone compact across and compact high on its side; screens that follow the size class are checked as they show. Assisted-by: LLM --- companion/App/LayoutCheck.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/companion/App/LayoutCheck.swift b/companion/App/LayoutCheck.swift index 885c35fb..e90bf397 100644 --- a/companion/App/LayoutCheck.swift +++ b/companion/App/LayoutCheck.swift @@ -26,7 +26,20 @@ enum LayoutCheck { for size in sizes { let controller = make(size) let window = UIWindow(frame: CGRect(x: 0, y: 0, width: 100, height: 100)) - window.rootViewController = controller + // The size classes of the device of that size (an iPad is regular both ways; + // a phone is compact across, and compact high on its side). + let host = UIViewController() + host.addChild(controller) + controller.view.frame = host.view.bounds + controller.view.autoresizingMask = [.flexibleWidth, .flexibleHeight] + host.view.addSubview(controller.view) + controller.didMove(toParent: host) + let pad = min(size.width, size.height) >= 600 + host.setOverrideTraitCollection(UITraitCollection(traitsFrom: [ + UITraitCollection(horizontalSizeClass: pad ? .regular : .compact), + UITraitCollection(verticalSizeClass: pad || size.height > size.width ? .regular : .compact), + UITraitCollection(userInterfaceIdiom: pad ? .pad : .phone)]), forChild: controller) + window.rootViewController = host window.isHidden = false window.layoutIfNeeded() window.frame = CGRect(origin: .zero, size: size) From 725ab19c71244ba59669c80df1e25d9550b9517f Mon Sep 17 00:00:00 2001 From: Henrik Klee Date: Sat, 5 Dec 2026 13:04:54 +0800 Subject: [PATCH 4/4] iOS apps: the footer follows the screen instead of standing over it The footer was pinned to the bottom of the window, over a screen taller than the window (an iPod touch, a phone on its side). It is now part of what scrolls: at the bottom where there is room, after the screen where there isn't. The layout check runs once the app has launched, as iOS ends an app whose launch takes as long as the check does on a slow Mac. Assisted-by: LLM --- companion/App/App.swift | 33 ++++++++++++++++------ companion/App/AppDelegate.swift | 5 ++-- companion/App/LayoutCheck.swift | 7 +++++ ios-installer/App/AppDelegate.swift | 5 ++-- ios-installer/App/RootViewController.swift | 22 ++++++++++----- 5 files changed, 53 insertions(+), 19 deletions(-) diff --git a/companion/App/App.swift b/companion/App/App.swift index 6cc38284..66bdc8a8 100644 --- a/companion/App/App.swift +++ b/companion/App/App.swift @@ -310,9 +310,15 @@ final class StatusController: UIViewController { private let reading = DispatchQueue(label: "org.orchardlinux.companion.status") private var status: Status? private var shown: String? - /// The screen, in a scroll view for screens taller than the window (phones on their side). + /// The screen and the footer under it, in a scroll view for screens taller than the + /// window (phones on their side): the footer is at the bottom where there is room + /// and follows the screen where there isn't, never over it. private let scroll = UIScrollView() private let content = UIView() + /// The room above the footer, which the screen is centred in. + private let area = UIView() + /// The screen shown now, in the content beside the footer. + private var screenView: UIView? private var margins: [NSLayoutConstraint] = [] private let minutes = label("", mono(14), .faint) private var timer: Timer? @@ -334,9 +340,14 @@ final class StatusController: UIViewController { scroll.contentInsetAdjustmentBehavior = .never scroll.alwaysBounceVertical = false scroll.showsHorizontalScrollIndicator = false - for v in [scroll, footer] { v.translatesAutoresizingMaskIntoConstraints = false; view.addSubview(v) } + scroll.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(scroll) content.translatesAutoresizingMaskIntoConstraints = false scroll.addSubview(content) + footer.translatesAutoresizingMaskIntoConstraints = false + content.addSubview(footer) + area.translatesAutoresizingMaskIntoConstraints = false + content.addSubview(area) // The content is as wide as the window and at least as high; higher scrolls. let fit = content.heightAnchor.constraint(equalTo: scroll.frameLayoutGuide.heightAnchor) fit.priority = .defaultLow @@ -344,7 +355,7 @@ final class StatusController: UIViewController { scroll.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), scroll.leadingAnchor.constraint(equalTo: view.leadingAnchor), scroll.trailingAnchor.constraint(equalTo: view.trailingAnchor), - scroll.bottomAnchor.constraint(equalTo: footer.topAnchor), + scroll.bottomAnchor.constraint(equalTo: view.bottomAnchor), content.topAnchor.constraint(equalTo: scroll.contentLayoutGuide.topAnchor), content.bottomAnchor.constraint(equalTo: scroll.contentLayoutGuide.bottomAnchor), content.leadingAnchor.constraint(equalTo: scroll.contentLayoutGuide.leadingAnchor), @@ -352,9 +363,13 @@ final class StatusController: UIViewController { content.widthAnchor.constraint(equalTo: scroll.frameLayoutGuide.widthAnchor), content.heightAnchor.constraint(greaterThanOrEqualTo: scroll.frameLayoutGuide.heightAnchor), fit, - footer.centerXAnchor.constraint(equalTo: view.centerXAnchor), + area.topAnchor.constraint(equalTo: content.topAnchor), + area.leadingAnchor.constraint(equalTo: content.leadingAnchor), + area.trailingAnchor.constraint(equalTo: content.trailingAnchor), + area.bottomAnchor.constraint(equalTo: footer.topAnchor), + footer.centerXAnchor.constraint(equalTo: content.centerXAnchor), footer.heightAnchor.constraint(equalToConstant: 72), - footer.bottomAnchor.constraint(equalTo: view.bottomAnchor), + footer.bottomAnchor.constraint(equalTo: content.bottomAnchor), ]) render() refresh() @@ -412,7 +427,7 @@ final class StatusController: UIViewController { func show(_ screen: String) { guard screen != shown else { return } shown = screen - content.subviews.forEach { $0.removeFromSuperview() } + screenView?.removeFromSuperview() let view: UIView switch screen { case "access": view = storageAccess(working: false, restartsDevice: restartsDevice) { [weak self] in self?.proceed() } @@ -425,15 +440,17 @@ final class StatusController: UIViewController { } view.translatesAutoresizingMaskIntoConstraints = false content.addSubview(view) + screenView = view // The column: 500 wide, or what the margins leave. let wanted = view.widthAnchor.constraint(equalTo: content.widthAnchor) wanted.priority = .required - 1 let margin: CGFloat = min(self.view.bounds.width, self.view.bounds.height) < 600 ? 24 : 72 margins = [view.leadingAnchor.constraint(greaterThanOrEqualTo: content.leadingAnchor, constant: margin), - view.topAnchor.constraint(greaterThanOrEqualTo: content.topAnchor, constant: margin)] + view.topAnchor.constraint(greaterThanOrEqualTo: area.topAnchor, constant: margin), + area.bottomAnchor.constraint(greaterThanOrEqualTo: view.bottomAnchor, constant: margin)] NSLayoutConstraint.activate(margins + [ view.centerXAnchor.constraint(equalTo: content.centerXAnchor), - view.centerYAnchor.constraint(equalTo: content.centerYAnchor), + view.centerYAnchor.constraint(equalTo: area.centerYAnchor), view.widthAnchor.constraint(lessThanOrEqualToConstant: 500), wanted, ]) diff --git a/companion/App/AppDelegate.swift b/companion/App/AppDelegate.swift index 1bd78a0c..c5acb326 100644 --- a/companion/App/AppDelegate.swift +++ b/companion/App/AppDelegate.swift @@ -34,7 +34,7 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { #if targetEnvironment(simulator) if ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_CHECK"] != nil { - LayoutCheck.finish([false, true].flatMap { restarts in + LayoutCheck.start { [false, true].flatMap { restarts in StatusController.screens.flatMap { screen in LayoutCheck.problems(screen + (restarts ? " (restarts)" : "")) { _ in let controller = StatusController(gate: .open) { nil } @@ -44,7 +44,8 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { return controller } } - }) + }} + return true } #endif application.isIdleTimerDisabled = true diff --git a/companion/App/LayoutCheck.swift b/companion/App/LayoutCheck.swift index e90bf397..c3d73f6c 100644 --- a/companion/App/LayoutCheck.swift +++ b/companion/App/LayoutCheck.swift @@ -58,8 +58,15 @@ enum LayoutCheck { return problems } + /// Runs `check` once the app has launched (iOS ends an app whose launch takes as long + /// as the check does on a slow Mac), then prints its problems and ends the app. + static func start(_ check: @escaping () -> [String]) { + DispatchQueue.main.async { finish(check()) } + } + /// Prints the problems and ends the app: status 0 without any. static func finish(_ problems: [String]) -> Never { + setvbuf(stdout, nil, _IOLBF, 0) problems.forEach { print("LAYOUT: \($0)") } print(problems.isEmpty ? "LAYOUT OK" : "LAYOUT FAILED: \(problems.count) problems") exit(problems.isEmpty ? 0 : 1) diff --git a/ios-installer/App/AppDelegate.swift b/ios-installer/App/AppDelegate.swift index 52f05b72..aac38e62 100644 --- a/ios-installer/App/AppDelegate.swift +++ b/ios-installer/App/AppDelegate.swift @@ -31,14 +31,15 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { #if targetEnvironment(simulator) // build-simulator.sh --check-layout: every frame at every size (LayoutCheck.swift in companion/App). if ProcessInfo.processInfo.environment["ORCHARD_LAYOUT_CHECK"] != nil { - LayoutCheck.finish(Mock.frames.flatMap { frame in + LayoutCheck.start { Mock.frames.flatMap { frame in LayoutCheck.problems(frame) { size in Mock.kindOverride = min(size.width, size.height) >= 600 ? "iPad" : size.width == 320 || size.height == 320 ? "iPod touch" : "iPhone" let controller = RootViewController(mock: frame) controller.loadViewIfNeeded() return controller } - }) + }} + return true } #endif // iOS 12 has no scenes: the window is the app's own. diff --git a/ios-installer/App/RootViewController.swift b/ios-installer/App/RootViewController.swift index 84e3922a..8a54927a 100644 --- a/ios-installer/App/RootViewController.swift +++ b/ios-installer/App/RootViewController.swift @@ -18,6 +18,9 @@ final class RootViewController: UIViewController { private let scroll = UIScrollView() private let content = UIView() + /// The room above the footer, which the column is centred in. The footer is part of + /// the content: at the bottom where there is room, after the column where there isn't. + private let area = UIView() private let footer = text("Orchard Installer", Theme.mono(12), Theme.comment, lines: 1) private var footerHeight: NSLayoutConstraint! private var footerCenter: NSLayoutConstraint! @@ -67,18 +70,23 @@ final class RootViewController: UIViewController { scroll.keyboardDismissMode = .interactive scroll.indicatorStyle = .white scroll.contentInsetAdjustmentBehavior = .never - for child in [scroll, footer] { child.translatesAutoresizingMaskIntoConstraints = false; view.addSubview(child) } + scroll.translatesAutoresizingMaskIntoConstraints = false + view.addSubview(scroll) content.translatesAutoresizingMaskIntoConstraints = false scroll.addSubview(content) + for child in [area, footer] { child.translatesAutoresizingMaskIntoConstraints = false; content.addSubview(child) } // As high as the screen, unless the column needs more: then it scrolls. let fit = content.heightAnchor.constraint(equalTo: scroll.frameLayoutGuide.heightAnchor) fit.priority = .defaultLow - footerHeight = scroll.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -72) - footerCenter = footer.centerYAnchor.constraint(equalTo: view.bottomAnchor, constant: -36) + footerHeight = area.bottomAnchor.constraint(equalTo: content.bottomAnchor, constant: -72) + footerCenter = footer.centerYAnchor.constraint(equalTo: content.bottomAnchor, constant: -36) NSLayoutConstraint.activate([ scroll.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor), scroll.leadingAnchor.constraint(equalTo: view.leadingAnchor), scroll.trailingAnchor.constraint(equalTo: view.trailingAnchor), - footerHeight, footerCenter, footer.centerXAnchor.constraint(equalTo: view.centerXAnchor), + scroll.bottomAnchor.constraint(equalTo: view.bottomAnchor), + area.topAnchor.constraint(equalTo: content.topAnchor), + area.leadingAnchor.constraint(equalTo: content.leadingAnchor), area.trailingAnchor.constraint(equalTo: content.trailingAnchor), + footerHeight, footerCenter, footer.centerXAnchor.constraint(equalTo: content.centerXAnchor), content.topAnchor.constraint(equalTo: scroll.contentLayoutGuide.topAnchor), content.bottomAnchor.constraint(equalTo: scroll.contentLayoutGuide.bottomAnchor), content.leadingAnchor.constraint(equalTo: scroll.contentLayoutGuide.leadingAnchor), @@ -258,10 +266,10 @@ final class RootViewController: UIViewController { // The group is centred between the status bar and the footer and never stretched; a taller one scrolls. NSLayoutConstraint.activate([ column.centerXAnchor.constraint(equalTo: content.centerXAnchor), - column.centerYAnchor.constraint(equalTo: content.centerYAnchor), + column.centerYAnchor.constraint(equalTo: area.centerYAnchor), column.widthAnchor.constraint(equalToConstant: metrics.column), - column.topAnchor.constraint(greaterThanOrEqualTo: content.topAnchor, constant: 24), - column.bottomAnchor.constraint(lessThanOrEqualTo: content.bottomAnchor, constant: -24), + column.topAnchor.constraint(greaterThanOrEqualTo: area.topAnchor, constant: 24), + column.bottomAnchor.constraint(lessThanOrEqualTo: area.bottomAnchor, constant: -24), ]) self.column = column if current?.screen == "account" { refreshAccount() }