Signed-off-by: Matt Bruce <mbrucedogs@gmail.com>
This commit is contained in:
parent
2b0f36a12c
commit
4d79f08089
@ -20,7 +20,7 @@ enum Design {
|
|||||||
static let showDebugBorders = false
|
static let showDebugBorders = false
|
||||||
|
|
||||||
/// Set to true to show debug log statements
|
/// Set to true to show debug log statements
|
||||||
static let showDebugLogs = true
|
static let showDebugLogs = false
|
||||||
|
|
||||||
/// Debug logger - only prints when showDebugLogs is true
|
/// Debug logger - only prints when showDebugLogs is true
|
||||||
static func debugLog(_ message: String) {
|
static func debugLog(_ message: String) {
|
||||||
|
|||||||
@ -19,14 +19,8 @@ struct GameTableView: View {
|
|||||||
@State private var showRules = false
|
@State private var showRules = false
|
||||||
@State private var showStats = false
|
@State private var showStats = false
|
||||||
|
|
||||||
/// Full screen size (measured from TableBackgroundView - stable, doesn't change with content)
|
/// Screen size for card sizing (measured from TableBackgroundView)
|
||||||
@State private var fullScreenSize: CGSize = CGSize(width: 375, height: 667)
|
@State private var screenSize: 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
|
|
||||||
|
|
||||||
// MARK: - Environment
|
// MARK: - Environment
|
||||||
|
|
||||||
@ -114,42 +108,12 @@ struct GameTableView: View {
|
|||||||
@ViewBuilder
|
@ViewBuilder
|
||||||
private func mainGameView(state: GameState) -> some View {
|
private func mainGameView(state: GameState) -> some View {
|
||||||
ZStack {
|
ZStack {
|
||||||
// Background - measures full screen size (stable)
|
// Background - measures screen size for card sizing
|
||||||
TableBackgroundView()
|
TableBackgroundView()
|
||||||
.onGeometryChange(for: CGSize.self) { proxy in
|
.onGeometryChange(for: CGSize.self) { proxy in
|
||||||
proxy.size
|
proxy.size
|
||||||
} action: { size in
|
} action: { size in
|
||||||
let oldFullSize = fullScreenSize
|
screenSize = size
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mainContent(state: state)
|
mainContent(state: state)
|
||||||
@ -180,18 +144,15 @@ struct GameTableView: View {
|
|||||||
.transition(.move(edge: .top).combined(with: .opacity))
|
.transition(.move(edge: .top).combined(with: .opacity))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Table layout - use fixedSize to prevent expanding when chip selector disappears
|
// Table layout
|
||||||
// Use cachedScreenSize to prevent card size fluctuations
|
|
||||||
BlackjackTableView(
|
BlackjackTableView(
|
||||||
state: state,
|
state: state,
|
||||||
selectedChip: selectedChip,
|
selectedChip: selectedChip,
|
||||||
fullScreenSize: cachedScreenSize
|
fullScreenSize: screenSize
|
||||||
)
|
)
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
.frame(maxWidth: maxContentWidth)
|
.frame(maxWidth: maxContentWidth)
|
||||||
|
|
||||||
// Flexible spacer absorbs extra space when chip selector is hidden
|
// Flexible spacer absorbs extra space when chip selector is hidden
|
||||||
// This prevents the table view from expanding/contracting
|
|
||||||
Spacer(minLength: 0)
|
Spacer(minLength: 0)
|
||||||
|
|
||||||
// Chip selector - only shown during betting phase AND when result banner is NOT showing
|
// Chip selector - only shown during betting phase AND when result banner is NOT showing
|
||||||
|
|||||||
@ -62,27 +62,19 @@ struct BlackjackTableView: View {
|
|||||||
private var showDebugBorders: Bool { Design.showDebugBorders }
|
private var showDebugBorders: Bool { Design.showDebugBorders }
|
||||||
|
|
||||||
var body: some View {
|
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) {
|
VStack(spacing: 0) {
|
||||||
// Dealer area - fixedSize prevents expanding beyond intrinsic content size
|
// Dealer area
|
||||||
DealerHandView(
|
DealerHandView(
|
||||||
hand: state.dealerHand,
|
hand: state.dealerHand,
|
||||||
showHoleCard: state.shouldShowDealerHoleCard,
|
showHoleCard: state.shouldShowDealerHoleCard,
|
||||||
showCardCount: showCardCount,
|
showCardCount: showCardCount,
|
||||||
cardWidth: currentCardWidth,
|
cardWidth: cardWidth,
|
||||||
cardSpacing: cardSpacing
|
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")
|
.debugBorder(showDebugBorders, color: .red, label: "Dealer")
|
||||||
|
|
||||||
// Top spacer - limited height to prevent layout jumping
|
// Top spacer
|
||||||
Spacer(minLength: Design.Spacing.small)
|
Spacer(minLength: Design.Spacing.small)
|
||||||
.frame(maxHeight: Design.Spacing.xxLarge)
|
|
||||||
.debugBorder(showDebugBorders, color: .yellow, label: "TopSpacer")
|
.debugBorder(showDebugBorders, color: .yellow, label: "TopSpacer")
|
||||||
|
|
||||||
// Card count view centered between dealer and player
|
// Card count view centered between dealer and player
|
||||||
@ -94,13 +86,11 @@ struct BlackjackTableView: View {
|
|||||||
.debugBorder(showDebugBorders, color: .mint, label: "CardCount")
|
.debugBorder(showDebugBorders, color: .mint, label: "CardCount")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bottom spacer - limited height to prevent layout jumping
|
// Bottom spacer
|
||||||
Spacer(minLength: Design.Spacing.small)
|
Spacer(minLength: Design.Spacing.small)
|
||||||
.frame(maxHeight: Design.Spacing.xxLarge)
|
|
||||||
.debugBorder(showDebugBorders, color: .yellow, label: "BottomSpacer")
|
.debugBorder(showDebugBorders, color: .yellow, label: "BottomSpacer")
|
||||||
|
|
||||||
// Player hands area - only show when there are cards dealt
|
// 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 {
|
if state.playerHands.first?.cards.isEmpty == false {
|
||||||
ZStack {
|
ZStack {
|
||||||
PlayerHandsView(
|
PlayerHandsView(
|
||||||
@ -108,10 +98,9 @@ struct BlackjackTableView: View {
|
|||||||
activeHandIndex: state.activeHandIndex,
|
activeHandIndex: state.activeHandIndex,
|
||||||
isPlayerTurn: state.isPlayerTurn,
|
isPlayerTurn: state.isPlayerTurn,
|
||||||
showCardCount: showCardCount,
|
showCardCount: showCardCount,
|
||||||
cardWidth: currentCardWidth,
|
cardWidth: cardWidth,
|
||||||
cardSpacing: cardSpacing
|
cardSpacing: cardSpacing
|
||||||
)
|
)
|
||||||
.fixedSize(horizontal: false, vertical: true)
|
|
||||||
|
|
||||||
// Side bet toasts (positioned on left/right sides to not cover cards)
|
// Side bet toasts (positioned on left/right sides to not cover cards)
|
||||||
if state.settings.sideBetsEnabled && state.showSideBetToasts {
|
if state.settings.sideBetsEnabled && state.showSideBetToasts {
|
||||||
@ -180,9 +169,6 @@ struct BlackjackTableView: View {
|
|||||||
}
|
}
|
||||||
.padding(.bottom, 5)
|
.padding(.bottom, 5)
|
||||||
.transition(.opacity)
|
.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")
|
.debugBorder(showDebugBorders, color: .green, label: "Player")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,9 +194,6 @@ struct BlackjackTableView: View {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.padding(.horizontal, Design.Spacing.large)
|
.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")
|
.debugBorder(showDebugBorders, color: .white, label: "TableView")
|
||||||
.animation(.spring(duration: Design.Animation.springDuration), value: state.currentPhase)
|
.animation(.spring(duration: Design.Animation.springDuration), value: state.currentPhase)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user