Skip to content

Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.

iOS shell: the game settings and Back in iPhone Duo's side column, placed by the occluded areas

v0lumehi897e76329261
diff --git a/frontend-ios/README.md b/frontend-ios/README.md
index 356637ad..becf8454 100644
--- a/frontend-ios/README.md
+++ b/frontend-ios/README.md
@@ -96,7 +96,7 @@ Only the available size decides, never the device model, idiom or orientation (`
| Regular width and height, not wide (iPad portrait, an unfolded foldable held like a book) | The library alone: the same hero with Play and the settings button in it, a grid of wide cards, recently played. Settings, when asked for, float in as a panel from the right over the dimmed library. |
| Wider than tall (iPhone and iPad landscape, an unfolded foldable on its side) | Cover Flow over the blurred banner, wide cards in a calm deck. Settings, when asked for, float in as the same panel (regular) or take the whole screen (compact). |
-iPhone Duo keeps a column on one side for the status bar and the system's vertical bars (#622). Where the system names that edge (`toolbarVerticalEdge`, iOS 27.1) and the column is wide enough, the Controllers and Settings chips leave the header and sit at the bottom of the column, above the home indicator and clear of the camera (`reservedRegions(kind: .occlusion)`). The top half stays free for the status bar. Everywhere else nothing changes (`SideBar`, tested in `SideBarTests`, rendered on a simulated outer display by `SideBarCaptureTests`). A shell built with an SDK older than iOS 27.1 keeps the chips in the header.
+iPhone Duo keeps a column on one side for the status bar and the system's vertical bars (#622). Where the system names that edge (`toolbarVerticalEdge`, iOS 27.1) and the column is wide enough, the shell's own bar moves into the column. The Controllers and Settings chips sit at its bottom, above the home indicator. The game settings button sits at the top of its free part, so Play has the bottom bar to itself, and while a game's settings are open Back takes that place. Every chip stays clear of the occluded areas (`reservedRegions(kind: .occlusion)`), which in the iPhone Duo Simulator include the status bar and the camera in every pose. Where the column has no occluded area, nothing reports the status bar, so the top stays empty and the chips stay in the lower half. Upright, the inner display has a status bar at the top and no column, so nothing changes there. Everywhere else nothing changes either (`SideBar`, tested in `SideBarTests` with the values the Simulator reported, rendered on a simulated outer display by `SideBarCaptureTests`). A shell built with an SDK older than iOS 27.1 keeps the chips in the header.
Settings appear only when asked for (the settings button, X on a controller) and close with Back, B or a tap outside. They are one view in one place for every layout, with the game's banner as their header, so the selected game, open settings and both scroll positions survive a fold, a rotation or a Stage Manager resize.
diff --git a/frontend-ios/Sources/ShellUI/CoverFlowView.swift b/frontend-ios/Sources/ShellUI/CoverFlowView.swift
index 0a9ef492..e179f3c0 100644
--- a/frontend-ios/Sources/ShellUI/CoverFlowView.swift
+++ b/frontend-ios/Sources/ShellUI/CoverFlowView.swift
@@ -13,6 +13,8 @@ struct CoverFlowView: View, Equatable {
var screenInsets = EdgeInsets()
/// The Controllers and Settings chips sit in the side column (SideBar), not in the top bar.
var chipsInSideBar = false
+ /// The game settings button sits at the top of the side column, not in the top bar.
+ var settingsInSideBar = false
let select: (String) -> Void
let primary: (GameDetail) -> Void
let openSettings: () -> Void
@@ -36,7 +38,7 @@ struct CoverFlowView: View, Equatable {
nonisolated static func == (lhs: Self, rhs: Self) -> Bool {
lhs.games.map(\.game) == rhs.games.map(\.game) && lhs.selected.game == rhs.selected.game
&& lhs.controllers == rhs.controllers && lhs.showsHints == rhs.showsHints && lhs.screenInsets == rhs.screenInsets
- && lhs.chipsInSideBar == rhs.chipsInSideBar
+ && lhs.chipsInSideBar == rhs.chipsInSideBar && lhs.settingsInSideBar == rhs.settingsInSideBar
}
var body: some View {
@@ -104,11 +106,13 @@ struct CoverFlowView: View, Equatable {
hints.opacity(showsHints ? 1 : 0)
Spacer(minLength: 12)
}
- Button(action: openSettings) { Image(systemName: "slider.horizontal.3").frame(minWidth: 18) }
- .buttonStyle(ChipButtonStyle())
- .accessibilityLabel(ShellStrings.text("Game settings") + ", " + selected.game.title)
- .accessibilityIdentifier("settings.open")
- .shellTarget("lib.settings", radius: 22, action: openSettings)
+ if !settingsInSideBar {
+ Button(action: openSettings) { Image(systemName: "slider.horizontal.3").frame(minWidth: 18) }
+ .buttonStyle(ChipButtonStyle())
+ .accessibilityLabel(ShellStrings.text("Game settings") + ", " + selected.game.title)
+ .accessibilityIdentifier("settings.open")
+ .shellTarget("lib.settings", radius: 22, action: openSettings)
+ }
if !chipsInSideBar {
ControllerChip(count: controllers, action: openControllers)
ShellSettingsChip(action: openShellSettings)
diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swift
index 96028758..9217e65b 100644
--- a/frontend-ios/Sources/ShellUI/LibraryView.swift
+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift
@@ -109,7 +109,9 @@ public struct LibraryView: View {
let paneCovers = settingsOpen && !floating
let panelOverLibrary = settingsOpen && floating
// The chips go into the side column where the system has one. At the accessibility text sizes they stay in the header.
- let column = typeSize.isAccessibilitySize ? nil : (sideBarOverride ?? probedSideBar).column(screen: whole, insets: insets)
+ let side = typeSize.isAccessibilitySize ? nil : (sideBarOverride ?? probedSideBar)
+ .place(screen: whole, insets: insets, top: games.isEmpty ? [] : SideBar.topHeights)
+ let column = side?.bottom
ZStack(alignment: .topLeading) {
if layout.isCoverFlow, let selected { CoverFlowBackdrop(game: selected.game) } else { ShellPalette.background.ignoresSafeArea() }
if games.isEmpty {
@@ -124,18 +126,26 @@ public struct LibraryView: View {
}
if let column { sideChips(column, insets: insets) }
} else if let selected {
- library(selected, layout: layout, size: geometry.size, insets: insets, chipsInSideBar: column != nil)
+ library(selected, layout: layout, size: geometry.size, insets: insets, chipsInSideBar: column != nil,
+ settingsInSideBar: side?.top != nil)
.frame(width: width, height: geometry.size.height)
.opacity(paneCovers && edgeDrag == 0 ? 0 : 1)
.allowsHitTesting(!settingsOpen)
.accessibilityHidden(settingsOpen || helpGameID != nil || deleteGameID != nil)
.transformPreference(FocusTargets.self) { if settingsOpen { $0.removeAll() } }
- if let column {
- sideChips(column, insets: insets)
- .opacity(paneCovers && edgeDrag == 0 ? 0 : 1)
- .allowsHitTesting(!settingsOpen)
- .accessibilityHidden(settingsOpen || helpGameID != nil || deleteGameID != nil)
- .transformPreference(FocusTargets.self) { if settingsOpen { $0.removeAll() } }
+ if let side {
+ Group {
+ sideChips(side.bottom, insets: insets)
+ if let top = side.top, !settingsOpen {
+ SideBarTopChip(symbol: "slider.horizontal.3", label: ShellStrings.text("Game settings") + ", " + selected.game.title,
+ identifier: "settings.open", target: "lib.settings", action: openSettings)
+ .sideBarFrame(top, insets: insets)
+ }
+ }
+ .opacity(paneCovers && edgeDrag == 0 ? 0 : 1)
+ .allowsHitTesting(!settingsOpen)
+ .accessibilityHidden(settingsOpen || helpGameID != nil || deleteGameID != nil)
+ .transformPreference(FocusTargets.self) { if settingsOpen { $0.removeAll() } }
}
if panelOverLibrary {
// The same dimming and dismissal as the Controllers overlay.
@@ -146,7 +156,7 @@ public struct LibraryView: View {
}
// One settings view in one place for every layout, so its state, scroll position and focus survive
// a fold, a rotation or a Stage Manager resize.
- settingsPane(selected, floating: floating, width: pane,
+ settingsPane(selected, floating: floating, width: pane, backInSideBar: side?.top != nil,
insets: floating ? EdgeInsets(top: insets.top, leading: 0, bottom: insets.bottom, trailing: insets.trailing)
: insets)
.frame(width: pane)
@@ -163,6 +173,14 @@ public struct LibraryView: View {
.accessibilityHidden(!settingsOpen || choice != nil || padMapping != nil || deleteGameID != nil)
.accessibilityAddTraits(settingsOpen ? .isModal : [])
.transformPreference(FocusTargets.self) { if !settingsOpen { $0.removeAll() } }
+ if let top = side?.top, settingsOpen {
+ // Back at the top of the side column, where the system's bars put an app's own navigation.
+ SideBarTopChip(symbol: "chevron.left", label: ShellStrings.text("Library"), identifier: "library.back",
+ target: "set.back", action: closeSettings)
+ .sideBarFrame(top, insets: insets)
+ .opacity(1 - min(1, edgeDrag / pane))
+ .accessibilityHidden(choice != nil || padMapping != nil || deleteGameID != nil)
+ }
}
if let id = helpGameID, let game = games.first(where: { $0.id == id })?.game {
Color.black.opacity(0.55).ignoresSafeArea().accessibilityHidden(true)
@@ -325,22 +343,21 @@ public struct LibraryView: View {
/// The Controllers and Settings chips in the side column, `column` in the screen's coordinates.
private func sideChips(_ column: CGRect, insets: EdgeInsets) -> some View {
SideBarChips(controllers: controllers.count, openControllers: openControllers, openShellSettings: openShellSettings)
- .frame(width: column.width, height: column.height)
- .offset(x: column.minX - insets.leading, y: column.minY - insets.top)
+ .sideBarFrame(column, insets: insets)
}
@ViewBuilder private func library(_ selected: GameDetail, layout: ShellLayout, size: CGSize, insets: EdgeInsets,
- chipsInSideBar: Bool) -> some View {
+ chipsInSideBar: Bool, settingsInSideBar: Bool) -> some View {
if layout.isCoverFlow {
CoverFlowView(games: games, selected: selected, controllers: controllers.count, showsHints: !touchMode, screenInsets: insets,
- chipsInSideBar: chipsInSideBar,
+ chipsInSideBar: chipsInSideBar, settingsInSideBar: settingsInSideBar,
select: select, primary: primary, openSettings: openSettings, openControllers: openControllers,
openShellSettings: openShellSettings)
.equatable()
.transition(.opacity)
} else {
PortraitLibrary(games: games, selected: selected, wide: layout == .grid, size: size, topInset: insets.top, bottomInset: insets.bottom,
- chipsInSideBar: chipsInSideBar,
+ chipsInSideBar: chipsInSideBar, settingsInSideBar: settingsInSideBar,
controllers: controllers.count, select: select, primary: primary,
openSettings: openSettings, openControllers: openControllers, openShellSettings: openShellSettings,
position: $libraryPosition)
@@ -355,7 +372,7 @@ public struct LibraryView: View {
/// the primary action and the setting groups. A panel or the whole screen, the same view. The banner runs edge to
/// edge under the status bar and the settings scroll under the home indicator, while Back, the words and the
/// settings keep their insets.
- private func settingsPane(_ selected: GameDetail, floating: Bool, width: CGFloat, insets: EdgeInsets) -> some View {
+ private func settingsPane(_ selected: GameDetail, floating: Bool, width: CGFloat, backInSideBar: Bool, insets: EdgeInsets) -> some View {
return ZStack(alignment: .top) {
ScrollViewReader { proxy in
ScrollView {
@@ -380,7 +397,8 @@ public struct LibraryView: View {
}
}
}
- HStack(spacing: 0) {
+ // In the side column (SideBar) Back sits at the column's top instead.
+ if !backInSideBar { HStack(spacing: 0) {
Button(action: closeSettings) {
if typeSize.isAccessibilitySize { Image(systemName: "chevron.left").frame(minWidth: 24) }
else { Label(ShellStrings.text("Library"), systemImage: "chevron.left") }
@@ -393,7 +411,7 @@ public struct LibraryView: View {
}
.padding(.leading, 16 + insets.leading).padding(.trailing, 16 + insets.trailing)
.padding(.top, 6)
- .accessibilityElement(children: .contain)
+ .accessibilityElement(children: .contain) }
}
}
diff --git a/frontend-ios/Sources/ShellUI/PortraitLibrary.swift b/frontend-ios/Sources/ShellUI/PortraitLibrary.swift
index ef07270d..a5843afb 100644
--- a/frontend-ios/Sources/ShellUI/PortraitLibrary.swift
+++ b/frontend-ios/Sources/ShellUI/PortraitLibrary.swift
@@ -22,6 +22,8 @@ struct PortraitLibrary: View, Equatable {
var bottomInset: CGFloat = 0
/// The Controllers and Settings chips sit in the side column (SideBar), not over the hero.
var chipsInSideBar = false
+ /// The game settings button sits at the top of the side column, so Play has the bar to itself.
+ var settingsInSideBar = false
let controllers: Int
let select: (String) -> Void
let primary: (GameDetail) -> Void
@@ -59,6 +61,7 @@ struct PortraitLibrary: View, Equatable {
lhs.games.map(\.game) == rhs.games.map(\.game) && lhs.selected.game == rhs.selected.game && lhs.wide == rhs.wide
&& lhs.size == rhs.size && lhs.topInset == rhs.topInset && lhs.bottomInset == rhs.bottomInset
&& lhs.controllers == rhs.controllers && lhs.chipsInSideBar == rhs.chipsInSideBar
+ && lhs.settingsInSideBar == rhs.settingsInSideBar
}
var body: some View {
@@ -76,7 +79,7 @@ struct PortraitLibrary: View, Equatable {
.accessibilityLabel(selected.game.state.actionTitle + ", " + selected.game.title)
.accessibilityIdentifier("state.action")
.shellTarget("lib.play", radius: 25) { primary(selected) }
- settingsButton
+ if !settingsInSideBar { settingsButton }
}.padding(.top, 8)
}
}
@@ -213,7 +216,7 @@ struct PortraitLibrary: View, Equatable {
.accessibilityLabel(selected.game.state.actionTitle + ", " + selected.game.title)
.accessibilityIdentifier("state.action")
.shellTarget("lib.play", radius: 25) { primary(selected) }
- settingsButton
+ if !settingsInSideBar { settingsButton }
}
.padding(.horizontal, 24).padding(.top, 22).padding(.bottom, 8)
.background {
diff --git a/frontend-ios/Sources/ShellUI/SideBar.swift b/frontend-ios/Sources/ShellUI/SideBar.swift
index 9f3d8f2b..bdbcfb3e 100644
--- a/frontend-ios/Sources/ShellUI/SideBar.swift
+++ b/frontend-ios/Sources/ShellUI/SideBar.swift
@@ -1,15 +1,17 @@
import SwiftUI
-/// iPhone Duo (#622) keeps a column on one side of the screen for the status bar and the system's vertical bars: the Dynamic
-/// Island and the status bar at the top, then the app's toolbar and tab bar. The column lies outside the safe area, so the library
-/// leaves it empty. Apple's design guide counts the app's own controls among the controls on the side, and
-/// `toolbarVerticalEdge` (iOS 27.1) is there to place custom bars beside the system's. So where the system uses that column,
-/// the Controllers and Settings chips go into it, at its bottom end, away from the status bar at the top.
-/// Nothing here knows the device: only the edge the system names, the safe area and the occluded areas decide.
+/// iPhone Duo (#622) keeps a column on one side of the screen for the status bar and the system's vertical bars. The column lies
+/// outside the safe area, so the library leaves it empty. Apple's design guide counts the app's own toolbar among the controls on
+/// the side, and `toolbarVerticalEdge` (iOS 27.1) is there to place custom bars beside the system's. So where the system uses that
+/// column, the shell's own bar goes into it: the game's settings (or Back while they are open) at the top of the free part, the
+/// Controllers and Settings chips at the bottom.
+/// Nothing here knows the device: only the edge the system names, the safe area and the occluded areas decide. In the iPhone Duo
+/// Simulator (iOS 27.2) the occluded areas include the status bar and the Dynamic Island in every pose, and the status bar is at
+/// the top of the column upright and hidden on the side, where the Dynamic Island is at one end of the column.
public struct SideBar: Equatable, Sendable {
/// The edge of the system's vertical bar, nil where the system never places one (every other iPhone and iPad).
public var edge: HorizontalEdge?
- /// Areas a camera or the Dynamic Island covers, in the screen's coordinates (`reservedRegions(kind: .occlusion)`).
+ /// Areas the status bar, a camera or the Dynamic Island covers, in the screen's coordinates (`reservedRegions(kind: .occlusion)`).
public var occlusions: [CGRect]
public init(edge: HorizontalEdge?, occlusions: [CGRect] = []) {
@@ -20,26 +22,71 @@ public struct SideBar: Equatable, Sendable {
/// A chip in the column: this wide, and the Controllers chip a little taller for its count under the symbol.
public static let chipWidth: CGFloat = 52
public static let heights: [CGFloat] = [56, 44]
+ /// The one chip at the top of the column: the game's settings, or Back.
+ public static let topHeights: [CGFloat] = [44]
public static let gap: CGFloat = 10
public static let margin: CGFloat = 12
+ /// Kept free at an end of the column that has no inset, where the screen's corner rounds off.
+ public static let corner: CGFloat = 28
+ /// The least room between the top chip and the chips at the bottom, so they read as two groups.
+ public static let groupGap: CGFloat = 24
- /// The column's frame in the screen's coordinates for chips of `heights`, or nil to keep them in the header: no vertical
- /// bar, a column too narrow for a chip, or no room below the status bar's half of the column. The chips sit at the bottom of
- /// the column above the home indicator, and move up past any occluded area they would touch.
- public func column(screen: CGSize, insets: EdgeInsets, heights: [CGFloat] = SideBar.heights) -> CGRect? {
- guard let edge, !heights.isEmpty else { return nil }
+ /// Where the column's chips go, in the screen's coordinates.
+ public struct Placement: Equatable, Sendable {
+ /// The Controllers and Settings chips, at the bottom of the column's free part.
+ public var bottom: CGRect
+ /// The game's settings or Back, at the top of the free part. Nil when there is no room, or nothing reports the status bar.
+ public var top: CGRect?
+ }
+
+ /// The chips' frames for chips of `bottom` and `top` heights, or nil to keep them all in the header: no vertical bar, a column
+ /// too narrow for a chip, or no free part of the column tall enough. The free part is the column between the ends of the
+ /// screen (above the home indicator, below any top inset) without the occluded areas. Where the system reports no occluded
+ /// area in the column, the status bar's place is unknown: then only the bottom chips may go there, and only in the lower half.
+ public func place(screen: CGSize, insets: EdgeInsets, bottom: [CGFloat] = SideBar.heights, top: [CGFloat] = []) -> Placement? {
+ guard let edge, !bottom.isEmpty else { return nil }
let side = edge == .trailing ? insets.trailing : insets.leading
guard side >= Self.chipWidth else { return nil }
- let height = heights.reduce(0, +) + Self.gap * CGFloat(heights.count - 1)
let x = (edge == .trailing ? screen.width - side : 0) + (side - Self.chipWidth) / 2
- var frame = CGRect(x: x, y: screen.height - insets.bottom - Self.margin - height, width: Self.chipWidth, height: height)
- for _ in 0...occlusions.count {
- guard let top = occlusions.filter({ $0.intersects(frame) }).map(\.minY).min() else { break }
- frame.origin.y = top - Self.margin - height
+ let strip = (x, x + Self.chipWidth)
+ let blocked = occlusions.filter { $0.minX < strip.1 && $0.maxX > strip.0 && $0.height > 0 }
+ .map { ($0.minY - Self.margin, $0.maxY + Self.margin) }
+ let low = insets.top > 0 ? insets.top + Self.margin : Self.corner
+ let high = screen.height - (insets.bottom > 0 ? insets.bottom + Self.margin : Self.corner)
+ let free = Self.subtract(blocked, from: (low, high))
+ let height = Self.stack(bottom)
+ guard let lowest = free.last(where: { $0.1 - $0.0 >= height }) else { return nil }
+ let frame = CGRect(x: x, y: lowest.1 - height, width: Self.chipWidth, height: height)
+ // No occluded area in the column: the status bar could be anywhere in its top half.
+ if blocked.isEmpty { return frame.minY >= screen.height / 2 ? Placement(bottom: frame, top: nil) : nil }
+ guard !top.isEmpty else { return Placement(bottom: frame, top: nil) }
+ let above = Self.subtract([(frame.minY - Self.groupGap, .infinity)], from: free)
+ let topHeight = Self.stack(top)
+ let first = above.first { $0.1 - $0.0 >= topHeight }
+ return Placement(bottom: frame, top: first.map { CGRect(x: x, y: $0.0, width: Self.chipWidth, height: topHeight) })
+ }
+
+ /// The bottom chips' frame alone, as `place` puts them.
+ public func column(screen: CGSize, insets: EdgeInsets, heights: [CGFloat] = SideBar.heights) -> CGRect? {
+ place(screen: screen, insets: insets, bottom: heights)?.bottom
+ }
+
+ private static func stack(_ heights: [CGFloat]) -> CGFloat { heights.reduce(0, +) + gap * CGFloat(max(0, heights.count - 1)) }
+
+ /// The parts of `ranges` (sorted, top first) that none of `cuts` covers.
+ private static func subtract(_ cuts: [(CGFloat, CGFloat)], from ranges: [(CGFloat, CGFloat)]) -> [(CGFloat, CGFloat)] {
+ var parts = ranges.filter { $0.1 > $0.0 }
+ for cut in cuts {
+ parts = parts.flatMap { part -> [(CGFloat, CGFloat)] in
+ guard cut.0 < part.1, cut.1 > part.0 else { return [part] }
+ return [(part.0, cut.0), (cut.1, part.1)].filter { $0.1 > $0.0 }
+ }
}
- if occlusions.contains(where: { $0.intersects(frame) }) { return nil }
- // The top half belongs to the Dynamic Island and the status bar, which no API reports as an area to avoid.
- return frame.minY >= screen.height / 2 ? frame : nil
+ return parts
+ }
+
+ private static func subtract(_ cuts: [(CGFloat, CGFloat)], from range: (CGFloat, CGFloat)) -> [(CGFloat, CGFloat)] {
+ subtract(cuts, from: [range])
}
}
@@ -86,3 +133,30 @@ struct SideBarChips: View {
}
}
}
+
+/// The chip at the top of the side column: the selected game's settings in the library, Back while they are open. It keeps the
+/// accessibility label, identifier and focus target of the button it stands in for, so VoiceOver, the UI tests and a controller
+/// find it as before.
+struct SideBarTopChip: View {
+ let symbol: String
+ let label: String
+ let identifier: String
+ let target: String
+ let action: () -> Void
+ var body: some View {
+ Button(action: action) {
+ Image(systemName: symbol).frame(width: SideBar.chipWidth - 28, height: SideBar.topHeights[0])
+ }
+ .buttonStyle(ChipButtonStyle())
+ .accessibilityLabel(label)
+ .accessibilityIdentifier(identifier)
+ .shellTarget(target, radius: 22, action: action)
+ }
+}
+
+extension View {
+ /// Puts a side-column chip at `frame`, given in the screen's coordinates, inside a view laid out in the safe area.
+ func sideBarFrame(_ frame: CGRect, insets: EdgeInsets) -> some View {
+ self.frame(width: frame.width, height: frame.height).offset(x: frame.minX - insets.leading, y: frame.minY - insets.top)
+ }
+}
diff --git a/frontend-ios/Tests/ShellHostTests/SideBarCaptureTests.swift b/frontend-ios/Tests/ShellHostTests/SideBarCaptureTests.swift
index 552b2eff..a70efc24 100644
--- a/frontend-ios/Tests/ShellHostTests/SideBarCaptureTests.swift
+++ b/frontend-ios/Tests/ShellHostTests/SideBarCaptureTests.swift
@@ -5,10 +5,10 @@ import XCTest
@testable import ShellUI
@testable import ShellHost
-/// Visual QA of the library on iPhone Duo's outer display (#622), rendered on the Mac from the fixture games. The Mac has no Duo, so
-/// the screen is simulated: the outer display's size (466 x 678 points, from the Simulator's device profile) and a column of safe
-/// area on the trailing side where the status bar sits. The column's width is measured from the reporter's screenshots, so it is an
-/// estimate. The status bar's place in it is drawn as a light strip with a time. Set NX_SHELL_CAPTURE_DIR to write the PNGs, NX_SHELL_CAPTURE_LANG for the language.
+/// Visual QA of the library on iPhone Duo's outer display (#622), rendered on the Mac from the fixture games. The screen is
+/// simulated with the values the iPhone Duo Simulator (iOS 27.2) reported: the outer display's size, its safe area (a column of 84
+/// points on one side, 34 at the bottom) and its occluded areas (the status bar, the camera), which are drawn as light areas.
+/// Set NX_SHELL_CAPTURE_DIR to write the PNGs, NX_SHELL_CAPTURE_LANG for the language.
@MainActor
final class SideBarCaptureTests: XCTestCase {
private var lang: String { ProcessInfo.processInfo.environment["NX_SHELL_CAPTURE_LANG"] ?? "en" }
@@ -24,17 +24,18 @@ final class SideBarCaptureTests: XCTestCase {
HostStrings.captureBundle = nil
}
- /// The view inside a screen of `size` whose safe area leaves `insets` free, with the status bar's column drawn as a dim strip
- /// along the trailing edge's top so the image shows where the system's time and Wi-Fi would be.
- private func capture<V: View>(_ name: String, size: CGSize, insets: EdgeInsets, statusHeight: CGFloat, _ view: V) throws {
+ /// The view inside a screen of `size` whose safe area leaves `insets` free, with the occluded areas of `bar` drawn as light
+ /// shapes, so the image shows where the system's time and the camera are.
+ private func capture<V: View>(_ name: String, size: CGSize, insets: EdgeInsets, bar: SideBar, _ view: V) throws {
let dir = try XCTUnwrap(ProcessInfo.processInfo.environment["NX_SHELL_CAPTURE_DIR"])
NSApplication.shared.setActivationPolicy(.accessory)
- let screen = ZStack(alignment: .topTrailing) {
- // The system's vertical bar on the trailing edge, as `toolbarVerticalEdge` reports it on iPhone Duo.
- view.safeAreaPadding(insets).environment(\.shellSideBar, SideBar(edge: .trailing))
- Rectangle().fill(.white.opacity(0.18)).frame(width: insets.trailing, height: statusHeight)
- .overlay { Text("9:41").font(.system(size: 13, weight: .semibold)).foregroundStyle(.white.opacity(0.7)) }
- .allowsHitTesting(false)
+ let screen = ZStack(alignment: .topLeading) {
+ view.safeAreaPadding(insets).environment(\.shellSideBar, bar)
+ ForEach(Array(bar.occlusions.enumerated()), id: \.offset) { _, area in
+ RoundedRectangle(cornerRadius: min(area.width, area.height) / 2).fill(.white.opacity(0.18))
+ .frame(width: area.width, height: area.height).offset(x: area.minX, y: area.minY)
+ }
+ .allowsHitTesting(false)
}
let framed = screen.frame(width: size.width, height: size.height).background(ShellPalette.background).environment(\.colorScheme, .dark)
let host = NSHostingView(rootView: framed)
@@ -65,15 +66,20 @@ final class SideBarCaptureTests: XCTestCase {
let box = try Sandbox()
let model = try model(box)
let upright = CGSize(width: 466, height: 678), sideways = CGSize(width: 678, height: 466)
- let uprightInsets = EdgeInsets(top: 0, leading: 0, bottom: 20, trailing: 80)
- let sidewaysInsets = EdgeInsets(top: 0, leading: 0, bottom: 20, trailing: 56)
- try capture("duo-outer-upright", size: upright, insets: uprightInsets, statusHeight: 165,
+ let insets = EdgeInsets(top: 0, leading: 0, bottom: 34, trailing: 84)
+ let uprightBar = SideBar(edge: .trailing, occlusions: [CGRect(x: 382, y: 0, width: 84, height: 174),
+ CGRect(x: 399.67, y: 29.33, width: 37, height: 37)])
+ let sidewaysBar = SideBar(edge: .trailing, occlusions: [CGRect(x: 594, y: 384, width: 84, height: 82),
+ CGRect(x: 611.67, y: 399.67, width: 37, height: 37)])
+ try capture("duo-outer-upright", size: upright, insets: insets, bar: uprightBar,
LibraryView(games: model.details, initialSelection: Fixtures.orbit))
- try capture("duo-outer-sideways", size: sideways, insets: sidewaysInsets, statusHeight: 80,
+ try capture("duo-outer-upright-settings", size: upright, insets: insets, bar: uprightBar,
+ LibraryView(games: model.details, initialSelection: Fixtures.orbit, initialDetailOpen: true))
+ try capture("duo-outer-sideways", size: sideways, insets: insets, bar: sidewaysBar,
LibraryView(games: model.details, initialSelection: Fixtures.orbit))
- try capture("duo-outer-sideways-settings", size: sideways, insets: sidewaysInsets, statusHeight: 80,
+ try capture("duo-outer-sideways-settings", size: sideways, insets: insets, bar: sidewaysBar,
LibraryView(games: model.details, initialSelection: Fixtures.orbit, initialDetailOpen: true))
- try capture("duo-outer-empty", size: upright, insets: uprightInsets, statusHeight: 165, LibraryView(games: []))
+ try capture("duo-outer-empty", size: upright, insets: insets, bar: uprightBar, LibraryView(games: []))
}
}
#endif
diff --git a/frontend-ios/Tests/ShellUITests/SideBarTests.swift b/frontend-ios/Tests/ShellUITests/SideBarTests.swift
index f0399be6..a1e288f7 100644
--- a/frontend-ios/Tests/ShellUITests/SideBarTests.swift
+++ b/frontend-ios/Tests/ShellUITests/SideBarTests.swift
@@ -2,7 +2,7 @@ import SwiftUI
import XCTest
@testable import ShellUI
-/// The side column of iPhone Duo (#622): where the Controllers and Settings chips may go, and where they may not.
+/// The side column of iPhone Duo (#622): where the game settings, Controllers and Settings chips may go, and where they may not.
final class SideBarTests: XCTestCase {
/// iPhone Duo's outer display upright, 466 x 678 points, with the status bar's column on the trailing side.
private let outer = CGSize(width: 466, height: 678)
@@ -44,19 +44,81 @@ final class SideBarTests: XCTestCase {
XCTAssertLessThanOrEqual(column.maxY, camera.minY)
}
- func testNoRoomBelowTheStatusBarKeepsThemInTheHeader() {
- // An occluded area over the whole lower half of the column.
- let cover = CGRect(x: outer.width - 80, y: outer.height * 0.45, width: 80, height: outer.height * 0.55)
- XCTAssertNil(SideBar(edge: .trailing, occlusions: [cover]).column(screen: outer, insets: outerInsets))
- // A screen so short that the chips would reach into the status bar's half.
+ func testNoRoomInTheColumnKeepsThemInTheHeader() {
+ // Occluded areas over the whole column but a strip too short for the chips.
+ let upper = CGRect(x: outer.width - 80, y: 0, width: 80, height: 300)
+ let lower = CGRect(x: outer.width - 80, y: 380, width: 80, height: 300)
+ XCTAssertNil(SideBar(edge: .trailing, occlusions: [upper, lower]).column(screen: outer, insets: outerInsets))
+ // No occluded area reported and a screen so short that the chips would reach into the status bar's half.
XCTAssertNil(SideBar(edge: .trailing).column(screen: CGSize(width: 466, height: 200), insets: outerInsets))
}
- /// Seeded random screens, insets and occluded areas: a column, where there is one, lies in the side inset on the screen, in the
- /// bottom half, clear of every occluded area and of the safe area the library uses.
+ // The values below are what the iPhone Duo Simulator (iOS 27.2) reported: the size, the safe area and
+ // `reservedRegions(kind: .occlusion)` in each pose.
+
+ /// The outer display upright: the status bar is an occluded area at the top of the column, the camera inside it.
+ func testTheOuterDisplayUprightAsTheSimulatorReportsIt() throws {
+ let bar = SideBar(edge: .trailing, occlusions: [CGRect(x: 399.67, y: 29.33, width: 37, height: 37), CGRect(x: 382, y: 0, width: 84, height: 174)])
+ let place = try XCTUnwrap(bar.place(screen: outer, insets: duoInsets(trailing: 84), top: SideBar.topHeights))
+ XCTAssertEqual(place.bottom, CGRect(x: 398, y: 522, width: 52, height: 110))
+ XCTAssertEqual(place.top, CGRect(x: 398, y: 186, width: 52, height: 44))
+ }
+
+ /// The outer display on its side, top to the left: no status bar, the camera at the bottom of the trailing column.
+ func testTheOuterDisplayOnItsSideKeepsTheChipsAboveTheCamera() throws {
+ let screen = CGSize(width: 678, height: 466)
+ let bar = SideBar(edge: .trailing, occlusions: [CGRect(x: 611.67, y: 399.67, width: 37, height: 37), CGRect(x: 594, y: 384, width: 84, height: 82)])
+ let place = try XCTUnwrap(bar.place(screen: screen, insets: duoInsets(trailing: 84), top: SideBar.topHeights))
+ XCTAssertEqual(place.bottom, CGRect(x: 610, y: 262, width: 52, height: 110))
+ XCTAssertEqual(place.top, CGRect(x: 610, y: SideBar.corner, width: 52, height: 44))
+ }
+
+ /// The outer display on its other side: the column and the camera are on the leading edge, the camera at the top.
+ func testTheOuterDisplayOnItsOtherSideUsesTheLeadingColumn() throws {
+ let screen = CGSize(width: 678, height: 466)
+ let bar = SideBar(edge: .leading, occlusions: [CGRect(x: 29.33, y: 29.33, width: 37, height: 37), CGRect(x: 0, y: 0, width: 84, height: 82)])
+ let place = try XCTUnwrap(bar.place(screen: screen, insets: EdgeInsets(top: 0, leading: 84, bottom: 34, trailing: 0), top: SideBar.topHeights))
+ XCTAssertEqual(place.bottom, CGRect(x: 16, y: 310, width: 52, height: 110))
+ XCTAssertEqual(place.top, CGRect(x: 16, y: 94, width: 52, height: 44))
+ }
+
+ /// The inner display on its side: the status bar at the top of the trailing column. Upright the inner display has no column.
+ func testTheInnerDisplay() throws {
+ let screen = CGSize(width: 951, height: 669)
+ let bar = SideBar(edge: .trailing, occlusions: [CGRect(x: 867, y: 0, width: 84, height: 124)])
+ let place = try XCTUnwrap(bar.place(screen: screen, insets: duoInsets(trailing: 84), top: SideBar.topHeights))
+ XCTAssertEqual(place.bottom, CGRect(x: 883, y: 513, width: 52, height: 110))
+ XCTAssertEqual(place.top, CGRect(x: 883, y: 136, width: 52, height: 44))
+ let upright = SideBar(edge: nil, occlusions: [CGRect(x: 525, y: 0, width: 144, height: 82)])
+ XCTAssertNil(upright.place(screen: CGSize(width: 669, height: 951), insets: EdgeInsets(top: 82, leading: 0, bottom: 34, trailing: 0),
+ top: SideBar.topHeights))
+ }
+
+ /// Without an occluded area in the column the status bar's place is unknown: no chip at the top, the others in the lower half.
+ func testNoReportedStatusBarLeavesTheTopEmpty() throws {
+ let place = try XCTUnwrap(SideBar(edge: .trailing).place(screen: outer, insets: outerInsets, top: SideBar.topHeights))
+ XCTAssertNil(place.top)
+ XCTAssertGreaterThanOrEqual(place.bottom.minY, outer.height / 2)
+ }
+
+ /// A column too short for both groups keeps the bottom chips and drops the top one.
+ func testTheTopChipNeedsRoomAboveTheOthers() throws {
+ let screen = CGSize(width: 466, height: 330)
+ let status = CGRect(x: 382, y: 0, width: 84, height: 140)
+ let place = try XCTUnwrap(SideBar(edge: .trailing, occlusions: [status]).place(screen: screen, insets: duoInsets(trailing: 84),
+ top: SideBar.topHeights))
+ XCTAssertNil(place.top)
+ XCTAssertGreaterThanOrEqual(place.bottom.minY, status.maxY + SideBar.margin)
+ }
+
+ private func duoInsets(trailing: CGFloat) -> EdgeInsets { EdgeInsets(top: 0, leading: 0, bottom: 34, trailing: trailing) }
+
+ /// Seeded random screens, insets and occluded areas: chips, where there are some, lie in the side inset on the screen, clear of
+ /// every occluded area, of the home indicator and of the safe area the library uses. Where no occluded area is in the column
+ /// they stay in the bottom half and the top chip stays away. The top chip is always above the others with room between.
func testRandomScreensNeverPutTheChipsOnContentOrACamera() {
var rng = SplitMix(seed: 622)
- var placed = 0
+ var placed = 0, topped = 0
for _ in 0..<5000 {
let size = CGSize(width: rng.next(in: 200...1400), height: rng.next(in: 200...1400))
let insets = EdgeInsets(top: rng.next(in: 0...70), leading: rng.next(in: 0...100), bottom: rng.next(in: 0...40), trailing: rng.next(in: 0...100))
@@ -64,17 +126,29 @@ final class SideBarTests: XCTestCase {
let occlusions = (0..<Int(rng.next(in: 0...3.99))).map { _ in
CGRect(x: rng.next(in: -50...size.width), y: rng.next(in: -50...size.height), width: rng.next(in: 1...120), height: rng.next(in: 1...200))
}
- guard let column = SideBar(edge: edge, occlusions: occlusions).column(screen: size, insets: insets) else { continue }
+ guard let place = SideBar(edge: edge, occlusions: occlusions).place(screen: size, insets: insets, top: SideBar.topHeights) else { continue }
placed += 1
let safe = CGRect(x: insets.leading, y: insets.top, width: size.width - insets.leading - insets.trailing,
height: size.height - insets.top - insets.bottom)
- XCTAssertFalse(column.intersects(safe), "on the library's content: \(column) \(safe)")
- XCTAssertTrue(CGRect(origin: .zero, size: size).contains(column), "off the screen: \(column) \(size)")
- XCTAssertGreaterThanOrEqual(column.minY, size.height / 2, "in the status bar's half: \(column) \(size)")
- XCTAssertLessThanOrEqual(column.maxY, size.height - insets.bottom, "on the home indicator: \(column)")
- for area in occlusions { XCTAssertFalse(column.intersects(area), "on an occluded area: \(column) \(area)") }
+ let inColumn = occlusions.contains { $0.minX < place.bottom.maxX && $0.maxX > place.bottom.minX }
+ for chip in [place.bottom] + (place.top.map { [$0] } ?? []) {
+ XCTAssertFalse(chip.intersects(safe), "on the library's content: \(chip) \(safe)")
+ XCTAssertTrue(CGRect(origin: .zero, size: size).contains(chip), "off the screen: \(chip) \(size)")
+ XCTAssertLessThanOrEqual(chip.maxY, size.height - insets.bottom, "on the home indicator: \(chip)")
+ XCTAssertGreaterThanOrEqual(chip.minY, insets.top, "under the top inset: \(chip)")
+ for area in occlusions { XCTAssertFalse(chip.intersects(area), "on an occluded area: \(chip) \(area)") }
+ }
+ if !inColumn {
+ XCTAssertNil(place.top, "a top chip where nothing reports the status bar")
+ XCTAssertGreaterThanOrEqual(place.bottom.minY, size.height / 2, "in the status bar's half: \(place.bottom) \(size)")
+ }
+ if let top = place.top {
+ topped += 1
+ XCTAssertLessThanOrEqual(top.maxY + SideBar.groupGap, place.bottom.minY + 0.001, "too close to the others: \(top) \(place.bottom)")
+ }
}
XCTAssertGreaterThan(placed, 500, "the random cases should reach the column often")
+ XCTAssertGreaterThan(topped, 100, "the random cases should place a top chip often")
}
}