From 2dd9ae020e4a97cc52bbfa003d24dc0ec9392c8e Mon Sep 17 00:00:00 2001 From: Matt Bruce Date: Tue, 23 Dec 2025 14:55:57 -0600 Subject: [PATCH] Signed-off-by: Matt Bruce --- .../Blackjack/Views/Game/GameTableView.swift | 13 ++++++++-- .../Views/Table/BlackjackTableView.swift | 26 +++++++------------ .../Views/Table/DealerHandView.swift | 14 ---------- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/Blackjack/Blackjack/Views/Game/GameTableView.swift b/Blackjack/Blackjack/Views/Game/GameTableView.swift index e9d5a8a..d675be7 100644 --- a/Blackjack/Blackjack/Views/Game/GameTableView.swift +++ b/Blackjack/Blackjack/Views/Game/GameTableView.swift @@ -19,6 +19,9 @@ struct GameTableView: View { @State private var showRules = false @State private var showStats = false + /// Full screen size (measured from TableBackgroundView - stable, doesn't change with content) + @State private var fullScreenSize: CGSize = CGSize(width: 375, height: 667) + // MARK: - Environment @Environment(\.horizontalSizeClass) private var horizontalSizeClass @@ -73,8 +76,13 @@ struct GameTableView: View { @ViewBuilder private func mainGameView(state: GameState) -> some View { ZStack { - // Background + // Background - measures full screen size (stable) TableBackgroundView() + .onGeometryChange(for: CGSize.self) { proxy in + proxy.size + } action: { size in + fullScreenSize = size + } mainContent(state: state) } @@ -117,7 +125,8 @@ struct GameTableView: View { // Table layout - fills available space BlackjackTableView( state: state, - onPlaceBet: { placeBet(state: state) } + onPlaceBet: { placeBet(state: state) }, + fullScreenSize: fullScreenSize ) .frame(maxWidth: maxContentWidth) diff --git a/Blackjack/Blackjack/Views/Table/BlackjackTableView.swift b/Blackjack/Blackjack/Views/Table/BlackjackTableView.swift index b589427..3d6152d 100644 --- a/Blackjack/Blackjack/Views/Table/BlackjackTableView.swift +++ b/Blackjack/Blackjack/Views/Table/BlackjackTableView.swift @@ -12,15 +12,17 @@ struct BlackjackTableView: View { @Bindable var state: GameState let onPlaceBet: () -> Void + /// Full screen size passed from parent (stable - measured from TableBackgroundView) + let fullScreenSize: CGSize + // MARK: - Environment @Environment(\.verticalSizeClass) private var verticalSizeClass - // MARK: - State + // MARK: - Computed from stable screen size - /// Screen dimensions measured from container for responsive sizing - @State private var screenHeight: CGFloat = 800 - @State private var screenWidth: CGFloat = 375 + private var screenWidth: CGFloat { fullScreenSize.width } + private var screenHeight: CGFloat { fullScreenSize.height } /// Whether to show Hi-Lo card count values on cards. var showCardCount: Bool { state.settings.showCardCount } @@ -43,13 +45,11 @@ struct BlackjackTableView: View { return verticalSizeClass == .compact } - /// Card width derived from screen height percentage and card aspect ratio - /// cardHeight = maxHeight × percentage, then cardWidth = cardHeight / aspectRatio + /// Card width based on full screen height (stable - doesn't change with content) private var cardWidth: CGFloat { - let maxHeight = max(screenWidth, screenHeight) - let heightPercentage: CGFloat = 0.19 // Card takes 12% of screen height - let cardHeight = maxHeight * heightPercentage - return cardHeight + let maxDimension = screenHeight + let percentage: CGFloat = 0.13 // ~10% of screen + return maxDimension * percentage } /// Card overlap scales proportionally with card width @@ -146,12 +146,6 @@ struct BlackjackTableView: View { } .padding(.horizontal, Design.Spacing.large) .padding(.vertical, Design.Spacing.medium) - .onGeometryChange(for: CGSize.self) { proxy in - proxy.size - } action: { size in - screenWidth = size.width - screenHeight = size.height - } .debugBorder(showDebugBorders, color: .white, label: "TableView") .animation(.spring(duration: Design.Animation.springDuration), value: state.currentPhase) } diff --git a/Blackjack/Blackjack/Views/Table/DealerHandView.swift b/Blackjack/Blackjack/Views/Table/DealerHandView.swift index 5327d11..38566ef 100644 --- a/Blackjack/Blackjack/Views/Table/DealerHandView.swift +++ b/Blackjack/Blackjack/Views/Table/DealerHandView.swift @@ -81,20 +81,6 @@ struct DealerHandView: View { } .accessibilityElement(children: .ignore) .accessibilityLabel(dealerAccessibilityLabel) - .background( - GeometryReader { geo in - Color.clear - .onAppear { - print("🃏 DealerHandView SIZE: \(geo.size.width) x \(geo.size.height), cards: \(hand.cards.count), cardWidth: \(cardWidth), cardSpacing: \(cardSpacing)") - } - .onChange(of: geo.size) { oldSize, newSize in - print("🃏 DealerHandView CHANGED: \(oldSize.width)x\(oldSize.height) → \(newSize.width)x\(newSize.height), cards: \(hand.cards.count)") - } - .onChange(of: hand.cards.count) { oldCount, newCount in - print("🃏 DealerHandView CARDS: \(oldCount) → \(newCount), size: \(geo.size.width)x\(geo.size.height)") - } - } - ) } // MARK: - Computed Properties