Files
sodalive-ios/SodaLive/Sources/Settings/Event/EventListView.swift

63 lines
2.3 KiB
Swift

//
// EventListView.swift
// SodaLive
//
// Created by klaus on 2023/08/10.
//
import SwiftUI
import Kingfisher
struct EventListView: View {
@ObservedObject var viewModel = EventListViewModel()
var body: some View {
BaseView(isLoading: $viewModel.isLoading) {
VStack(spacing: 0) {
DetailNavigationBar(title: "이벤트")
ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 15) {
ForEach(viewModel.events, id: \.self) { event in
KFImage(URL(string: event.thumbnailImageUrl))
.cancelOnDisappear(true)
.downsampling(
size: CGSize(
width: screenSize().width - 26.7,
height: (screenSize().width - 26.7) * 300 / 1000
)
)
.resizable()
.scaledToFill()
.frame(
width: screenSize().width - 26.7,
height: (screenSize().width - 26.7) * 300 / 1000
)
.contentShape(Rectangle())
.onTapGesture {
if let _ = event.detailImageUrl {
AppState.shared.setAppStep(step: .eventDetail(event: event))
} else if let link = event.link, link.trimmingCharacters(in: .whitespaces).count > 0, let url = URL(string: link), UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url)
}
}
}
}
}
.padding(.vertical, 13.3)
}
}
.sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2)
.onAppear {
viewModel.getEvents()
}
}
}
struct EventListView_Previews: PreviewProvider {
static var previews: some View {
EventListView()
}
}