| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import SwiftUI
- import SwiftData
- // MARK: - ContentView
- /// Root navigation container for the CelestiaTrace app.
- /// Uses a TabView with three tabs: Home, History, and Settings.
- struct ContentView: View {
- /// Currently selected tab.
- @State private var selectedTab: Tab = .home
- var body: some View {
- TabView(selection: $selectedTab) {
- HomeView()
- .tabItem {
- Label(Tab.home.title, systemImage: Tab.home.icon)
- }
- .tag(Tab.home)
- SessionListView {
- selectedTab = .home
- }
- .tabItem {
- Label(Tab.history.title, systemImage: Tab.history.icon)
- }
- .tag(Tab.history)
- SettingsView()
- .tabItem {
- Label(Tab.settings.title, systemImage: Tab.settings.icon)
- }
- .tag(Tab.settings)
- ProfileView()
- .tabItem {
- Label(Tab.profile.title, systemImage: Tab.profile.icon)
- }
- .tag(Tab.profile)
- }
- .tint(.celestiaCyan)
- }
- }
- // MARK: - Tab Definition
- extension ContentView {
- /// Defines the available tabs in the app's root navigation.
- enum Tab: Hashable {
- case home
- case history
- case settings
- case profile
- var title: String {
- switch self {
- case .home: "首页"
- case .history: "历史记录"
- case .settings: "设置"
- case .profile: "个人中心"
- }
- }
- var icon: String {
- switch self {
- case .home: "house.fill"
- case .history: "clock.arrow.circlepath"
- case .settings: "gearshape.fill"
- case .profile: "person.crop.circle.fill"
- }
- }
- }
- }
- // MARK: - Preview
- #Preview {
- ContentView()
- .modelContainer(for: CelestiaSession.self, inMemory: true)
- }
|