ContentView.swift 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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("Контакты", systemImage: "person.crop.circle")
  23. }
  24. .tag(Tab.contacts)
  25. RoomsListView(viewModel: roomsViewModel)
  26. .navigationViewStyle(StackNavigationViewStyle())
  27. .tabItem {
  28. Label("Чаты", systemImage: "bubble.left.and.bubble.right")
  29. }
  30. .tag(Tab.rooms)
  31. Text("")
  32. .navigationBarTitleDisplayMode(.inline)
  33. .navigationViewStyle(StackNavigationViewStyle())
  34. .tabItem {
  35. Label("Настройки", systemImage: "gear")
  36. }
  37. .tag(Tab.settings)
  38. }
  39. .navigationBarTitle(returnNaviBarTitle(tabSelection: 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. }
  58. }
  59. struct ContentView_Previews: PreviewProvider {
  60. static var previews: some View {
  61. ContentView()
  62. }
  63. }