12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- //
- // 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(Tab.contacts.string, systemImage: "person.crop.circle")
- }
- .tag(Tab.contacts)
- RoomsListView(viewModel: roomsViewModel)
- .navigationViewStyle(StackNavigationViewStyle())
- .tabItem {
- Label(Tab.rooms.string, systemImage: "bubble.left.and.bubble.right")
- }
- .tag(Tab.rooms)
- Text("")
- .navigationBarTitleDisplayMode(.inline)
- .navigationViewStyle(StackNavigationViewStyle())
- .tabItem {
- Label(Tab.settings.string, systemImage: "gear")
- }
- .tag(Tab.settings)
- }
- .navigationBarTitle(returnNaviBarTitle(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
- var string: String {
- switch self {
- case .contacts: return "Контакты"
- case .rooms: return "Чаты"
- case .settings: return "Настройки"
- }
- }
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
|