132 lines
3.9 KiB
Swift
132 lines
3.9 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
|
|
let onTapBanner: (RecommendationBannerResponse) -> Void
|
|
let onTapFollowAll: (@escaping () -> Void) -> Void
|
|
let onSelectFollowingTab: () -> Bool
|
|
let onTapFollowingLogin: () -> Void
|
|
let onTapFollowingAll: () -> Void
|
|
let onTapChatTab: () -> Void
|
|
let onTapChatRoom: (Int) -> Void
|
|
let onTapFollowingSchedule: (CreatorActivityType, 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: selectedTabBinding,
|
|
title: { $0.title }
|
|
)
|
|
|
|
tabContent
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
}
|
|
.background(Color.black.ignoresSafeArea())
|
|
}
|
|
|
|
private var selectedTabBinding: Binding<MainHomeTab> {
|
|
Binding(
|
|
get: { selectedTab },
|
|
set: { newValue in
|
|
if newValue == .following, onSelectFollowingTab() == false {
|
|
return
|
|
}
|
|
|
|
selectedTab = newValue
|
|
}
|
|
)
|
|
}
|
|
|
|
@ViewBuilder
|
|
private var tabContent: some View {
|
|
switch selectedTab {
|
|
case .recommendation:
|
|
MainHomeRecommendationView(
|
|
onTapLive: onTapLive,
|
|
onTapCreator: onTapCreator,
|
|
onTapContent: onTapContent,
|
|
onTapCharacter: onTapCharacter,
|
|
onTapCommunity: onTapCommunity,
|
|
onTapBanner: onTapBanner,
|
|
onTapFollowAll: onTapFollowAll
|
|
)
|
|
case .ranking:
|
|
MainHomeRankingView(onTapCreator: onTapCreator)
|
|
case .following:
|
|
MainHomeFollowingView(
|
|
onTapLive: onTapLive,
|
|
onTapCreator: onTapCreator,
|
|
onTapContent: onTapContent,
|
|
onTapLogin: onTapFollowingLogin,
|
|
onTapFollowingAll: onTapFollowingAll,
|
|
onTapChatTab: onTapChatTab,
|
|
onTapChatRoom: onTapChatRoom,
|
|
onTapSchedule: onTapFollowingSchedule
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
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 },
|
|
onTapBanner: { _ in },
|
|
onTapFollowAll: { action in action() },
|
|
onSelectFollowingTab: { true },
|
|
onTapFollowingLogin: {},
|
|
onTapFollowingAll: {},
|
|
onTapChatTab: {},
|
|
onTapChatRoom: { _ in },
|
|
onTapFollowingSchedule: { _, _ in }
|
|
)
|
|
}
|
|
}
|