ContentView.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import SwiftUI
  2. import SwiftData
  3. // MARK: - ContentView
  4. /// Root navigation container for the CelestiaTrace app.
  5. /// Uses a TabView with three tabs: Home, History, and Settings.
  6. struct ContentView: View {
  7. /// Currently selected tab.
  8. @State private var selectedTab: Tab = .home
  9. var body: some View {
  10. TabView(selection: $selectedTab) {
  11. HomeView()
  12. .tabItem {
  13. Label(Tab.home.title, systemImage: Tab.home.icon)
  14. }
  15. .tag(Tab.home)
  16. SessionListView()
  17. .tabItem {
  18. Label(Tab.history.title, systemImage: Tab.history.icon)
  19. }
  20. .tag(Tab.history)
  21. SettingsView()
  22. .tabItem {
  23. Label(Tab.settings.title, systemImage: Tab.settings.icon)
  24. }
  25. .tag(Tab.settings)
  26. ProfileView()
  27. .tabItem {
  28. Label(Tab.profile.title, systemImage: Tab.profile.icon)
  29. }
  30. .tag(Tab.profile)
  31. }
  32. .tint(.celestiaCyan)
  33. }
  34. }
  35. // MARK: - Tab Definition
  36. extension ContentView {
  37. /// Defines the available tabs in the app's root navigation.
  38. enum Tab: Hashable {
  39. case home
  40. case history
  41. case settings
  42. case profile
  43. var title: String {
  44. switch self {
  45. case .home: "首页"
  46. case .history: "历史记录"
  47. case .settings: "设置"
  48. case .profile: "个人中心"
  49. }
  50. }
  51. var icon: String {
  52. switch self {
  53. case .home: "house.fill"
  54. case .history: "clock.arrow.circlepath"
  55. case .settings: "gearshape.fill"
  56. case .profile: "person.crop.circle.fill"
  57. }
  58. }
  59. }
  60. }
  61. // MARK: - Preview
  62. #Preview {
  63. ContentView()
  64. .modelContainer(for: CelestiaSession.self, inMemory: true)
  65. }