ContentView.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // ContentView.swift
  3. // Shared
  4. //
  5. // Created by Sergey Tarasov on 24.07.2022.
  6. //
  7. import SwiftUI
  8. struct ContentView: View {
  9. @ObservedObject var loginStore: LoginStore = LoginStore()
  10. @State var authStatus: Bool = false
  11. @State var selectedTab: Tab = .rooms
  12. var body: some View {
  13. Group {
  14. if authStatus {
  15. NavigationView {
  16. TabView(selection: $selectedTab) {
  17. ChatListView()
  18. .navigationViewStyle(StackNavigationViewStyle())
  19. .tabItem {
  20. Label(Tab.contacts.string, systemImage: "person.crop.circle")
  21. }
  22. .tag(Tab.contacts)
  23. RoomsListView()
  24. .navigationViewStyle(StackNavigationViewStyle())
  25. .tabItem {
  26. Label(Tab.rooms.string, systemImage: "bubble.left.and.bubble.right")
  27. }
  28. .tag(Tab.rooms)
  29. Text("")
  30. .navigationBarTitleDisplayMode(.inline)
  31. .navigationViewStyle(StackNavigationViewStyle())
  32. .tabItem {
  33. Label(Tab.settings.string, systemImage: "gear")
  34. }
  35. .tag(Tab.settings)
  36. }
  37. .navigationBarTitle(returnNaviBarTitle(self.selectedTab))
  38. }
  39. } else {
  40. LoginView(store: loginStore, authStatus: $authStatus)
  41. }
  42. }
  43. }
  44. func returnNaviBarTitle(_ tabSelection: Tab) -> String {
  45. switch tabSelection {
  46. case .contacts: return "Контакты"
  47. case .rooms: return "Чаты"
  48. case .settings: return "Настройки"
  49. }
  50. }
  51. enum Tab {
  52. case contacts
  53. case rooms
  54. case settings
  55. var string: String {
  56. switch self {
  57. case .contacts: return "Контакты"
  58. case .rooms: return "Чаты"
  59. case .settings: return "Настройки"
  60. }
  61. }
  62. }
  63. }
  64. struct ContentView_Previews: PreviewProvider {
  65. static var previews: some View {
  66. ContentView()
  67. }
  68. }