Files
e-party-iOS/yana/MVVM/MainPage.swift
edwinQQQ 90a840c5f3 feat: 更新日志级别管理及底部导航栏组件化
- 在ContentView中根据编译模式初始化日志级别,确保调试信息的灵活性。
- 在APILogger中使用actor封装日志级别,增强并发安全性。
- 新增通用底部Tab栏组件,优化MainPage中的底部导航逻辑,提升代码可维护性。
- 移除冗余的AppRootView和MainView,简化视图结构,提升代码整洁性。
2025-09-18 16:12:18 +08:00

150 lines
4.8 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import SwiftUI
// MARK: - Main View
struct MainPage: View {
@StateObject private var viewModel = MainViewModel()
let onLogout: () -> Void
var body: some View {
NavigationStack(path: $viewModel.navigationPath) {
GeometryReader { geometry in
ZStack {
//
LoginBackgroundView()
//
mainContentView(geometry: geometry)
.frame(maxWidth: .infinity, maxHeight: .infinity)
VStack {
HStack {
Spacer()
//
topRightButton
}
Spacer()
//
BottomTabBar(
items: [
TabBarItem(id: MainViewModel.Tab.feed.rawValue, title: MainViewModel.Tab.feed.title, systemIconName: MainViewModel.Tab.feed.iconName),
TabBarItem(id: MainViewModel.Tab.me.rawValue, title: MainViewModel.Tab.me.title, systemIconName: MainViewModel.Tab.me.iconName)
],
selectedId: Binding(
get: { viewModel.selectedTab.rawValue },
set: { raw in
if let tab = MainViewModel.Tab(rawValue: raw) {
viewModel.onTabChanged(tab)
}
}
),
onSelect: { _ in }
)
.frame(height: 80)
.padding(.horizontal, 24)
.padding(.bottom, 100)
}
}
}
.navigationDestination(for: String.self) { _ in EmptyView() }
.navigationDestination(for: AppRoute.self) { route in
switch route {
case .setting:
SettingPage(
onBack: {
viewModel.navigationPath.removeLast()
},
onLogout: {
viewModel.onLogoutTapped()
}
)
.navigationBarHidden(true)
case .publish:
CreateFeedPage(
onDismiss: {
viewModel.navigationPath.removeLast()
}
)
default:
EmptyView()
}
}
}
.onAppear {
viewModel.onLogout = onLogout
viewModel.onAddButtonTapped = {
// TODO:
debugInfoSync(" 添加按钮被点击")
}
viewModel.onAppear()
}
.onChange(of: viewModel.isLoggedOut) { _, isLoggedOut in
if isLoggedOut {
onLogout()
}
}
}
// MARK: - UI Components
private func mainContentView(geometry: GeometryProxy) -> some View {
Group {
switch viewModel.selectedTab {
case .feed:
MomentListHomePage()
case .me:
TempMePage()
}
}
}
//
// MARK: -
private var topRightButton: some View {
Button(action: {
viewModel.onTopRightButtonTapped()
}) {
Group {
switch viewModel.selectedTab {
case .feed:
Image("add icon")
.resizable()
.aspectRatio(contentMode: .fit)
.frame(width: 40, height: 40)
case .me:
Image(systemName: "gearshape")
.font(.system(size: 24, weight: .medium))
.foregroundColor(.white)
.frame(width: 40, height: 40)
.background(Color.black.opacity(0.3))
.clipShape(Circle())
}
}
}
.padding(.trailing, 16)
.padding(.top, 8)
}
}
// MARK: - MeView ()
struct TempMePage: View {
var body: some View {
VStack {
Text("Me View")
.font(.title)
.foregroundColor(.white)
Text("This is a simplified MeView")
.font(.body)
.foregroundColor(.white.opacity(0.8))
}
}
}
//#Preview {
// MainPage(onLogout: {})
//}