151 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			151 lines
		
	
	
		
			5.4 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  LiveRoomDonationRankingItemView.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 2023/08/15.
 | 
						|
//
 | 
						|
 | 
						|
import SwiftUI
 | 
						|
import Kingfisher
 | 
						|
 | 
						|
struct LiveRoomDonationRankingItemView: View {
 | 
						|
    
 | 
						|
    let index: Int
 | 
						|
    let item: GetLiveRoomDonationItem
 | 
						|
    let itemCount: Int
 | 
						|
    
 | 
						|
    let rankingCrawns = ["ic_crown_1", "ic_crown_2", "ic_crown_3"]
 | 
						|
    let rankingColors = [
 | 
						|
        [Color(hex: "ffdc00"), Color(hex: "ffb600")],
 | 
						|
        [Color(hex: "ffffff"), Color(hex: "9f9f9f")],
 | 
						|
        [Color(hex: "e6a77a"), Color(hex: "c67e4a")],
 | 
						|
        [Color(hex: "ffffff").opacity(0), Color(hex: "ffffff").opacity(0)]
 | 
						|
    ]
 | 
						|
    
 | 
						|
    var body: some View {
 | 
						|
        HStack(spacing: 0) {
 | 
						|
            ZStack {
 | 
						|
                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())
 | 
						|
                    .overlay(
 | 
						|
                        Circle()
 | 
						|
                            .stroke(
 | 
						|
                                AngularGradient(colors: rankingColors[index < 4 ? index : 3], center: .center),
 | 
						|
                                lineWidth: 3
 | 
						|
                            )
 | 
						|
                    )
 | 
						|
                
 | 
						|
                if index < 3 {
 | 
						|
                    VStack(alignment: .trailing, spacing: 0) {
 | 
						|
                        Spacer()
 | 
						|
                        
 | 
						|
                        Image(rankingCrawns[index])
 | 
						|
                            .resizable()
 | 
						|
                            .frame(width: 25, height: 25)
 | 
						|
                    }
 | 
						|
                    .frame(width: 63, height: 63, alignment: .trailing)
 | 
						|
                }
 | 
						|
            }
 | 
						|
            .frame(width: 63, height: 63)
 | 
						|
            
 | 
						|
            Text("\(index + 1)")
 | 
						|
                .font(.custom(Font.bold.rawValue, size: 13.3))
 | 
						|
                .foregroundColor(Color(hex: "eeeeee"))
 | 
						|
                .padding(.leading, 20)
 | 
						|
                .padding(.trailing, 13.3)
 | 
						|
            
 | 
						|
            let nickname = item.nickname.count > 10 ? "\(String(item.nickname.prefix(10)))..." : item.nickname
 | 
						|
            Text(nickname)
 | 
						|
                .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                .foregroundColor(Color(hex: "eeeeee"))
 | 
						|
            
 | 
						|
            Spacer()
 | 
						|
            
 | 
						|
            VStack(alignment: .trailing, spacing: 8) {
 | 
						|
                if item.can > 0 {
 | 
						|
                    HStack(spacing: 4) {
 | 
						|
                        Text("\(item.can)")
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                            .foregroundColor(Color.button)
 | 
						|
                        
 | 
						|
                        Text("캔")
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                            .foregroundColor(Color(hex: "eeeeee"))
 | 
						|
                    }
 | 
						|
                }
 | 
						|
                
 | 
						|
                if item.secretCan > 0 {
 | 
						|
                    HStack(spacing: 4) {
 | 
						|
                        Text("비밀")
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                            .foregroundColor(Color.gray11)
 | 
						|
                            .padding(.horizontal, 3.3)
 | 
						|
                            .padding(.vertical, 2.7)
 | 
						|
                            .background(Color(hex: "fedc00"))
 | 
						|
                            .cornerRadius(2.7)
 | 
						|
                        
 | 
						|
                        Text("\(item.secretCan)")
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                            .foregroundColor(Color(hex: "fedc00"))
 | 
						|
                        
 | 
						|
                        Text("캔")
 | 
						|
                            .font(.custom(Font.medium.rawValue, size: 13.3))
 | 
						|
                            .foregroundColor(Color(hex: "eeeeee"))
 | 
						|
                    }
 | 
						|
                }
 | 
						|
            }
 | 
						|
        }
 | 
						|
        .padding(.horizontal, isTop3Index(index: index) ? 20 : 0)
 | 
						|
        .padding(.top, getTopPadding(index: index))
 | 
						|
        .padding(.bottom, getBottomPadding(index: index))
 | 
						|
        .background(Color(hex: "13181b").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 {
 | 
						|
    LiveRoomDonationRankingItemView(
 | 
						|
        index: 0,
 | 
						|
        item: GetLiveRoomDonationItem(profileImage: "", nickname: "테스트", userId: 1, can: 10, secretCan: 30),
 | 
						|
        itemCount: 3
 | 
						|
    )
 | 
						|
}
 |