Play your own Switch games on iPhone/iPad — one-click macOS app, no terminal. | 把 Switch 游戏装进 iPhone:图形界面一键构建,不用命令行。Bring your own game.
Swift apple-siliconcustom-formathomebrewiosipaipadipadosiphonemetalnative-portnintendo-switchnxnativeromfsswitch-games
iOS shell: Cover Flow centred on the screen, settings header for square art
v0lumehibb8ce88708ab
diff --git a/frontend-ios/Sources/ShellUI/CoverFlowView.swift b/frontend-ios/Sources/ShellUI/CoverFlowView.swiftindex b0268671..7aff8359 100644--- a/frontend-ios/Sources/ShellUI/CoverFlowView.swift+++ b/frontend-ios/Sources/ShellUI/CoverFlowView.swift@@ -9,6 +9,8 @@ struct CoverFlowView: View, Equatable {let controllers: Int/// The controller hints at the bottom, while a controller or keyboard is in use.let showsHints: Bool+ /// The screen's safe areas around this view, so the cards can sit in the middle of the whole screen.+ var screenInsets = EdgeInsets()let select: (String) -> Voidlet primary: (GameDetail) -> Voidlet openSettings: () -> Void@@ -30,34 +32,40 @@ struct CoverFlowView: View, Equatable {/// not reach the carousel.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.controllers == rhs.controllers && lhs.showsHints == rhs.showsHints && lhs.screenInsets == rhs.screenInsets}var body: some View {GeometryReader { geometry inlet short = geometry.size.height < 520- // A wide card as large as the Mac console's focused tile: what the height allows, never so wide that the- // neighbours vanish.- let cardHeight = max(90, min(geometry.size.height * (short ? 0.42 : 0.44), geometry.size.width * 0.54 * 9 / 16))+ // The centred card sits in the middle of the whole screen, the top bar laid over it. The title and state+ // go under the card at a fixed distance, so the card is only as tall as leaves room for them above the+ // bottom edge, and never so wide that the neighbours vanish.+ let height = geometry.size.height+ let middle = (height + screenInsets.top + screenInsets.bottom) / 2 - screenInsets.top+ let gap: CGFloat = short ? 10 : 24+ let words = Self.infoHeight(short: short)+ let below: CGFloat = short ? 4 : 56 // the hint row on a tablet, a margin on a phone+ let byBottom = 2 * (height - middle - gap - words - below)+ let byTop = 2 * (middle - (short ? 54 : 76))+ let cardHeight = max(90, min(byBottom, byTop, geometry.size.width * 0.54 * 9 / 16) / 1.06)let cover = cardHeight * 16 / 9- VStack(spacing: 0) {- topBar.padding(.horizontal, 24).padding(.top, short ? 4 : 16)- // The cover block (cards, title and state, the hint row) is centred in the space under the top bar, a- // touch above the middle, never closer to the bar than the minimum gap. Its parts keep fixed places- // inside it, so nothing moves between games.- Spacer(minLength: short ? 18 : 32)+ ZStack(alignment: .top) {VStack(spacing: 0) {Group {if games.count <= 3 { shelf(width: geometry.size.width, cover: cover) } else { carousel(width: geometry.size.width, cover: cover) }- }.frame(height: cover * 9 / 16 * 1.06)+ }.frame(height: cardHeight * 1.06)info(short: short, width: geometry.size.width)- .padding(.top, short ? 12 : 26).padding(.horizontal, 24)- // The hint row keeps its place when it is hidden, so the card does not move when it appears.- hints.opacity(showsHints ? 1 : 0).padding(.top, short ? 10 : 28)+ .padding(.top, gap).padding(.horizontal, 24)+ }+ .padding(.top, middle - cardHeight * 1.06 / 2)+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)+ topBar(short: short).padding(.horizontal, 24).padding(.top, short ? 4 : 16)+ if !short {+ // The hint row keeps its place when it is hidden, so nothing moves when it appears.+ hints.opacity(showsHints ? 1 : 0).padding(.bottom, 20)+ .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .bottom)}- Spacer(minLength: short ? 6 : 16)- // The optical lift: a little more room below than above.- Color.clear.frame(height: short ? 14 : 36)}}.sensoryFeedback(.selection, trigger: selected.id)@@ -70,12 +78,23 @@ struct CoverFlowView: View, Equatable {}}- private var topBar: some View {+ /// The title and state under the card: two lines of title reserved, then the state line.+ static func infoHeight(short: Bool) -> CGFloat {+ let size: CGFloat = short ? 18 : 28+ return size * 1.3 * 2 + 8 + 34+ }++ private func topBar(short: Bool) -> some View {HStack(alignment: .center, spacing: 10) {SectionHeading(title: ShellStrings.text("Your games"))Text(ShellStrings.text("\(position) of \(games.count)")).shellText(12, .medium, relativeTo: .caption).monospacedDigit().foregroundStyle(.white.opacity(0.45)).padding(.leading, 4)Spacer(minLength: 12)+ if short {+ // On a phone on its side the hints share the top bar, so the cards keep the height.+ 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)@@ -190,7 +209,7 @@ struct CoverFlowView: View, Equatable {/// do. The space is reserved, so nothing moves when the selection changes, only the words crossfade.private func info(short: Bool, width: CGFloat) -> some View {let game = selected.game- let size: CGFloat = short ? 20 : 28+ let size: CGFloat = short ? 18 : 28return ZStack(alignment: .top) {VStack(spacing: 8) {Text("M\nM").shellType(ShellType.flowTitle(size))diff --git a/frontend-ios/Sources/ShellUI/LibraryView.swift b/frontend-ios/Sources/ShellUI/LibraryView.swiftindex 4dea2db6..380ffbc0 100644--- a/frontend-ios/Sources/ShellUI/LibraryView.swift+++ b/frontend-ios/Sources/ShellUI/LibraryView.swift@@ -201,7 +201,7 @@ public struct LibraryView: View {@ViewBuilder private func library(_ selected: GameDetail, layout: ShellLayout, size: CGSize, insets: EdgeInsets) -> some View {if layout.isCoverFlow {- CoverFlowView(games: games, selected: selected, controllers: controllers.count, showsHints: !touchMode,+ CoverFlowView(games: games, selected: selected, controllers: controllers.count, showsHints: !touchMode, screenInsets: insets,select: select, primary: primary, openSettings: openSettings, openControllers: openControllers).equatable().transition(.opacity)@@ -352,36 +352,57 @@ private struct PaneBanner: View {/// The status bar's height where the banner runs under it.var topInset: CGFloat = 0var body: some View {- let bannerHeight = min(width * 9 / 16, 220) + topInset- // The words are bottom-aligned in a block that always reserves two lines of title, as in the library hero: a- // short title shows more banner above it instead of leaving a hole, and the settings start at the same place.- ZStack(alignment: .bottomLeading) {- words(title: "M\nM").hidden().accessibilityHidden(true)- words(title: game.title)+ let hasBanner = game.banner != nil+ // A banner gets its full width and 16:9 height. Square or portrait art is never cropped into a tile: it shows+ // whole as a rounded cover above the words, on a heavily blurred fill of itself.+ let bannerHeight = hasBanner ? min(width * 9 / 16, 220) + topInset : topInset + 64+ // On a wide screen the cover sits beside the words, on a narrow one above them, aligned to the same edge.+ let layout = width >= 560 ? AnyLayout(HStackLayout(alignment: .bottom, spacing: 22))+ : AnyLayout(VStackLayout(alignment: .leading, spacing: 16))+ layout {+ if !hasBanner { CoverThumbnail(game: game).frame(width: 96, height: 96) }+ // The words are bottom-aligned in a block that always reserves two lines of title, as in the library+ // hero: a short title shows more banner above it instead of leaving a hole.+ ZStack(alignment: .bottomLeading) {+ words(title: "M\nM").hidden().accessibilityHidden(true)+ words(title: game.title)+ }}.padding(.leading, leading + 24).padding(.trailing, 24)- .padding(.top, bannerHeight - 22)+ .padding(.top, bannerHeight - (hasBanner ? 22 : 0)).frame(maxWidth: .infinity, alignment: .leading).background {- // The banner fills the whole header edge to edge, cropped as needed, and fades into the page under the words.- ArtView(game: game, lettering: false)- .frame(width: width)- .overlay(alignment: .top) {- // Darker under the status bar, so the time and battery stay legible on any art.- if topInset > 0 {- LinearGradient(colors: [.black.opacity(0.5), .clear], startPoint: .top, endPoint: .bottom)- .frame(height: topInset + 50)- }- }- .overlay {- LinearGradient(stops: [.init(color: .clear, location: 0.35), .init(color: .black.opacity(0.45), location: 0.7),- .init(color: .black.opacity(0.6), location: 1)], startPoint: .top, endPoint: .bottom)+ Group {+ if hasBanner {+ // The banner fills the whole header edge to edge, cropped as needed, darker under the words.+ ArtView(game: game, lettering: false)+ .frame(width: width)+ .overlay {+ LinearGradient(stops: [.init(color: .clear, location: 0.35), .init(color: .black.opacity(0.45), location: 0.7),+ .init(color: .black.opacity(0.6), location: 1)], startPoint: .top, endPoint: .bottom)+ }+ } else {+ ArtView(game: game, backdrop: true)+ .frame(width: width)+ .scaleEffect(1.4)+ .blur(radius: 40, opaque: true)+ .saturation(1.2)+ .overlay(Color.black.opacity(0.38))}- .mask {- LinearGradient(stops: [.init(color: .black, location: 0), .init(color: .black, location: 0.7),- .init(color: .clear, location: 1)], startPoint: .top, endPoint: .bottom)+ }+ .overlay(alignment: .top) {+ // Darker under the status bar, so the time and battery stay legible on any art.+ if topInset > 0 {+ LinearGradient(colors: [.black.opacity(0.5), .clear], startPoint: .top, endPoint: .bottom)+ .frame(height: topInset + 50)}- .accessibilityHidden(true)+ }+ .mask {+ LinearGradient(stops: [.init(color: .black, location: 0), .init(color: .black, location: 0.7),+ .init(color: .clear, location: 1)], startPoint: .top, endPoint: .bottom)+ }+ .clipped()+ .accessibilityHidden(true)}}@@ -400,6 +421,26 @@ private struct PaneBanner: View {}}+/// A game's square art shown whole: the icon, or the placeholder cover when there is none.+private struct CoverThumbnail: View {+ let game: GameTile+ var body: some View {+ Group {+ if let icon = game.icon {+ Image(decorative: icon.image, scale: 1).resizable().interpolation(.high).scaledToFill()+ } else if let banner = game.banner {+ Image(decorative: banner.image, scale: 1).resizable().interpolation(.high).scaledToFill()+ } else {+ PlaceholderArt(title: game.title, seed: game.id)+ }+ }+ .clipShape(RoundedRectangle(cornerRadius: 18))+ .overlay(RoundedRectangle(cornerRadius: 18).strokeBorder(.white.opacity(0.14)))+ .shadow(color: .black.opacity(0.4), radius: 16, y: 6)+ .accessibilityHidden(true)+ }+}+/// Marks the actions a controller or key press causes, so they are not taken for touch. Not observed.@MainActor final class InputGate {var handling = falsediff --git a/frontend-ios/UITests/ShellCaptureTests.swift b/frontend-ios/UITests/ShellCaptureTests.swiftindex e140f8fc..93c819c3 100644--- a/frontend-ios/UITests/ShellCaptureTests.swift+++ b/frontend-ios/UITests/ShellCaptureTests.swift@@ -68,6 +68,23 @@ import XCTestXCUIDevice.shared.orientation = .portrait}+ /// Every sample game's settings header: banners, square icons and the drawn placeholder.+ func testCaptureSettingsHeaders() {+ for orientation in [UIDeviceOrientation.landscapeLeft, .portrait] {+ XCUIDevice.shared.orientation = orientation+ let suffix = orientation == .portrait ? "portrait" : "landscape"+ for id in ["orbit", "tide", "paper", "moon", "wild", "drift", "amber"] {+ launch(["--screen", "settings", "--select", id])+ shot("header-\(id)-\(suffix)")+ }+ launch(["--screen", "library", "--select", "drift"])+ shot("library-short-title-\(suffix)")+ launch(["--screen", "library", "--select", "paper"])+ shot("library-long-title-\(suffix)")+ }+ XCUIDevice.shared.orientation = .portrait+ }+/// The fold stand-in: one running shell resized between a folded and an unfolded screen.func testCaptureFold() throws {try XCTSkipUnless(UIDevice.current.userInterfaceIdiom == .pad, "The fold stand-in needs an iPad canvas")