// // LiveRoomHeartRankingItemView.swift // SodaLive // // Created by klaus on 11/11/24. // import SwiftUI import Kingfisher struct LiveRoomHeartRankingItemView: View { let index: Int let item: GetLiveRoomHeartListItem let itemCount: Int let crowns = ["img_rank_1", "img_rank_2", "img_rank_3"] var body: some View { HStack(spacing: 0) { ZStack(alignment: .center) { KFImage(URL(string: item.profileImage)) .cancelOnDisappear(true) .downsampling(size: CGSize(width: 60, height: 60)) .resizable() .scaledToFill() .frame(width: 60, height: 60, alignment: .top) .clipShape(Circle()) if index < 3 { Image(crowns[index]) .resizable() .frame(width: 77, height: 75) } } .frame(width: 77, height: 75) Text("\(index + 1)") .appFont(size: 13.3, weight: .bold) .foregroundColor(Color.grayee) .padding(.leading, 20) .padding(.trailing, 13.3) let nickname = item.nickname.count > 10 ? "\(String(item.nickname.prefix(10)))..." : item.nickname Text(nickname) .appFont(size: 13.3, weight: .medium) .foregroundColor(Color.grayee) Spacer() VStack(alignment: .trailing, spacing: 8) { if item.heart > 0 { HStack(spacing: 4) { Text("\(item.heart)") .appFont(size: 13.3, weight: .medium) .foregroundColor(Color.button) Text("하트") .appFont(size: 13.3, weight: .medium) .foregroundColor(Color.grayee) } } } } .padding(.horizontal, isTop3Index(index: index) ? 20 : 0) .padding(.top, getTopPadding(index: index)) .padding(.bottom, getBottomPadding(index: index)) .background(Color.bg.opacity(isTop3Index(index: index) ? 1 : 0)) .cornerRadius(4.7, corners: cornerRadiusConers(index: index)) .padding(.horizontal, isTop3Index(index: index) ? 0 : 6.7) } private func isTop3Index(index: Int) -> Bool { return index == 0 || index == 1 || index == 2 } private func getTopPadding(index: Int) -> CGFloat { if index == 0 || index == 3 { return 20 } else { return 6.7 } } private func getBottomPadding(index: Int) -> CGFloat { if (index == 0 && itemCount == 1) || (index == 1 && itemCount == 2) || index == 2 { return 20 } else { return 6.7 } } private func cornerRadiusConers(index: Int) -> UIRectCorner { if (index == 0 && itemCount == 1) { return [.topLeft, .topRight, .bottomLeft, .bottomRight] } else if index == 0 { return [.topLeft, .topRight] } else if (index == 1 && itemCount == 2) || index == 2 { return [.bottomLeft, .bottomRight] } else { return [] } } } #Preview { LiveRoomHeartRankingItemView( index: 0, item: GetLiveRoomHeartListItem(profileImage: "", nickname: "테스트", heart: 10), itemCount: 3 ) }