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

88 lines
2.8 KiB
Swift

//
// HomeCreatorRankingItemView.swift
// SodaLive
//
// Created by klaus on 7/11/25.
//
import SwiftUI
import Kingfisher
struct HomeCreatorRankingItemView: View {
let rank: Int
@State var item: GetExplorerSectionCreatorResponse
let onClickFollow: (Int, Bool) -> Void
let crowns = ["rank_1", "rank_2", "rank_3"]
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
var body: some View {
ZStack(alignment: .topLeading) {
VStack(spacing: 0) {
DownsampledKFImage(
url: URL(string: item.profileImageUrl),
size: CGSize(width: 84, height: 84)
)
.clipShape(Circle())
Text(item.nickname)
.font(.custom(Font.preRegular.rawValue, size: 16))
.foregroundColor(.white)
.padding(.top, 20)
Spacer()
if item.id != UserDefaults.int(forKey: .userId) {
Text(item.follow ? "팔로잉" : "팔로우")
.font(.custom(Font.preRegular.rawValue, size: 14))
.padding(.vertical, 4)
.frame(maxWidth: .infinity)
.background(
item.follow ? Color(hex: "455a64") : Color.white
)
.cornerRadius(999)
.foregroundColor(
item.follow ? .white : Color(hex: "263238")
)
.onTapGesture {
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
item.follow = !item.follow
}
onClickFollow(item.id, item.follow)
}
}
}
.padding(16)
.frame(width: 144, height: 204)
.background(Color(hex: "263238"))
.cornerRadius(16)
.padding(.top, 20)
if rank <= 3 {
Image(crowns[rank - 1])
.resizable()
.frame(width: 40, height: 40)
.padding(.leading, 10)
}
}
}
}
#Preview {
HomeCreatorRankingItemView(
rank: 1,
item: GetExplorerSectionCreatorResponse(
id: 1,
nickname: "유빈ASMR",
tags: "",
profileImageUrl: "https://cf.sodalive.net/profile/34806/34806-profile-49db6b45-bb1e-4dc7-917e-1a614a853f5f-4232-1752158072656",
follow: true
),
onClickFollow: { _, _ in }
)
}