Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>

This commit is contained in:
Matt Bruce 2025-12-24 14:01:45 -06:00
parent 2b0f36a12c
commit 4d79f08089
3 changed files with 12 additions and 68 deletions

View File

@ -20,7 +20,7 @@ enum Design {
static let showDebugBorders = false
/// Set to true to show debug log statements
static let showDebugLogs = true
static let showDebugLogs = false
/// Debug logger - only prints when showDebugLogs is true
static func debugLog(_ message: String) {

View File

@ -19,14 +19,8 @@ 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)
/// Cached screen size - only updates on significant changes (orientation)
@State private var cachedScreenSize: CGSize = CGSize(width: 375, height: 667)
/// Whether we've captured the initial screen size (only capture once)
@State private var hasInitializedScreenSize = false
/// Screen size for card sizing (measured from TableBackgroundView)
@State private var screenSize: CGSize = CGSize(width: 375, height: 667)
// MARK: - Environment
@ -114,42 +108,12 @@ struct GameTableView: View {
@ViewBuilder
private func mainGameView(state: GameState) -> some View {
ZStack {
// Background - measures full screen size (stable)
// Background - measures screen size for card sizing
TableBackgroundView()
.onGeometryChange(for: CGSize.self) { proxy in
proxy.size
} action: { size in
let oldFullSize = fullScreenSize
fullScreenSize = size
// Debug: Log all geometry changes
if size != oldFullSize {
Design.debugLog("📐 Geometry changed: \(Int(oldFullSize.width))×\(Int(oldFullSize.height))\(Int(size.width))×\(Int(size.height))")
Design.debugLog(" Cached: \(Int(cachedScreenSize.width))×\(Int(cachedScreenSize.height)), initialized=\(hasInitializedScreenSize)")
}
// Capture screen size ONCE on first valid measurement
// Use the DEFAULT initialized value (667 for iPhone) if first measurement is smaller
// This handles the case where safe area reduces the first measurement
if !hasInitializedScreenSize && size.width > 0 && size.height > 0 {
// Use the LARGER of default and first measurement
let useHeight = max(size.height, cachedScreenSize.height)
let useWidth = max(size.width, cachedScreenSize.width)
let captureSize = CGSize(width: useWidth, height: useHeight)
Design.debugLog("📐 🎯 INITIAL capture: measured=\(Int(size.width))×\(Int(size.height)), using=\(Int(captureSize.width))×\(Int(captureSize.height))")
cachedScreenSize = captureSize
hasInitializedScreenSize = true
} else if hasInitializedScreenSize {
// After initialization: ONLY update on TRUE orientation change
let wasPortrait = cachedScreenSize.height > cachedScreenSize.width
let isPortrait = size.height > size.width
if wasPortrait != isPortrait {
Design.debugLog("📐 🔄 ORIENTATION changed: \(Int(cachedScreenSize.width))×\(Int(cachedScreenSize.height))\(Int(size.width))×\(Int(size.height))")
cachedScreenSize = size
}
// Otherwise: IGNORE all geometry changes - keep cached size stable
}
screenSize = size
}
mainContent(state: state)
@ -180,18 +144,15 @@ struct GameTableView: View {
.transition(.move(edge: .top).combined(with: .opacity))
}
// Table layout - use fixedSize to prevent expanding when chip selector disappears
// Use cachedScreenSize to prevent card size fluctuations
// Table layout
BlackjackTableView(
state: state,
selectedChip: selectedChip,
fullScreenSize: cachedScreenSize
fullScreenSize: screenSize
)
.fixedSize(horizontal: false, vertical: true)
.frame(maxWidth: maxContentWidth)
// Flexible spacer absorbs extra space when chip selector is hidden
// This prevents the table view from expanding/contracting
Spacer(minLength: 0)
// Chip selector - only shown during betting phase AND when result banner is NOT showing

View File

@ -62,27 +62,19 @@ struct BlackjackTableView: View {
private var showDebugBorders: Bool { Design.showDebugBorders }
var body: some View {
let currentCardWidth = cardWidth // Capture for logging
let _ = Design.debugLog("🃏 Card sizing: screenHeight=\(Int(screenHeight)), cardWidth=\(Int(currentCardWidth)), fullScreenSize=\(Int(fullScreenSize.width))×\(Int(fullScreenSize.height))")
VStack(spacing: 0) {
// Dealer area - fixedSize prevents expanding beyond intrinsic content size
// Dealer area
DealerHandView(
hand: state.dealerHand,
showHoleCard: state.shouldShowDealerHoleCard,
showCardCount: showCardCount,
cardWidth: currentCardWidth,
cardWidth: cardWidth,
cardSpacing: cardSpacing
)
.fixedSize(horizontal: false, vertical: true)
.onGeometryChange(for: CGSize.self) { $0.size } action: { size in
Design.debugLog("📦 Dealer hand frame: \(Int(size.width))×\(Int(size.height))")
}
.debugBorder(showDebugBorders, color: .red, label: "Dealer")
// Top spacer - limited height to prevent layout jumping
// Top spacer
Spacer(minLength: Design.Spacing.small)
.frame(maxHeight: Design.Spacing.xxLarge)
.debugBorder(showDebugBorders, color: .yellow, label: "TopSpacer")
// Card count view centered between dealer and player
@ -94,13 +86,11 @@ struct BlackjackTableView: View {
.debugBorder(showDebugBorders, color: .mint, label: "CardCount")
}
// Bottom spacer - limited height to prevent layout jumping
// Bottom spacer
Spacer(minLength: Design.Spacing.small)
.frame(maxHeight: Design.Spacing.xxLarge)
.debugBorder(showDebugBorders, color: .yellow, label: "BottomSpacer")
// Player hands area - only show when there are cards dealt
// fixedSize prevents the view from expanding beyond its intrinsic content size
if state.playerHands.first?.cards.isEmpty == false {
ZStack {
PlayerHandsView(
@ -108,10 +98,9 @@ struct BlackjackTableView: View {
activeHandIndex: state.activeHandIndex,
isPlayerTurn: state.isPlayerTurn,
showCardCount: showCardCount,
cardWidth: currentCardWidth,
cardWidth: cardWidth,
cardSpacing: cardSpacing
)
.fixedSize(horizontal: false, vertical: true)
// Side bet toasts (positioned on left/right sides to not cover cards)
if state.settings.sideBetsEnabled && state.showSideBetToasts {
@ -180,9 +169,6 @@ struct BlackjackTableView: View {
}
.padding(.bottom, 5)
.transition(.opacity)
.onGeometryChange(for: CGSize.self) { $0.size } action: { size in
Design.debugLog("📦 Player hands frame: \(Int(size.width))×\(Int(size.height))")
}
.debugBorder(showDebugBorders, color: .green, label: "Player")
}
@ -208,9 +194,6 @@ struct BlackjackTableView: View {
}
}
.padding(.horizontal, Design.Spacing.large)
.onGeometryChange(for: CGSize.self) { $0.size } action: { size in
Design.debugLog("📦 BlackjackTableView frame: \(Int(size.width))×\(Int(size.height))")
}
.debugBorder(showDebugBorders, color: .white, label: "TableView")
.animation(.spring(duration: Design.Animation.springDuration), value: state.currentPhase)
}