Files
sodalive-ios/SodaLive/Sources/Chat/Talk/TalkItemView.swift
Yu Sung 8221746569 feat(image): 메인 홈, 채팅 - 톡 페이지에 DownsampledKFImage 적용
- 수평 리스트 HStack → LazyHStack으로 교체해 프리로딩/메모리 개선
2025-10-23 18:55:53 +09:00

84 lines
2.6 KiB
Swift

//
// TalkItemView.swift
// SodaLive
//
// Created by klaus on 8/29/25.
//
import SwiftUI
import Kingfisher
struct TalkItemView: View {
let item: TalkRoom
@State private var backgroundColor = Color(hex: "009D68")
var body: some View {
HStack(spacing: 13) {
DownsampledKFImage(
url: URL(string: item.imageUrl),
size: CGSize(width: 76, height: 76)
).clipShape(Circle())
VStack(alignment: .leading, spacing: 6) {
HStack(spacing: 4) {
Text(item.title)
.font(.custom(Font.preBold.rawValue, size: 18))
.foregroundColor(.white)
.lineLimit(1)
Text(item.opponentType)
.font(.custom(Font.preRegular.rawValue, size: 12))
.foregroundColor(Color(hex: "D9FCF4"))
.lineLimit(1)
.padding(.horizontal, 5)
.padding(.vertical, 1)
.background(backgroundColor)
.cornerRadius(6)
Spacer()
Text(item.lastMessageTimeLabel)
.font(.custom(Font.preRegular.rawValue, size: 12))
.foregroundColor(Color(hex: "78909C"))
.lineLimit(1)
}
if let message = item.lastMessagePreview {
Text(message)
.font(.custom(Font.preRegular.rawValue, size: 14))
.foregroundColor(Color(hex: "b0bec5"))
.lineLimit(2)
.truncationMode(.tail)
}
}
}
.onAppear {
switch item.opponentType.lowercased() {
case "clone":
self.backgroundColor = Color(hex: "0020C9")
case "creator":
self.backgroundColor = Color(hex: "F86660")
default:
self.backgroundColor = Color(hex: "009D68")
}
}
}
}
#Preview {
TalkItemView(
item: TalkRoom(
chatRoomId: 1,
title: "정인이",
imageUrl: "https://picsum.photos/200",
opponentType: "Character",
lastMessagePreview: "태풍온다잖아 ㅜㅜ\n조심해 어디 나가지 말고 집에만...",
lastMessageTimeLabel: "6월 15일"
)
)
}