Files
iceglass/IceGlass-iOS/Views/GameRow.swift
T
rzen 52ebfc1a6b Use colon score format and placeholder for upcoming game rows
Game rows now render scores as "2 : 3" (with spaces) in secondary
color so they read as data, not as part of the team-name run.
Pre-game rows show "- : -" in the same slot so tricode columns line
up regardless of whether the game has started — only two-digit scores
push the layout, which doesn't happen in NHL play.
2026-04-25 15:26:25 -04:00

113 lines
3.4 KiB
Swift

//
// GameRow.swift
// IceGlass-iOS
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
struct GameRow: View {
let game: Scoreboard.Game
private static let logoSize: CGFloat = 40
var body: some View {
Button(action: open) {
HStack(spacing: 10) {
if game.gameType == 2 {
Text("#\(game.seasonGameNumber)")
.font(.caption2.monospacedDigit())
.foregroundStyle(.tertiary)
.frame(width: 44, alignment: .leading)
}
matchupBlock
Spacer(minLength: 8)
rightContent
}
.padding(.horizontal, 14)
.padding(.vertical, 8)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
}
private var matchupBlock: some View {
let state = game.parsedGameState
let showScore = !state.isFuture
return HStack(spacing: 6) {
TeamLogo(abbrev: game.awayTeam.abbrev, size: Self.logoSize)
Text(game.awayTeam.abbrev)
.font(.title3.monospaced())
.fontWeight(.semibold)
.foregroundStyle(.primary)
.lineLimit(1)
.fixedSize()
Text(showScore ? scoreText : "- : -")
.font(.title3.monospacedDigit())
.fontWeight(.bold)
.foregroundStyle(.secondary)
.lineLimit(1)
.fixedSize()
.padding(.horizontal, 2)
Text(game.homeTeam.abbrev)
.font(.title3.monospaced())
.fontWeight(.semibold)
.foregroundStyle(.primary)
.lineLimit(1)
.fixedSize()
TeamLogo(abbrev: game.homeTeam.abbrev, size: Self.logoSize)
}
}
@ViewBuilder
private var rightContent: some View {
let state = game.parsedGameState
VStack(alignment: .trailing, spacing: 2) {
Text(primaryRightLine)
.font(.subheadline.monospacedDigit())
.foregroundStyle(state.isLive ? .red : .secondary)
if let secondary = secondaryRightLine {
Text(secondary)
.font(.caption2)
.foregroundStyle(.tertiary)
}
}
}
private var primaryRightLine: String {
let state = game.parsedGameState
if state.isFuture {
return game.startTimeET.trimmingCharacters(in: .whitespaces)
}
let tag = state.shortTag
return tag.isEmpty
? game.startTimeET.trimmingCharacters(in: .whitespaces)
: tag
}
private var secondaryRightLine: String? {
let state = game.parsedGameState
guard !state.isFuture, !state.shortTag.isEmpty else { return nil }
// For finished games, show kickoff time below FINAL/OFF; for live games, just show tag.
if state.isLive { return nil }
return game.startTimeET.trimmingCharacters(in: .whitespaces)
}
private var scoreText: String {
let a = game.awayTeam.score ?? 0
let h = game.homeTeam.score ?? 0
return "\(a) : \(h)"
}
private func open() {
guard let url = URL(string: game.gameCenterUrl) else { return }
UIApplication.shared.open(url)
}
}