39 lines
1.1 KiB
Swift
39 lines
1.1 KiB
Swift
//
|
||
// MainTabsView.swift
|
||
// suixinkan
|
||
//
|
||
// Created by Codex on 2026/6/18.
|
||
//
|
||
|
||
import SwiftUI
|
||
|
||
/// 主 Tab 容器视图,为每个 Tab 创建独立的 NavigationStack。
|
||
struct MainTabsView: View {
|
||
@Environment(AppRouter.self) private var appRouter
|
||
|
||
var body: some View {
|
||
@Bindable var appRouter = appRouter
|
||
|
||
TabView(selection: $appRouter.selectedTab) {
|
||
ForEach(AppTab.allCases) { tab in
|
||
NavigationStack(path: appRouter.binding(for: tab)) {
|
||
tab.rootView
|
||
.navigationTitle(tab.title)
|
||
.navigationDestination(for: AppRoute.self) { route in
|
||
route.destinationView
|
||
.toolbar(route.hidesTabBarWhenPushed ? .hidden : .visible, for: .tabBar)
|
||
}
|
||
}
|
||
.environment(appRouter.router(for: tab))
|
||
.tabItem { tab.label }
|
||
.tag(tab)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
|
||
#Preview {
|
||
MainTabsView()
|
||
.environment(AppRouter())
|
||
}
|