ContentView.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 contactsViewModel: ChatListViewModel = ChatListViewModel()
  10. @ObservedObject var roomsViewModel: RoomsListViewModel = RoomsListViewModel()
  11. @ObservedObject var loginViewModel: LoginViewModel = LoginViewModel()
  12. @State var authStatus: Bool = false
  13. @State var selectedTab: Tab = .rooms
  14. var body: some View {
  15. Group {
  16. if authStatus {
  17. NavigationView {
  18. TabView(selection: $selectedTab) {
  19. ChatListView(viewModel: contactsViewModel)
  20. .navigationViewStyle(StackNavigationViewStyle())
  21. .tabItem {
  22. Label(Tab.contacts.string, systemImage: "person.crop.circle")
  23. }
  24. .tag(Tab.contacts)
  25. RoomsListView(viewModel: roomsViewModel)
  26. .navigationViewStyle(StackNavigationViewStyle())
  27. .tabItem {
  28. Label(Tab.rooms.string, systemImage: "bubble.left.and.bubble.right")
  29. }
  30. .tag(Tab.rooms)
  31. Text("")
  32. .navigationBarTitleDisplayMode(.inline)
  33. .navigationViewStyle(StackNavigationViewStyle())
  34. .tabItem {
  35. Label(Tab.settings.string, systemImage: "gear")
  36. }
  37. .tag(Tab.settings)
  38. }
  39. .navigationBarTitle(returnNaviBarTitle(self.selectedTab))
  40. }
  41. } else {
  42. LoginView(viewModel: loginViewModel, authStatus: $authStatus)
  43. }
  44. }
  45. }
  46. func returnNaviBarTitle(_ tabSelection: Tab) -> String {
  47. switch tabSelection {
  48. case .contacts: return "Контакты"
  49. case .rooms: return "Чаты"
  50. case .settings: return "Настройки"
  51. }
  52. }
  53. enum Tab {
  54. case contacts
  55. case rooms
  56. case settings
  57. var string: String {
  58. switch self {
  59. case .contacts: return "Контакты"
  60. case .rooms: return "Чаты"
  61. case .settings: return "Настройки"
  62. }
  63. }
  64. }
  65. }
  66. struct ContentView_Previews: PreviewProvider {
  67. static var previews: some View {
  68. ContentView()
  69. }
  70. }