Add team logos and monospaced tricodes to iPhone game/series rows

New TeamLogo view loads bundled TeamLogos/{abbrev}.png with a UIImage
cache so scrolling doesn't repeatedly re-decode. GameRow and SeriesRow
now render [logo] TRI @ [logo] TRI with tricodes in a monospaced font
so columns line up regardless of which letters are present. SF Symbol
fallback when an abbrev has no bundled logo (e.g. "TBD" for unfilled
playoff slots).
This commit is contained in:
2026-04-25 15:14:20 -04:00
parent aaffa3771c
commit 506bea04cc
3 changed files with 95 additions and 20 deletions
+49
View File
@@ -0,0 +1,49 @@
//
// TeamLogo.swift
// IceGlass-iOS
//
// Copyright 2026 Rouslan Zenetl. All Rights Reserved.
//
import SwiftUI
import UIKit
/// Loads a bundled team logo PNG from `TeamLogos/{abbrev}.png`. Falls back to
/// an SF Symbol if the file is missing (e.g. abbrev is "TBD" for unfilled
/// playoff matchups).
struct TeamLogo: View {
let abbrev: String
var size: CGFloat = 22
var body: some View {
Group {
if let image = Self.loadImage(for: abbrev) {
Image(uiImage: image)
.resizable()
.interpolation(.high)
.scaledToFit()
} else {
Image(systemName: "shield")
.resizable()
.scaledToFit()
.foregroundStyle(.tertiary)
}
}
.frame(width: size, height: size)
}
/// Bundle lookup is trivial but image decoding isn't free cache by
/// abbrev so scrolling through 16+ rows doesn't repeatedly hit disk.
private static var cache: [String: UIImage] = [:]
private static func loadImage(for abbrev: String) -> UIImage? {
if let cached = cache[abbrev] { return cached }
guard let url = Bundle.main.url(
forResource: abbrev, withExtension: "png", subdirectory: "TeamLogos"
), let image = UIImage(contentsOfFile: url.path) else {
return nil
}
cache[abbrev] = image
return image
}
}