86 lines
2.7 KiB
Swift
86 lines
2.7 KiB
Swift
import SwiftUI
|
|
|
|
struct MainContentView: View {
|
|
let onTapCanCharge: () -> Void
|
|
let onTapSearch: () -> Void
|
|
let onTapNotificationList: () -> Void
|
|
let onTapContent: (Int) -> Void
|
|
let onTapBanner: (AudioBannerResponse) -> Void
|
|
let onTapSeries: (Int) -> Void
|
|
let onTapNewAndHotAll: () -> Void
|
|
|
|
@State private var selectedTab: MainContentTab = .recommendation
|
|
@StateObject private var allViewModel = MainContentAllViewModel()
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
HomeTitleBar {
|
|
HStack(spacing: SodaSpacing.s14) {
|
|
Image("ic_bar_cash")
|
|
.onTapGesture { onTapCanCharge() }
|
|
|
|
Image("ic_bar_search")
|
|
.onTapGesture { onTapSearch() }
|
|
|
|
Image("ic_bar_bell")
|
|
.onTapGesture { onTapNotificationList() }
|
|
}
|
|
}
|
|
|
|
TextTabBar(
|
|
items: MainContentTab.allCases,
|
|
selectedItem: $selectedTab,
|
|
title: { $0.title }
|
|
)
|
|
|
|
tabContent
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
.background(Color.black.ignoresSafeArea())
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var tabContent: some View {
|
|
switch selectedTab {
|
|
case .recommendation:
|
|
MainContentRecommendationView(
|
|
onTapContent: onTapContent,
|
|
onTapBanner: onTapBanner,
|
|
onTapSeries: onTapSeries,
|
|
onTapLatestAudioAll: { applyAllTab(type: .audio, sort: .latest) },
|
|
onTapNewAndHotAll: onTapNewAndHotAll,
|
|
onTapVoiceOnOnlyAll: { applyAllTab(type: .original, sort: .latest) },
|
|
onTapFreeAudioAll: { applyAllTab(type: .free, sort: .popular) },
|
|
onTapPointAudioAll: { applyAllTab(type: .point, sort: .popular) }
|
|
)
|
|
case .ranking:
|
|
MainContentRankingView(onTapContent: onTapContent)
|
|
case .all:
|
|
MainContentAllView(
|
|
viewModel: allViewModel,
|
|
onTapContent: onTapContent,
|
|
onTapSeries: onTapSeries
|
|
)
|
|
}
|
|
}
|
|
|
|
private func applyAllTab(type: MainContentAllType, sort: ContentSort) {
|
|
selectedTab = .all
|
|
allViewModel.apply(type: type, sort: sort)
|
|
}
|
|
}
|
|
|
|
struct MainContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MainContentView(
|
|
onTapCanCharge: {},
|
|
onTapSearch: {},
|
|
onTapNotificationList: {},
|
|
onTapContent: { _ in },
|
|
onTapBanner: { _ in },
|
|
onTapSeries: { _ in },
|
|
onTapNewAndHotAll: {}
|
|
)
|
|
}
|
|
}
|