117 lines
4.4 KiB
Swift
117 lines
4.4 KiB
Swift
//
|
|
// HomeAuditionView.swift
|
|
// SodaLive
|
|
//
|
|
// Created by klaus on 7/12/25.
|
|
//
|
|
|
|
import SwiftUI
|
|
import Kingfisher
|
|
|
|
struct HomeAuditionView: View {
|
|
|
|
@State private var currentIndex = 0
|
|
@State private var timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
|
|
@AppStorage("token") private var token: String = UserDefaults.string(forKey: UserDefaultsKey.token)
|
|
|
|
let items: [GetAuditionListItem]
|
|
|
|
var body: some View {
|
|
VStack(spacing: 16) {
|
|
TabView(selection: $currentIndex) {
|
|
ForEach(0..<items.count, id: \.self) { index in
|
|
let item = items[index]
|
|
if let url = item.imageUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed) {
|
|
KFImage(URL(string: url))
|
|
.cancelOnDisappear(true)
|
|
.resizable()
|
|
.scaledToFill()
|
|
.frame(
|
|
width: screenSize().width - 48,
|
|
height: (screenSize().width - 48) * 530 / 1000,
|
|
alignment: .center
|
|
)
|
|
.tag(index)
|
|
.onTapGesture {
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
AppState.shared.setAppStep(step: .auditionDetail(auditionId: item.id))
|
|
} else {
|
|
AppState.shared.setAppStep(step: .login)
|
|
}
|
|
}
|
|
} else {
|
|
KFImage(URL(string: item.imageUrl))
|
|
.cancelOnDisappear(true)
|
|
.resizable()
|
|
.scaledToFill()
|
|
.frame(
|
|
width: screenSize().width - 48,
|
|
height: (screenSize().width - 48) * 530 / 1000,
|
|
alignment: .center
|
|
)
|
|
.tag(index)
|
|
.onTapGesture {
|
|
if !token.trimmingCharacters(in: .whitespacesAndNewlines).isEmpty {
|
|
AppState.shared.setAppStep(step: .auditionDetail(auditionId: item.id))
|
|
} else {
|
|
AppState.shared.setAppStep(step: .login)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
.tabViewStyle(PageTabViewStyle(indexDisplayMode: .never))
|
|
.frame(
|
|
width: screenSize().width,
|
|
height: screenSize().width * 530 / 1000,
|
|
alignment: .center
|
|
)
|
|
|
|
HStack(spacing: 8) {
|
|
ForEach(0..<items.count, id: \.self) { index in
|
|
Capsule()
|
|
.foregroundColor(index == currentIndex ? .button : .gray77)
|
|
.frame(width: 10, height: 10)
|
|
.tag(index)
|
|
}
|
|
}
|
|
}
|
|
.onAppear {
|
|
timer = Timer.publish(every: 3, on: .main, in: .common).autoconnect()
|
|
}
|
|
.onDisappear {
|
|
timer.upstream.connect().cancel()
|
|
}
|
|
.onReceive(timer) { _ in
|
|
DispatchQueue.main.async {
|
|
withAnimation {
|
|
if currentIndex == items.count - 1 {
|
|
currentIndex = 0
|
|
} else {
|
|
currentIndex += 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
#Preview {
|
|
HomeAuditionView(
|
|
items: [
|
|
GetAuditionListItem(
|
|
id: 1,
|
|
title: "오디션 제목 테스트",
|
|
imageUrl: "https://test-cf.sodalive.net/audition/production/1/audition-2950c964-b460-4085-87e4-f76849c826ab-240-1735215756152",
|
|
isOff: false
|
|
),
|
|
GetAuditionListItem(
|
|
id: 3,
|
|
title: "스위치온",
|
|
imageUrl: "https://test-cf.sodalive.net/audition/production/3/audition-aa934579-c01a-4da2-89fd-cce70d51c612-4267-1735908116928",
|
|
isOff: false
|
|
)
|
|
]
|
|
)
|
|
}
|