// // EventDetailView.swift // SodaLive // // Created by klaus on 2023/08/10. // import SwiftUI import Kingfisher struct EventDetailView: View { @Environment(\.dismiss) private var dismiss @StateObject private var viewModel: EventDetailViewModel init(eventId: Int) { _viewModel = StateObject(wrappedValue: EventDetailViewModel(eventId: eventId)) } var body: some View { BaseView(isLoading: $viewModel.isLoading) { GeometryReader { proxy in VStack(spacing: 0) { DetailNavigationBar(title: I18n.Settings.Event.detailTitle, backAction: { viewModel.cancel() dismiss() }) ScrollView(.vertical, showsIndicators: false) { if case .loaded(let event) = viewModel.state, let detailImageUrl = event.detailImageUrl { KFImage(URL(string: detailImageUrl)) .cancelOnDisappear(true) .resizable() .scaledToFit() } } Spacer() if let url = viewModel.participationURL, UIApplication.shared.canOpenURL(url) { Button { UIApplication.shared.open(url) } label: { Text(I18n.Settings.Event.participateButton) .appFont(size: 18.3, weight: .bold) .foregroundColor(.white) .padding(.vertical, 16) .frame(width: screenSize().width - 26.7) .background(Color(hex: "3e737c")) .cornerRadius(10) .padding(13.3) .background(Color(hex: "222222")) .cornerRadius(16.7, corners: [.topLeft, .topRight]) } .buttonStyle(.plain) } if proxy.safeAreaInsets.bottom > 0 { Rectangle() .foregroundColor(Color(hex: "222222")) .frame(width: proxy.size.width, height: 15.3) } } .edgesIgnoringSafeArea(.bottom) } } .sodaToast(isPresented: $viewModel.isShowPopup, message: viewModel.errorMessage, autohideIn: 2) .onAppear { viewModel.load() } .onDisappear { viewModel.cancel() } .onReceive(viewModel.$state) { state in if state == .unavailable, viewModel.takeUnavailableDismissal() { dismiss() } } } } struct EventDetailView_Previews: PreviewProvider { static var previews: some View { EventDetailView(eventId: 0) } }