Files
sodalive-ios/SodaLive/Sources/Live/Now/LiveNowItemView.swift

162 lines
5.6 KiB
Swift

//
// LiveNowItemView.swift
// SodaLive
//
// Created by klaus on 2023/08/14.
//
import SwiftUI
import Kingfisher
struct LiveNowItemView: View {
let item: GetRoomListResponse
let itemWidth: CGFloat?
private let defaultWidth: CGFloat = 144
private let defaultHeight: CGFloat = 204
private var resolvedWidth: CGFloat {
itemWidth ?? defaultWidth
}
private var resolvedHeight: CGFloat {
resolvedWidth * defaultHeight / defaultWidth
}
private var tagsToShow: [String] {
Array(item.tags.prefix(2))
}
var body: some View {
VStack(spacing: 8) {
ZStack(alignment: .top) {
HStack(spacing: 0) {
if item.isPrivateRoom {
Image("ic_lock")
.resizable()
.frame(width: 20, height: 20)
}
Spacer()
}
VStack(spacing: 0) {
ZStack(alignment: .bottom) {
ZStack {
DownsampledKFImage(
url: URL(string: item.creatorProfileImage),
size: CGSize(width: 72, height: 72)
)
.clipShape(Circle())
}
.frame(width: 84, height: 84)
.overlay {
Circle()
.strokeBorder(lineWidth: 3)
.foregroundColor(.button)
}
Image("img_live")
.resizable()
.frame(width: 50, height: 18)
}
Spacer()
Text(item.creatorNickname)
.appFont(size: 16, weight: .regular)
.foregroundColor(.white)
.padding(.horizontal, 2)
Text(item.title)
.appFont(size: 12, weight: .regular)
.foregroundColor(Color(hex: "#B0BEC5"))
.lineLimit(1)
.truncationMode(.tail)
.padding(.top, 4)
.padding(.horizontal, 2)
Spacer()
if item.price > 0 {
HStack(spacing: 2) {
Image("ic_can")
.resizable()
.scaledToFit()
.frame(width: 16)
Text("\(item.price)")
.appFont(size: 14, weight: .regular)
.foregroundColor(.white)
}
.padding(.vertical, 4)
.frame(maxWidth: .infinity)
.background(Color(hex: "3b5ff1"))
.cornerRadius(999)
.padding(.horizontal, 2)
.padding(.bottom, 2)
} else {
Text("무료")
.appFont(size: 14, weight: .regular)
.foregroundColor(Color(hex: "#263238"))
.padding(.vertical, 4)
.frame(maxWidth: .infinity)
.background(Color.white)
.cornerRadius(999)
.padding(.horizontal, 2)
.padding(.bottom, 2)
}
}
}
.padding(10)
.frame(width: resolvedWidth, height: resolvedHeight, alignment: .top)
.background(Color(hex: "263238"))
.cornerRadius(16)
if !tagsToShow.isEmpty {
HStack(spacing: 4) {
ForEach(tagsToShow, id: \.self) { tag in
Text(tag)
.appFont(size: 12, weight: .regular)
.foregroundColor(.white)
.padding(.horizontal, 8)
.padding(.vertical, 4)
.background(Color(hex: "37474F"))
.cornerRadius(8)
}
Spacer()
}
.padding(.horizontal, 4)
}
}
}
}
struct LiveNowItemView_Previews: PreviewProvider {
static var previews: some View {
LiveNowItemView(
item: GetRoomListResponse(
roomId: 99,
title: "testtesttesttesttesttesttesttesttesttesttesttesttesttesttesttest",
content: "testtest",
beginDateTimeUtc: "2025-08-10T15:00:00",
numberOfParticipate: 3,
numberOfPeople: 5,
coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
isAdult: true,
price: 0,
tags: ["팬미팅", "힐링"],
channelName: nil,
creatorProfileImage: "https://test-cf.sodalive.net/profile/default-profile.png",
creatorNickname: "user8",
creatorId: 19,
isReservation: false,
isPrivateRoom: false
),
itemWidth: 144
)
}
}