-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy pathHomeView.swift
More file actions
122 lines (112 loc) · 4.75 KB
/
HomeView.swift
File metadata and controls
122 lines (112 loc) · 4.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//
// HomeView.swift
// berkeley-mobile
//
// Created by Justin Wong on 3/1/25.
// Copyright © 2025 ASUC OCTO. All rights reserved.
//
import SwiftUI
struct HomeView: View {
@EnvironmentObject private var homeViewModel: HomeViewModel
@State private var tabSelectedIndex = 0
@State private var navigationPath = NavigationPath()
@State private var isPresentingDetailView = false
@State private var selectedDetent: PresentationDetent = .fraction(0.45)
@State private var homeDrawerPinViewModel = HomeDrawerPinViewModel()
@State private var diningHallsViewModel = DiningHallsViewModel()
@State private var guidesViewModel = GuidesViewModel()
private var mapViewController: MapViewController
private let menuIconCacheManager = MenuItemIconCacheManager()
init(mapViewController: MapViewController) {
self.mapViewController = mapViewController
}
var body: some View {
ZStack {
HomeMapView(mapViewController: mapViewController)
.ignoresSafeArea()
VStack {
if homeViewModel.isShowingDrawer {
BMDrawerView(drawerViewState: $homeViewModel.drawerViewState, hPadding: 0, vPadding: 0) {
homeDrawerContentView
}
.transition(AnyTransition.move(edge: .bottom).combined(with: .opacity))
}
}
.animation(.default, value: homeViewModel.isShowingDrawer)
.onChange(of: homeViewModel.isShowingDrawer) { _ in
homeViewModel.drawerViewState = .medium
}
}
}
private var segmentedControlHeader: some View {
BMSegmentedControlView(
tabNames: ["Dining", "Fitness", "Study", "Guides"],
selectedTabIndex: $tabSelectedIndex
)
.padding(.top, 20)
}
private var homeDrawerContentView: some View {
NavigationStack(path: $navigationPath) {
Group {
if homeViewModel.isFetching {
ProgressView("LOADING")
.padding(.vertical, 20)
Spacer()
} else {
segmentedControlHeader
switch tabSelectedIndex {
case 0:
DiningHallsView(mapViewController: mapViewController) { selectedDiningHall in
navigationPath.append(selectedDiningHall)
}
.environment(diningHallsViewModel)
.environment(homeDrawerPinViewModel)
.onAppear {
homeViewModel.logOpenedDiningHomeSectionAnalytics()
}
case 1:
FitnessView(mapViewController: mapViewController) { selectedGym in
navigationPath.append(selectedGym)
}
.environmentObject(homeViewModel)
.environment(homeDrawerPinViewModel)
case 2:
LibrariesView(mapViewController: mapViewController) { selectedLibrary in
navigationPath.append(selectedLibrary)
}
.environment(homeDrawerPinViewModel)
default:
GuidesView()
.environment(guidesViewModel)
}
}
}
.navigationBarTitleDisplayMode(.inline)
.containerBackground(.clear, for: .navigation)
.padding(.horizontal)
.navigationDestination(for: BMDiningHall.self) { diningHall in
DiningDetailView(diningHall: diningHall)
.containerBackground(.clear, for: .navigation)
.environment(diningHallsViewModel)
.environment(\.menuIconCache, menuIconCacheManager)
}
.navigationDestination(for: BMGym.self) { gym in
GymDetailView(gym: gym)
.containerBackground(.clear, for: .navigation)
}
.navigationDestination(for: BMLibrary.self) { library in
LibraryDetailView(library: library)
.containerBackground(.clear, for: .navigation)
}
.navigationDestination(for: BMMenuItem.self) { menuItem in
DiningMenuItemDetailView(menuItem: menuItem)
.containerBackground(.clear, for: .navigation)
.environment(\.menuIconCache, menuIconCacheManager)
}
}
}
}
#Preview {
HomeView(mapViewController: MapViewController())
.environmentObject(HomeViewModel())
}