1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071 |
- //
- // 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()
- }
- }
|