feat(character): 캐릭터 메인 화면 구현 및 Combine 기반 리팩터링
- 배너/최근/신규/큐레이션 섹션 UI 구성 및 데이터 바인딩 - 네트워크 이미지 로더를 Kingfisher(KFImage)로 교체하여 캐싱/재시도 지원 - CharacterApi에 토큰 헤더 포함, GET /api/chat/character/main 연동
This commit is contained in:
12
SodaLive/Sources/Chat/Character/Recent/RecentCharacter.swift
Normal file
12
SodaLive/Sources/Chat/Character/Recent/RecentCharacter.swift
Normal file
@@ -0,0 +1,12 @@
|
||||
//
|
||||
// RecentCharacter.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 8/29/25.
|
||||
//
|
||||
|
||||
struct RecentCharacter: Decodable {
|
||||
let characterId: Int
|
||||
let name: String
|
||||
let imageUrl: String
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// RecentCharacterItemView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 8/29/25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
import Kingfisher
|
||||
|
||||
struct RecentCharacterItemView: View {
|
||||
let character: RecentCharacter
|
||||
|
||||
var body: some View {
|
||||
VStack(spacing: 6) {
|
||||
KFImage(URL(string: character.imageUrl))
|
||||
.placeholder { Circle().fill(Color.gray.opacity(0.2)) }
|
||||
.retry(maxCount: 2, interval: .seconds(1))
|
||||
.cancelOnDisappear(true)
|
||||
.resizable()
|
||||
.scaledToFill()
|
||||
.frame(width: 76, height: 76)
|
||||
.clipShape(Circle())
|
||||
|
||||
Text(character.name)
|
||||
.font(.custom(Font.preRegular.rawValue, size: 18))
|
||||
.foregroundColor(.white)
|
||||
.lineLimit(1)
|
||||
.frame(maxWidth: 76)
|
||||
.multilineTextAlignment(.center)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
RecentCharacterItemView(
|
||||
character: RecentCharacter(characterId: 1, name: "앨리스", imageUrl: "https://picsum.photos/200")
|
||||
)
|
||||
.background(Color.black)
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// RecentCharacterSectionView.swift
|
||||
// SodaLive
|
||||
//
|
||||
// Created by klaus on 8/29/25.
|
||||
//
|
||||
|
||||
import SwiftUI
|
||||
|
||||
struct RecentCharacterSectionView: View {
|
||||
let titleCount: Int
|
||||
let items: [RecentCharacter]
|
||||
var onTap: (RecentCharacter) -> Void = { _ in }
|
||||
|
||||
var body: some View {
|
||||
VStack(alignment: .leading, spacing: 12) {
|
||||
HStack(spacing: 0) {
|
||||
Text("최근 대화한 캐릭터 ")
|
||||
.font(.custom(Font.preBold.rawValue, size: 20))
|
||||
.foregroundColor(.white)
|
||||
Text("\(titleCount)")
|
||||
.font(.custom(Font.preBold.rawValue, size: 20))
|
||||
.foregroundColor(Color(hex: "FDCA2F"))
|
||||
Spacer()
|
||||
}
|
||||
|
||||
ScrollView(.horizontal, showsIndicators: false) {
|
||||
HStack(spacing: 16) {
|
||||
ForEach(items.indices, id: \.self) { idx in
|
||||
let item = items[idx]
|
||||
RecentCharacterItemView(character: item)
|
||||
.onTapGesture { onTap(item) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#Preview {
|
||||
RecentCharacterSectionView(
|
||||
titleCount: 3,
|
||||
items: [
|
||||
RecentCharacter(characterId: 1, name: "라라", imageUrl: "https://picsum.photos/200"),
|
||||
RecentCharacter(characterId: 2, name: "마리", imageUrl: "https://picsum.photos/200"),
|
||||
RecentCharacter(characterId: 3, name: "Nana", imageUrl: "https://picsum.photos/200")
|
||||
]
|
||||
)
|
||||
.padding()
|
||||
.background(Color.black)
|
||||
}
|
||||
Reference in New Issue
Block a user