102 lines
4.2 KiB
Swift
102 lines
4.2 KiB
Swift
//
|
|
// NewCharacterListView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 9/12/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
|
|
struct NewCharacterListView: View {
|
|
@StateObject private var viewModel = NewCharacterListViewModel()
|
|
|
|
private let horizontalPadding: CGFloat = 12
|
|
private let gridSpacing: CGFloat = 12
|
|
|
|
var body: some View {
|
|
Group { BaseView(isLoading: $viewModel.isLoading) {
|
|
VStack(spacing: 8) {
|
|
// Toolbar
|
|
DetailNavigationBar(title: String(localized: "신규 캐릭터 전체보기"))
|
|
|
|
VStack(alignment: .leading, spacing: 12) {
|
|
// 전체 n개
|
|
HStack(spacing: 0) {
|
|
Text("전체")
|
|
.appFont(size: 12, weight: .regular)
|
|
.foregroundColor(Color(hex: "e2e2e2"))
|
|
Text(" \(viewModel.totalCount)")
|
|
.appFont(size: 12, weight: .regular)
|
|
.foregroundColor(Color(hex: "ff5c49"))
|
|
Text("개")
|
|
.appFont(size: 12, weight: .regular)
|
|
.foregroundColor(Color(hex: "e2e2e2"))
|
|
Spacer()
|
|
}
|
|
.padding(.horizontal, 24)
|
|
|
|
// Grid 3열
|
|
GeometryReader { geo in
|
|
let width = (geo.size.width - (horizontalPadding * 2) - gridSpacing) / 2
|
|
|
|
ScrollView(.vertical, showsIndicators: false) {
|
|
LazyVGrid(
|
|
columns: Array(
|
|
repeating: GridItem(
|
|
.flexible(),
|
|
spacing: gridSpacing,
|
|
alignment: .topLeading
|
|
),
|
|
count: 2
|
|
),
|
|
alignment: .leading,
|
|
spacing: gridSpacing
|
|
) {
|
|
ForEach(viewModel.items.indices, id: \.self) { idx in
|
|
let item = viewModel.items[idx]
|
|
|
|
CharacterItemView(
|
|
character: item,
|
|
size: width,
|
|
rank: 0,
|
|
isShowRank: false
|
|
)
|
|
.onAppear { viewModel.loadMoreIfNeeded(currentIndex: idx) }
|
|
.onTapGesture { AppState.shared.setAppStep(step: .characterDetail(characterId: item.characterId)) }
|
|
}
|
|
}
|
|
.padding(.horizontal, horizontalPadding)
|
|
|
|
if viewModel.isLoadingMore {
|
|
HStack {
|
|
Spacer()
|
|
ProgressView()
|
|
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
|
.padding(.vertical, 16)
|
|
Spacer()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.frame(minHeight: 0, maxHeight: .infinity)
|
|
}
|
|
.padding(.vertical, 12)
|
|
.onAppear {
|
|
// 최초 1회만 로드하여 상세 진입 후 복귀 시 스크롤 위치가 유지되도록 함
|
|
if viewModel.items.isEmpty {
|
|
viewModel.fetch()
|
|
}
|
|
}
|
|
}
|
|
.background(Color.black)
|
|
}
|
|
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2)
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
NewCharacterListView()
|
|
.background(Color.black)
|
|
}
|