// // ContentView.swift // Shared // // Created by Sergey Tarasov on 24.07.2022. // import SwiftUI struct ContentView: View { @ObservedObject var contactsViewModel: ChatListViewModel = ChatListViewModel() @ObservedObject var roomsViewModel: RoomsListViewModel = RoomsListViewModel() @ObservedObject var loginViewModel: LoginViewModel = LoginViewModel() @State var authStatus: Bool = false @State var selectedTab: Tab = .rooms var body: some View { Group { if authStatus { NavigationView { TabView(selection: $selectedTab) { ChatListView(viewModel: contactsViewModel) .navigationViewStyle(StackNavigationViewStyle()) .tabItem { Label("Контакты", systemImage: "person.crop.circle") } .tag(Tab.contacts) RoomsListView(viewModel: roomsViewModel) .navigationViewStyle(StackNavigationViewStyle()) .tabItem { Label("Чаты", systemImage: "bubble.left.and.bubble.right") } .tag(Tab.rooms) Text("") .navigationBarTitleDisplayMode(.inline) .navigationViewStyle(StackNavigationViewStyle()) .tabItem { Label("Настройки", systemImage: "gear") } .tag(Tab.settings) } .navigationBarTitle(returnNaviBarTitle(tabSelection: self.selectedTab)) } } else { LoginView(viewModel: loginViewModel, authStatus: $authStatus) } } } func returnNaviBarTitle(tabSelection: Tab) -> String { switch tabSelection { case .contacts: return "Контакты" case .rooms: return "Чаты" case .settings: return "Настройки" } } enum Tab { case contacts case rooms case settings } } struct ContentView_Previews: PreviewProvider { static var previews: some View { ContentView() } }