
- 新增MainView Tab切换问题分析文档,详细描述问题原因及解决方案。 - 优化BottomTabView的绑定逻辑,简化状态管理,确保Tab切换时状态正确更新。 - 在MeView中实现用户信息加载逻辑调整,确保动态列表仅在首次进入时加载,并添加错误处理视图。 - 创建EmptyStateView组件,提供统一的空状态展示和重试功能。 - 增强调试信息输出,便于后续问题排查和用户体验提升。
56 lines
1.7 KiB
Swift
56 lines
1.7 KiB
Swift
import SwiftUI
|
||
import ComposableArchitecture
|
||
|
||
struct AppRootView: View {
|
||
@State private var isLoggedIn = false
|
||
@State private var mainStore: StoreOf<MainFeature>?
|
||
|
||
var body: some View {
|
||
Group {
|
||
if isLoggedIn {
|
||
if let mainStore = mainStore {
|
||
MainView(store: mainStore)
|
||
.onAppear {
|
||
debugInfoSync("🔄 AppRootView: 使用已存在的MainStore")
|
||
}
|
||
} else {
|
||
// 简化逻辑:直接创建MainStore,避免重复创建
|
||
let store = createMainStore()
|
||
let _ = debugInfoSync("🆕 AppRootView: 创建MainStore")
|
||
let _ = { mainStore = store }()
|
||
|
||
MainView(store: store)
|
||
.onAppear {
|
||
debugInfoSync("💾 AppRootView: MainStore已保存")
|
||
}
|
||
}
|
||
} else {
|
||
LoginView(
|
||
store: Store(
|
||
initialState: LoginFeature.State()
|
||
) {
|
||
LoginFeature()
|
||
},
|
||
onLoginSuccess: {
|
||
debugInfoSync("🔐 AppRootView: 登录成功,准备创建MainStore")
|
||
isLoggedIn = true
|
||
}
|
||
)
|
||
}
|
||
}
|
||
}
|
||
|
||
private func createMainStore() -> StoreOf<MainFeature> {
|
||
debugInfoSync("🏗️ AppRootView: 创建新的MainStore实例")
|
||
return Store(
|
||
initialState: MainFeature.State()
|
||
) {
|
||
MainFeature()
|
||
}
|
||
}
|
||
}
|
||
//
|
||
//#Preview {
|
||
// AppRootView()
|
||
//}
|