Files
sodalive-ios/SodaLive/Sources/Live/Reservation/MyLiveReservationItemView.swift
Yu Sung 6fc6360f23 feat: 메인 라이브
- 라이브 예약중 UI 적용
2025-07-22 05:29:50 +09:00

208 lines
7.9 KiB
Swift

//
// MyLiveReservationItemView.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import SwiftUI
import Kingfisher
struct MyLiveReservationItemView: View {
let item: GetRoomListResponse
let index: Int
@State var dateDic: [String: String] = [:]
var body: some View {
VStack(alignment: .leading, spacing: 8) {
if index == 0 {
HStack(spacing: 8) {
Image("ic_mic_colored")
Text("내가 개설한 라이브")
.font(.custom(Font.preBold.rawValue, size: 18))
.foregroundColor(Color(hex: "80D8FF"))
}
}
HStack(spacing: 16) {
ZStack(alignment: .topLeading) {
KFImage(URL(string: item.creatorProfileImage))
.cancelOnDisappear(true)
.resizable()
.scaledToFill()
.frame(width: 100, height: 100, alignment: .top)
.cornerRadius(16)
.clipped()
if item.isPrivateRoom {
Image("ic_lock")
.resizable()
.frame(width: 20, height: 20)
.padding(4)
.background(Color(hex: "333333").opacity(0.7))
.clipShape(Circle())
.padding(.leading, 4)
.padding(.top, 4)
}
}
VStack(alignment: .leading, spacing: 8) {
Text(item.creatorNickname)
.font(.custom(Font.preRegular.rawValue, size: 18))
.foregroundColor(.white)
.lineLimit(1)
.truncationMode(.tail)
Text(item.title)
.font(.custom(Font.preRegular.rawValue, size: 16))
.foregroundColor(Color(hex: "B0BEC5"))
.lineLimit(1)
.truncationMode(.tail)
HStack(spacing: 0) {
Text("\(dateDic["dayOfWeek"] ?? "")")
.font(.custom(Font.preRegular.rawValue, size: 14))
.foregroundColor(Color(hex: "78909C"))
Text("|")
.font(.custom(Font.preRegular.rawValue, size: 14))
.foregroundColor(Color(hex: "78909C"))
Text("\(dateDic["time"] ?? "")")
.font(.custom(Font.preRegular.rawValue, size: 14))
.foregroundColor(Color(hex: "98A2F6"))
}
}
Spacer()
VStack(alignment: .trailing, spacing: 8) {
VStack(spacing: 4) {
Text("\(dateDic["month"] ?? "")")
.font(.custom(Font.preBold.rawValue, size: 14))
.foregroundColor(.white)
.padding(.vertical, 6)
.frame(maxWidth: .infinity)
.background(Color(hex: "FF5C49"))
.cornerRadius(16, corners: [.topLeft, .topRight])
Text("\(dateDic["day"] ?? "")")
.font(.custom(Font.preBold.rawValue, size: 14))
.foregroundColor(Color(hex: "263238"))
.padding(.vertical, 6)
.frame(maxWidth: .infinity)
.background(Color(hex: "FFFFFF"))
.cornerRadius(16, corners: [.bottomLeft, .bottomRight])
}
if item.price > 0 {
HStack(spacing: 2) {
Image("ic_can_circle")
.resizable()
.frame(width: 12, height: 12)
Text("\(item.price)")
.font(.custom(Font.preRegular.rawValue, size: 12))
.foregroundColor(.white)
}
.padding(4)
.frame(maxWidth: .infinity)
.background(Color(hex: "3b5ff1"))
.cornerRadius(4)
} else {
Text("무료")
.font(.custom(Font.preRegular.rawValue, size: 14))
.foregroundColor(Color(hex: "#263238"))
.padding(4)
.frame(maxWidth: .infinity)
.background(Color.white)
.cornerRadius(4)
}
}
.frame(width: 55)
}
.padding(10)
.background(Color(hex: "263238"))
.cornerRadius(16)
.overlay(
RoundedRectangle(cornerRadius: 16)
.stroke(Color(hex: "3bb9f1"), lineWidth: 1)
)
.onAppear {
self.dateDic = parseUtcIsoLocalDateTime(item.beginDateTimeUtc)
}
}
}
func parseUtcIsoLocalDateTime(_ utcString: String) -> [String: String] {
// 1. : "yyyy-MM-dd'T'HH:mm:ss"
let utcFormatter = DateFormatter()
utcFormatter.dateFormat = "yyyy-MM-dd'T'HH:mm:ss"
utcFormatter.locale = Locale.current
utcFormatter.timeZone = TimeZone(abbreviation: "UTC")
// 2. Date
guard let date = utcFormatter.date(from: utcString) else {
return [:] //
}
// 3~6. Formatter ( )
let localFormatter = DateFormatter()
localFormatter.locale = Locale.current
localFormatter.timeZone = TimeZone.current
// 3. (1~12)
localFormatter.dateFormat = "M"
let month = localFormatter.string(from: date)
// 4. (1~31)
localFormatter.dateFormat = "d"
let day = localFormatter.string(from: date)
// 5. (: "Mon", "")
localFormatter.dateFormat = "E"
let dayOfWeek = localFormatter.string(from: date)
// 6. (: "AM 05:00")
localFormatter.dateFormat = "a hh:mm"
let time = localFormatter.string(from: date)
return [
"month": month,
"day": day,
"dayOfWeek": dayOfWeek,
"time": time
]
}
}
struct MyLiveReservationItemView_Previews: PreviewProvider {
static var previews: some View {
MyLiveReservationItemView(
item: GetRoomListResponse(
roomId: 99,
title: "test",
content: "testtest",
beginDateTime: "2022.05.23 Mon 03:00 PM",
beginDateTimeUtc: "2025-08-10T15:00:00",
numberOfParticipate: 0,
numberOfPeople: 5,
coverImageUrl: "https://test-cf.sodalive.net/profile/default-profile.png",
isAdult: false,
price: 10000,
tags: ["팬미팅", "힐링"],
channelName: nil,
creatorProfileImage: "https://test-cf.sodalive.net/profile/default-profile.png",
creatorNickname: "user8",
creatorId: 19,
isReservation: false,
isPrivateRoom: true
),
index: 0
)
}
}