66 lines
1.8 KiB
Swift
66 lines
1.8 KiB
Swift
import SwiftUI
|
|
|
|
struct CreatorProfileItem: View {
|
|
let imageUrl: String?
|
|
let name: String
|
|
let subtitle: String?
|
|
let action: (() -> Void)?
|
|
|
|
init(
|
|
imageUrl: String?,
|
|
name: String,
|
|
subtitle: String? = nil,
|
|
action: (() -> Void)? = nil
|
|
) {
|
|
self.imageUrl = imageUrl
|
|
self.name = name
|
|
self.subtitle = subtitle
|
|
self.action = action
|
|
}
|
|
|
|
var body: some View {
|
|
Button {
|
|
action?()
|
|
} label: {
|
|
VStack(alignment: .center, spacing: SodaSpacing.s8) {
|
|
profileImage
|
|
|
|
VStack(alignment: .center, spacing: 2) {
|
|
Text(name)
|
|
.appFont(.body4)
|
|
.foregroundColor(.white)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
|
|
if let subtitle, !subtitle.isEmpty {
|
|
Text(subtitle)
|
|
.appFont(.caption2)
|
|
.foregroundColor(Color.gray500)
|
|
.lineLimit(1)
|
|
.truncationMode(.tail)
|
|
}
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
.buttonStyle(.plain)
|
|
.disabled(action == nil)
|
|
}
|
|
|
|
private var profileImage: some View {
|
|
DownsampledKFImage(url: URL(string: imageUrl ?? ""), size: CGSize(width: 72, height: 72))
|
|
.background(Color.gray800)
|
|
.clipShape(Circle())
|
|
}
|
|
}
|
|
|
|
struct CreatorProfileItem_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
CreatorProfileItem(imageUrl: nil, name: "크리에이터", subtitle: "방금 활동")
|
|
.frame(width: 96)
|
|
.padding(SodaSpacing.s20)
|
|
.background(Color.black)
|
|
.previewLayout(.sizeThatFits)
|
|
}
|
|
}
|