74 lines
2.7 KiB
Swift
74 lines
2.7 KiB
Swift
import SwiftUI
|
|
import FeatureAuth
|
|
import FeatureCheckin
|
|
import FeatureHome
|
|
import FeaturePlan
|
|
import FeatureProfile
|
|
|
|
public struct AppRootView: View {
|
|
@State private var homeViewModel: HomeViewModel
|
|
@State private var checkinViewModel: CheckinViewModel
|
|
@State private var planViewModel: PlanViewModel
|
|
@State private var profileViewModel: ProfileViewModel
|
|
@State private var authViewModel: AuthViewModel
|
|
@State private var selectedTab: AppTab = .home
|
|
@State private var isAuthPresented = false
|
|
|
|
public init() {
|
|
_homeViewModel = State(initialValue: AppContainer.makeHomeViewModel())
|
|
_checkinViewModel = State(initialValue: AppContainer.makeCheckinViewModel())
|
|
_planViewModel = State(initialValue: AppContainer.makePlanViewModel())
|
|
_profileViewModel = State(initialValue: AppContainer.makeProfileViewModel())
|
|
_authViewModel = State(initialValue: AppContainer.makeAuthViewModel())
|
|
}
|
|
|
|
public var body: some View {
|
|
TabView(selection: $selectedTab) {
|
|
NavigationStack {
|
|
HomeScreen(
|
|
viewModel: homeViewModel,
|
|
onNavigateToCheckin: { selectedTab = .checkin },
|
|
onNavigateToPlan: { selectedTab = .plan },
|
|
onNavigateToAuth: { isAuthPresented = true }
|
|
)
|
|
}
|
|
.tabItem { Label("首页", systemImage: "house.fill") }
|
|
.tag(AppTab.home)
|
|
|
|
NavigationStack {
|
|
CheckinScreen(viewModel: checkinViewModel, onNavigateToAuth: { isAuthPresented = true })
|
|
}
|
|
.tabItem { Label("打卡", systemImage: "checkmark.seal.fill") }
|
|
.tag(AppTab.checkin)
|
|
|
|
NavigationStack {
|
|
PlanScreen(
|
|
viewModel: planViewModel,
|
|
onNavigateToAuth: { isAuthPresented = true },
|
|
makePlanSubmitViewModel: { type, periodKey in
|
|
AppContainer.makePlanSubmitViewModel(type: type, periodKey: periodKey)
|
|
}
|
|
)
|
|
}
|
|
.tabItem { Label("计划", systemImage: "calendar") }
|
|
.tag(AppTab.plan)
|
|
|
|
NavigationStack {
|
|
ProfileScreen(viewModel: profileViewModel, onNavigateToAuth: { isAuthPresented = true })
|
|
}
|
|
.tabItem { Label("我的", systemImage: "person.crop.circle") }
|
|
.tag(AppTab.profile)
|
|
}
|
|
.sheet(isPresented: $isAuthPresented) {
|
|
AuthScreen(viewModel: authViewModel, onLoggedIn: { isAuthPresented = false })
|
|
}
|
|
}
|
|
}
|
|
|
|
private enum AppTab: Hashable {
|
|
case home
|
|
case checkin
|
|
case plan
|
|
case profile
|
|
}
|