Files
e-party-iOS/yana/Views/MainView.swift
edwinQQQ c072a7e73d feat: 移除设置功能并优化主功能状态管理
- 从HomeFeature和MainFeature中移除设置相关状态和逻辑,简化状态管理。
- 更新视图以去除设置页面的展示,提升用户体验。
- 删除SettingFeature及其相关视图,减少冗余代码,增强代码可维护性。
2025-07-24 15:04:39 +08:00

98 lines
3.6 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
import ComposableArchitecture
struct MainView: View {
let store: StoreOf<MainFeature>
var onLogout: (() -> Void)? = nil
var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
InternalMainView(store: store)
.onChange(of: viewStore.isLoggedOut) { isLoggedOut in
if isLoggedOut {
onLogout?()
}
}
}
}
}
// MainView InternalMainView
struct InternalMainView: View {
let store: StoreOf<MainFeature>
var body: some View {
WithViewStore(self.store, observe: { $0 }) { viewStore in
NavigationStack(path: viewStore.binding(get: \.navigationPath, send: MainFeature.Action.navigationPathChanged)) {
GeometryReader { geometry in
ZStack {
//
Image("bg")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.clipped()
.ignoresSafeArea(.all)
//
ZStack {
FeedListView(store: store.scope(
state: \.feedList,
action: \.feedList
))
.isHidden(viewStore.selectedTab != .feed)
MeView(
store: store.scope(
state: \.me,
action: \.me
)
)
.isHidden(viewStore.selectedTab != .other)
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
//
VStack {
Spacer()
BottomTabView(selectedTab: viewStore.binding(
get: { Tab(rawValue: $0.selectedTab.rawValue) ?? .feed },
send: { MainFeature.Action.selectTab(MainFeature.Tab(rawValue: $0.rawValue) ?? .feed) }
))
}
.padding(.bottom, geometry.safeAreaInsets.bottom + 60)
}
}
.navigationDestination(for: MainFeature.Destination.self) { destination in
switch destination {
case .test:
TestPushView()
case .appSetting:
IfLetStore(
self.store.scope(
state: \.appSettingState,
action: MainFeature.Action.appSettingAction
),
then: { appSettingStore in
WithPerceptionTracking {
AppSettingView(store: appSettingStore)
}
}
)
}
}
}
.onAppear {
viewStore.send(.onAppear)
}
}
}
}
struct TestPushView: View {
var body: some View {
ZStack {
Color.blue.ignoresSafeArea()
Text("Test Push View")
.font(.largeTitle)
.foregroundColor(.white)
}
}
}