38 lines
1.0 KiB
Swift
38 lines
1.0 KiB
Swift
//
|
|
// ProfileImageView.swift
|
|
// EmployeeDirectory
|
|
//
|
|
// Created by Matt Bruce on 3/3/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct ProfileImageView: View {
|
|
let urlString: String?
|
|
let size: CGFloat // Allows us to customize the image size
|
|
|
|
private let defaultImage = "person.circle.fill" // SF Symbol
|
|
|
|
var body: some View {
|
|
AsyncImage(url: URL(string: urlString ?? "")) { phase in
|
|
if let image = phase.image {
|
|
image.resizable()
|
|
} else if phase.error != nil || urlString == nil {
|
|
Image(systemName: defaultImage)
|
|
.resizable()
|
|
.foregroundColor(.gray)
|
|
} else {
|
|
ProgressView() // Show loader while fetching
|
|
}
|
|
}
|
|
.scaledToFill()
|
|
.frame(width: size, height: size)
|
|
.clipShape(Circle()) // Rounded shape
|
|
.overlay(Circle().stroke(Color.gray, lineWidth: 1)) // Border
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
ProfileImageView(urlString: MockEmployeeService.sample.photoURLSmall, size: 100).padding()
|
|
}
|