From 53b8b928bcc632ee2e973075bc5f3a3e3e4ad4cb Mon Sep 17 00:00:00 2001 From: Chin-Chang Yang <2770271+ChinChangYang@users.noreply.github.com> Date: Thu, 26 Oct 2023 21:37:28 +0800 Subject: [PATCH] Refactor GobanView and ToolbarView for responsive layout - Adjust view hierarchy based on size classes in both `GobanItems` and `ToolbarItems` --- ios/KataGo iOS/KataGo iOS/GobanView.swift | 21 +++++++++++++++++-- ios/KataGo iOS/KataGo iOS/ToolbarView.swift | 23 ++++++++++++++++++--- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/ios/KataGo iOS/KataGo iOS/GobanView.swift b/ios/KataGo iOS/KataGo iOS/GobanView.swift index 2971c2135..f929df8e1 100644 --- a/ios/KataGo iOS/KataGo iOS/GobanView.swift +++ b/ios/KataGo iOS/KataGo iOS/GobanView.swift @@ -7,7 +7,7 @@ import SwiftUI -struct GobanView: View { +struct GobanItems: View { @EnvironmentObject var stones: Stones @EnvironmentObject var board: ObservableBoard @EnvironmentObject var player: PlayerObject @@ -16,7 +16,7 @@ struct GobanView: View { let texture = WoodImage.createTexture() var body: some View { - VStack { + Group { GeometryReader { geometry in let dimensions = Dimensions(geometry: geometry, board: board) ZStack { @@ -81,6 +81,23 @@ struct GobanView: View { } } +struct GobanView: View { + @Environment(\.horizontalSizeClass) var hSizeClass + @Environment(\.verticalSizeClass) var vSizeClass + + var body: some View { + if hSizeClass == .compact && vSizeClass == .regular { + VStack { + GobanItems() + } + } else { + HStack { + GobanItems() + } + } + } +} + struct GobanView_Previews: PreviewProvider { static let stones = Stones() static let board = ObservableBoard() diff --git a/ios/KataGo iOS/KataGo iOS/ToolbarView.swift b/ios/KataGo iOS/KataGo iOS/ToolbarView.swift index 3ff8edfaf..7ae02d340 100644 --- a/ios/KataGo iOS/KataGo iOS/ToolbarView.swift +++ b/ios/KataGo iOS/KataGo iOS/ToolbarView.swift @@ -7,12 +7,12 @@ import SwiftUI -struct ToolbarView: View { +struct ToolbarItems: View { @EnvironmentObject var player: PlayerObject @EnvironmentObject var config: Config - + var body: some View { - HStack { + Group { Button(action: { KataGoHelper.sendCommand("undo") KataGoHelper.sendCommand("showboard") @@ -69,6 +69,23 @@ struct ToolbarView: View { } } +struct ToolbarView: View { + @Environment(\.horizontalSizeClass) var hSizeClass + @Environment(\.verticalSizeClass) var vSizeClass + + var body: some View { + if hSizeClass == .compact && vSizeClass == .regular { + HStack { + ToolbarItems() + } + } else { + VStack { + ToolbarItems() + } + } + } +} + struct ToolbarView_Previews: PreviewProvider { static let player = PlayerObject() static let config = Config()