Files
sodalive-ios/SodaLive/Sources/Chat/Character/CharacterView.swift
2025-09-11 21:23:46 +09:00

108 lines
4.0 KiB
Swift

//
// CharacterView.swift
// SodaLive
//
// Created by klaus on 8/29/25.
//
import SwiftUI
struct CharacterView: View {
@StateObject var viewModel = CharacterViewModel()
private let horizontalPadding: CGFloat = 16
let onSelectCharacter: (Int) -> Void
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
ScrollView(.vertical, showsIndicators: false) {
VStack(alignment: .leading, spacing: 48) {
//
if !viewModel.banners.isEmpty {
AutoSlideCharacterBannerView(items: viewModel.banners) { banner in
onSelectCharacter(banner.characterId)
}
}
//
if !viewModel.recentCharacters.isEmpty {
RecentCharacterSectionView(
titleCount: viewModel.recentCharacters.count,
items: viewModel.recentCharacters
) { ch in
onSelectCharacter(ch.characterId)
}
}
//
if !viewModel.popularCharacters.isEmpty {
CharacterSectionView(
title: "인기 캐릭터",
items: viewModel.popularCharacters,
isShowRank: true
) { ch in
onSelectCharacter(ch.characterId)
}
}
//
if !viewModel.newCharacters.isEmpty {
CharacterSectionView(
title: "신규 캐릭터",
items: viewModel.newCharacters,
isShowRank: false
) { ch in
onSelectCharacter(ch.characterId)
}
}
// ( )
if !viewModel.curations.isEmpty {
VStack(alignment: .leading, spacing: 48) {
ForEach(viewModel.curations.indices, id: \.self) { idx in
let section = viewModel.curations[idx]
CharacterSectionView(
title: section.title,
items: section.characters,
isShowRank: false
) { ch in
onSelectCharacter(ch.characterId)
}
}
}
}
}
.padding(.bottom, 24)
}
.background(Color.black.ignoresSafeArea())
.onAppear {
if !viewModel.isLoading {
viewModel.getCharacterMain()
}
}
}
.popup(isPresented: $viewModel.isShowPopup, type: .toast, position: .top, autohideIn: 2) {
GeometryReader { geo in
HStack {
Spacer()
Text(viewModel.errorMessage)
.padding(.vertical, 13.3)
.frame(width: geo.size.width - 66.7, alignment: .center)
.font(.custom(Font.medium.rawValue, size: 12))
.background(Color.button)
.foregroundColor(Color.white)
.multilineTextAlignment(.center)
.cornerRadius(20)
.padding(.top, 66.7)
Spacer()
}
}
}
}
}
#Preview {
CharacterView(onSelectCharacter: { _ in })
}