Files
sodalive-ios/SodaLive/Sources/Chat/Character/CharacterItemView.swift
2025-09-11 21:23:46 +09:00

69 lines
2.0 KiB
Swift

//
// CharacterItemView.swift
// SodaLive
//
// Created by klaus on 8/29/25.
//
import SwiftUI
import Kingfisher
struct CharacterItemView: View {
let character: Character
let size: CGFloat
let rank: Int
let isShowRank: Bool
private var capHeight: CGFloat {
UIFont(name: Font.preBold.rawValue, size: 72)?.capHeight ?? 72
}
var body: some View {
VStack(alignment: .leading, spacing: 4) {
ZStack(alignment: .bottomLeading) {
KFImage(URL(string: character.imageUrl))
.placeholder { Color.gray.opacity(0.2) }
.retry(maxCount: 2, interval: .seconds(1))
.cancelOnDisappear(true)
.resizable()
.scaledToFill()
.frame(width: size, height: size)
.clipped()
.cornerRadius(12)
if isShowRank {
Text("\(rank)")
.font(.custom(Font.preBold.rawValue, size: 72))
.foregroundColor(.white)
.lineLimit(1)
.frame(height: capHeight)
}
}
Text(character.name)
.font(.custom(Font.preRegular.rawValue, size: 18))
.foregroundColor(.white)
.lineLimit(1)
.truncationMode(.tail)
if let desc = character.description, !desc.isEmpty {
Text(desc)
.font(.custom(Font.preRegular.rawValue, size: 14))
.foregroundColor(Color(hex: "78909C"))
.lineLimit(1)
}
}
.frame(width: size, alignment: .leading)
}
}
#Preview {
CharacterItemView(
character: Character(characterId: 1, name: "찰리", description: "새로운 친구", imageUrl: "https://picsum.photos/300"),
size: 168,
rank: 20,
isShowRank: true
)
}