92 lines
2.4 KiB
Swift
92 lines
2.4 KiB
Swift
import SwiftUI
|
|
|
|
struct MainHomeView: View {
|
|
let onTapCanCharge: () -> Void
|
|
let onTapSearch: () -> Void
|
|
let onTapNotificationList: () -> Void
|
|
let onTapLive: (Int) -> Void
|
|
let onTapCreator: (Int) -> Void
|
|
let onTapContent: (Int) -> Void
|
|
let onTapCharacter: (Int) -> Void
|
|
let onTapCommunity: (Int) -> Void
|
|
|
|
@State private var selectedTab: MainHomeTab = .recommendation
|
|
|
|
var body: some View {
|
|
VStack(spacing: 0) {
|
|
HomeTitleBar {
|
|
HStack(spacing: 14) {
|
|
Image("ic_bar_cash")
|
|
.onTapGesture { onTapCanCharge() }
|
|
|
|
Image("ic_bar_search")
|
|
.onTapGesture { onTapSearch() }
|
|
|
|
Image("ic_bar_bell")
|
|
.onTapGesture { onTapNotificationList() }
|
|
}
|
|
}
|
|
|
|
TextTabBar(
|
|
items: MainHomeTab.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:
|
|
MainHomeRecommendationView(
|
|
onTapLive: onTapLive,
|
|
onTapCreator: onTapCreator,
|
|
onTapContent: onTapContent,
|
|
onTapCharacter: onTapCharacter,
|
|
onTapCommunity: onTapCommunity
|
|
)
|
|
case .ranking:
|
|
MainHomeRankingView()
|
|
case .following:
|
|
MainHomeFollowingView()
|
|
}
|
|
}
|
|
}
|
|
|
|
private enum MainHomeTab: CaseIterable, Hashable {
|
|
case recommendation
|
|
case ranking
|
|
case following
|
|
|
|
var title: String {
|
|
switch self {
|
|
case .recommendation:
|
|
return "추천"
|
|
case .ranking:
|
|
return "랭킹"
|
|
case .following:
|
|
return "팔로잉"
|
|
}
|
|
}
|
|
}
|
|
|
|
struct MainHomeView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
MainHomeView(
|
|
onTapCanCharge: {},
|
|
onTapSearch: {},
|
|
onTapNotificationList: {},
|
|
onTapLive: { _ in },
|
|
onTapCreator: { _ in },
|
|
onTapContent: { _ in },
|
|
onTapCharacter: { _ in },
|
|
onTapCommunity: { _ in }
|
|
)
|
|
}
|
|
}
|