Files
MLBApp/mlbTVOS/Views/Components/PitcherHeadshotView.swift
2026-03-26 15:37:31 -05:00

54 lines
1.5 KiB
Swift

import SwiftUI
struct PitcherHeadshotView: View {
let url: URL?
var teamCode: String?
var name: String?
var size: CGFloat = 56
var body: some View {
VStack(spacing: 6) {
AsyncImage(url: url) { phase in
switch phase {
case .success(let image):
image
.resizable()
.aspectRatio(contentMode: .fill)
case .failure:
fallbackImage
default:
fallbackImage
.redacted(reason: .placeholder)
}
}
.frame(width: size, height: size)
.clipShape(Circle())
.overlay(
Circle()
.strokeBorder(
teamCode.map { TeamAssets.color(for: $0) } ?? .gray,
lineWidth: 2
)
)
if let name {
Text(name)
.font(.system(size: 13, weight: .medium))
.foregroundStyle(.secondary)
.lineLimit(1)
}
}
}
@ViewBuilder
private var fallbackImage: some View {
ZStack {
Circle()
.fill(.gray.opacity(0.3))
Image(systemName: "person.fill")
.font(.system(size: size * 0.4))
.foregroundStyle(.secondary)
}
}
}