ContentView.swift 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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. selectedTab = .home
  18. }
  19. .tabItem {
  20. Label(Tab.history.title, systemImage: Tab.history.icon)
  21. }
  22. .tag(Tab.history)
  23. SettingsView()
  24. .tabItem {
  25. Label(Tab.settings.title, systemImage: Tab.settings.icon)
  26. }
  27. .tag(Tab.settings)
  28. ProfileView()
  29. .tabItem {
  30. Label(Tab.profile.title, systemImage: Tab.profile.icon)
  31. }
  32. .tag(Tab.profile)
  33. }
  34. .tint(.celestiaCyan)
  35. }
  36. }
  37. // MARK: - Tab Definition
  38. extension ContentView {
  39. /// Defines the available tabs in the app's root navigation.
  40. enum Tab: Hashable {
  41. case home
  42. case history
  43. case settings
  44. case profile
  45. var title: String {
  46. switch self {
  47. case .home: "首页"
  48. case .history: "历史记录"
  49. case .settings: "设置"
  50. case .profile: "个人中心"
  51. }
  52. }
  53. var icon: String {
  54. switch self {
  55. case .home: "house.fill"
  56. case .history: "clock.arrow.circlepath"
  57. case .settings: "gearshape.fill"
  58. case .profile: "person.crop.circle.fill"
  59. }
  60. }
  61. }
  62. }
  63. // MARK: - Preview
  64. #Preview {
  65. ContentView()
  66. .modelContainer(for: CelestiaSession.self, inMemory: true)
  67. }