From ef0a27e260530cd3c73699c2d62acfa6a1a8a316 Mon Sep 17 00:00:00 2001 From: Tim Morgan Date: Tue, 17 Nov 2026 22:02:04 -0800 Subject: [PATCH] Split inputs and results only in a space wider than tall At regular width the performance screens always split into two forms, so an iPad in portrait stacked them, each scrolling on its own, with the inputs in the top 62% and the results below. The split now applies only where the space is wider than tall: iPad in landscape and iPhone Duo's inner display, which runs in landscape across the fold. Everywhere else the screens show one form, inputs first, as at compact width. The shape is taken only when the width changes. The software keyboard shortens the space without narrowing it, and on an iPad in portrait it leaves the space wider than tall; measuring then would switch to the split and rebuild the forms under the field being edited, dismissing the keyboard. Co-Authored-By: Claude Opus 5.5 --- .../Views/Performance/PerformanceLayout.swift | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/SF50 TOLD/Views/Performance/PerformanceLayout.swift b/SF50 TOLD/Views/Performance/PerformanceLayout.swift index e93220b..97ff3af 100644 --- a/SF50 TOLD/Views/Performance/PerformanceLayout.swift +++ b/SF50 TOLD/Views/Performance/PerformanceLayout.swift @@ -1,42 +1,52 @@ import SF50_Shared import SwiftUI -/// Lays out a performance screen's inputs and results: as two forms at regular width, and as one -/// form, inputs first, at compact width. +/// Lays out a performance screen's inputs and results: as two forms side by side at regular width +/// in a space wider than tall, and otherwise as one form, inputs first. /// -/// At regular width the inputs and results sit side by side, or stacked where the space is -/// taller than wide, so the results stay in view while an input is changed. On iPhone Duo's inner -/// display the split follows the fold. +/// Side by side, the results stay in view while an input is changed. On iPhone Duo's inner display +/// the split follows the fold. struct PerformanceLayout: View { - /// The share of the height the inputs take when the forms are stacked, enough for every input - /// on a 13-inch iPad in portrait while iPhone Duo's inner display still shows every result. - private static var stackedInputsShare: CGFloat { 0.62 } - @Environment(\.horizontalSizeClass) private var horizontalSizeClass + @State private var measuredWidth: CGFloat? + @State private var isWiderThanTall = false + @ViewBuilder let inputs: () -> Inputs @ViewBuilder let results: () -> Results + private var canSplit: Bool { horizontalSizeClass == .regular && isWiderThanTall } + var body: some View { - if #available(iOS 27.1, *), horizontalSizeClass == .regular { - ArrangementView { - Form { inputs() } - .accessibilityIdentifier("performanceInputs") - .modifier(SeamMargin(edge: .trailing)) - } secondary: { - Form { results() } - .accessibilityIdentifier("performanceResults") - .modifier(SeamMargin(edge: .leading)) - } - .arrangementViewStyle(.split) - .splitArrangementLayoutRatio(idealVertical: Self.stackedInputsShare) - } else { - Form { - inputs() - results() + Group { + if #available(iOS 27.1, *), canSplit { + ArrangementView { + Form { inputs() } + .accessibilityIdentifier("performanceInputs") + .modifier(SeamMargin(edge: .trailing)) + } secondary: { + Form { results() } + .accessibilityIdentifier("performanceResults") + .modifier(SeamMargin(edge: .leading)) + } + .arrangementViewStyle(.split) + } else { + Form { + inputs() + results() + } } } + .onGeometryChange(for: CGSize.self, of: \.size, action: measureShape) + } + + /// Takes the space's shape when its width changes, which a rotation, an unfold or a window resize + /// does and the software keyboard, taking only height, does not. + private func measureShape(_ size: CGSize) { + guard size.width != measuredWidth else { return } + measuredWidth = size.width + isWiderThanTall = size.width > size.height } }