ContentView.swift 2.1 KB

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