Files
e-party-iOS/yana/Features/MainFeature.swift
edwinQQQ bb49b00a59 feat: 新增导航功能与设置页面支持
- 在MainFeature中新增导航路径和设置页面状态管理,支持页面导航。
- 更新MainView以集成导航功能,添加测试按钮以触发导航。
- 在MeFeature中新增设置按钮点击事件,交由MainFeature处理。
- 增强MeView以支持设置按钮,提升用户体验。
2025-07-23 20:10:37 +08:00

98 lines
3.2 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 Foundation
import ComposableArchitecture
import CasePaths
struct MainFeature: Reducer {
enum Tab: Int, Equatable, CaseIterable {
case feed, other
}
struct State: Equatable {
var selectedTab: Tab = .feed
var feedList: FeedListFeature.State = .init()
var me: MeFeature.State = .init()
var accountModel: AccountModel? = nil
// State
var navigationPath: [Destination] = []
var settingState: SettingFeature.State? = nil
}
//
enum Destination: Hashable, Equatable {
case setting
case test
}
@CasePathable
enum Action: Equatable {
case onAppear
case selectTab(Tab)
case feedList(FeedListFeature.Action)
case me(MeFeature.Action)
case accountModelLoaded(AccountModel?)
//
case navigationPathChanged([Destination])
case settingButtonTapped
case settingAction(SettingFeature.Action)
case testButtonTapped
}
var body: some ReducerOf<Self> {
Scope(state: \.feedList, action: \.feedList) {
FeedListFeature()
}
Scope(state: \.me, action: \.me) {
MeFeature()
}
Reduce { state, action in
switch action {
case .onAppear:
return .run { send in
let accountModel = await UserInfoManager.getAccountModel()
await send(.accountModelLoaded(accountModel))
}
case .selectTab(let tab):
state.selectedTab = tab
state.navigationPath = []
if tab == .other, let uidStr = state.accountModel?.uid, let uid = Int(uidStr), uid > 0 {
state.me = MeFeature.State(uid: uid)
return .send(.me(.onAppear))
}
return .none
case .feedList:
return .none
case let .accountModelLoaded(accountModel):
state.accountModel = accountModel
return .none
case .me(.settingButtonTapped):
// push
state.settingState = SettingFeature.State()
state.navigationPath.append(.setting)
return .none
case .me:
return .none
case .navigationPathChanged(let newPath):
// pop settingState
if !newPath.contains(.setting) {
state.settingState = nil
}
state.navigationPath = newPath
return .none
case .settingButtonTapped:
state.settingState = SettingFeature.State()
state.navigationPath.append(.setting)
return .none
case .settingAction:
return .none
case .testButtonTapped:
state.navigationPath.append(.test)
return .none
}
}
//
.ifLet(\ .settingState, action: /Action.settingAction) {
SettingFeature()
}
}
}