同步已迁移的 iOS 模块
This commit is contained in:
@ -12,6 +12,7 @@ import SwiftUI
|
||||
enum AppRoute: Hashable {
|
||||
case placeholder(title: String)
|
||||
case home(HomeRoute)
|
||||
case profile(ProfileRoute)
|
||||
|
||||
/// 返回该路由通过 NavigationStack push 后是否隐藏底部 TabBar。
|
||||
var hidesTabBarWhenPushed: Bool {
|
||||
@ -26,6 +27,8 @@ enum AppRoute: Hashable {
|
||||
PlaceholderDetailView(title: title)
|
||||
case .home(let route):
|
||||
route.destinationView
|
||||
case .profile(let route):
|
||||
route.destinationView
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -52,6 +55,7 @@ final class RouterPath {
|
||||
/// 主导航状态中心,管理当前 Tab 和每个 Tab 独立的 NavigationStack 路径。
|
||||
final class AppRouter {
|
||||
var selectedTab: AppTab = .home
|
||||
var selectedOrdersEntry: OrdersEntry = .storeOrders
|
||||
private var routers: [AppTab: RouterPath] = [:]
|
||||
|
||||
/// 获取指定 Tab 对应的路由路径容器,不存在时自动创建。
|
||||
@ -80,9 +84,16 @@ final class AppRouter {
|
||||
selectedTab = tab
|
||||
}
|
||||
|
||||
/// 切换到订单 Tab,并指定订单内部子入口。
|
||||
func selectOrders(entry: OrdersEntry) {
|
||||
selectedOrdersEntry = entry
|
||||
selectedTab = .orders
|
||||
}
|
||||
|
||||
/// 重置主 Tab 选择和所有 Tab 的导航历史。
|
||||
func reset() {
|
||||
selectedTab = .home
|
||||
selectedOrdersEntry = .storeOrders
|
||||
routers.values.forEach { $0.reset() }
|
||||
}
|
||||
}
|
||||
|
||||
@ -19,6 +19,8 @@ struct RootView: View {
|
||||
@State private var authAPI: AuthAPI
|
||||
@State private var profileAPI: ProfileAPI
|
||||
@State private var accountContextAPI: AccountContextAPI
|
||||
@State private var ordersAPI: OrdersAPI
|
||||
@State private var statisticsAPI: StatisticsAPI
|
||||
@State private var authSessionCoordinator: AuthSessionCoordinator
|
||||
@State private var sessionBootstrapper: SessionBootstrapper
|
||||
|
||||
@ -31,6 +33,8 @@ struct RootView: View {
|
||||
_authAPI = State(initialValue: AuthAPI(client: apiClient))
|
||||
_profileAPI = State(initialValue: ProfileAPI(client: apiClient))
|
||||
_accountContextAPI = State(initialValue: AccountContextAPI(client: apiClient))
|
||||
_ordersAPI = State(initialValue: OrdersAPI(client: apiClient))
|
||||
_statisticsAPI = State(initialValue: StatisticsAPI(client: apiClient))
|
||||
_authSessionCoordinator = State(
|
||||
initialValue: AuthSessionCoordinator(
|
||||
tokenStore: tokenStore,
|
||||
@ -59,6 +63,8 @@ struct RootView: View {
|
||||
.environment(authAPI)
|
||||
.environment(profileAPI)
|
||||
.environment(accountContextAPI)
|
||||
.environment(ordersAPI)
|
||||
.environment(statisticsAPI)
|
||||
.environment(authSessionCoordinator)
|
||||
.task {
|
||||
apiClient.bindAuthTokenProvider { appSession.token }
|
||||
|
||||
Reference in New Issue
Block a user