Initial commit
This commit is contained in:
53
mlbTVOS/Views/Components/PitcherHeadshotView.swift
Normal file
53
mlbTVOS/Views/Components/PitcherHeadshotView.swift
Normal file
@@ -0,0 +1,53 @@
|
||||
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)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user