
- 在CommonComponents中为BottomTabBar添加了便捷初始化和最简初始化方法,简化了外部使用。 - 新增内部默认items方法,确保底部导航栏的图标资源一致性。 - 在MainPage中更新BottomTabBar的使用方式,直接传入viewModel,提升代码可读性和维护性。
59 lines
2.0 KiB
Swift
59 lines
2.0 KiB
Swift
import SwiftUI
|
||
|
||
// MARK: - Main View
|
||
|
||
struct MainPage: View {
|
||
@StateObject private var viewModel = MainViewModel()
|
||
let onLogout: () -> Void
|
||
@State private var isPresentingCreatePage: Bool = false
|
||
|
||
var body: some View {
|
||
NavigationStack(path: $viewModel.navigationPath) {
|
||
GeometryReader { geometry in
|
||
ZStack {
|
||
// 背景图片
|
||
LoginBackgroundView()
|
||
|
||
// 主内容:使用 TabView 常驻子树
|
||
TabView(selection: $viewModel.selectedTab) {
|
||
MomentListHomePage(onCreateTapped: { isPresentingCreatePage = true })
|
||
.tag(MainViewModel.Tab.feed)
|
||
MePage(onLogout: onLogout)
|
||
.tag(MainViewModel.Tab.me)
|
||
}
|
||
.tabViewStyle(.page(indexDisplayMode: .never))
|
||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
|
||
VStack {
|
||
Spacer()
|
||
// 底部导航栏(组件化)
|
||
BottomTabBar(viewModel: viewModel)
|
||
.frame(height: 80)
|
||
.padding(.horizontal, 24)
|
||
.padding(.bottom)
|
||
}
|
||
}.ignoresSafeArea(.all)
|
||
}
|
||
.toolbar(.hidden)
|
||
}
|
||
.onAppear {
|
||
viewModel.onLogout = onLogout
|
||
viewModel.onAddButtonTapped = {
|
||
// TODO: 处理添加按钮点击事件
|
||
debugInfoSync("➕ 添加按钮被点击")
|
||
}
|
||
viewModel.onAppear()
|
||
}
|
||
.fullScreenCover(isPresented: $isPresentingCreatePage) {
|
||
CreateFeedPage {
|
||
isPresentingCreatePage = false
|
||
}
|
||
}
|
||
.onChange(of: viewModel.isLoggedOut) { _, isLoggedOut in
|
||
if isLoggedOut {
|
||
onLogout()
|
||
}
|
||
}
|
||
}
|
||
}
|