
- 在yanaApp中为SplashPage添加忽略安全区域的设置,确保全屏显示。 - 在DynamicsModels中更新MyMomentInfo结构,添加可选字段以兼容不同版本的服务器返回数据。 - 在CommonComponents中将LoginBackgroundView的背景图替换为蓝色,简化视图。 - 在MainPage中为内容添加忽略安全区域的设置,提升布局一致性。 - 在MePage中新增MePageViewModel,优化用户信息管理逻辑,支持动态列表的加载和错误处理。 - 在SplashPage中调整过渡动画时长,提升用户体验。
73 lines
2.9 KiB
Swift
73 lines
2.9 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(
|
||
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)
|
||
}
|
||
}.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()
|
||
}
|
||
}
|
||
}
|
||
}
|