ContentView.swift 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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. @State var selectedTab: Tab = .rooms
  10. var body: some View {
  11. NavigationView {
  12. TabView(selection: $selectedTab) {
  13. ChatListView()
  14. .navigationViewStyle(StackNavigationViewStyle())
  15. .tabItem {
  16. Label(Tab.contacts.string, systemImage: "person.crop.circle")
  17. }
  18. .tag(Tab.contacts)
  19. RoomsListView()
  20. .navigationViewStyle(StackNavigationViewStyle())
  21. .tabItem {
  22. Label(Tab.rooms.string, systemImage: "bubble.left.and.bubble.right")
  23. }
  24. .tag(Tab.rooms)
  25. Text("")
  26. .navigationBarTitleDisplayMode(.inline)
  27. .navigationViewStyle(StackNavigationViewStyle())
  28. .tabItem {
  29. Label(Tab.settings.string, systemImage: "gear")
  30. }
  31. .tag(Tab.settings)
  32. }
  33. .navigationBarTitle(returnNaviBarTitle(self.selectedTab))
  34. }
  35. }
  36. func returnNaviBarTitle(_ tabSelection: Tab) -> String {
  37. switch tabSelection {
  38. case .contacts: return "Контакты"
  39. case .rooms: return "Чаты"
  40. case .settings: return "Настройки"
  41. }
  42. }
  43. enum Tab {
  44. case contacts
  45. case rooms
  46. case settings
  47. var string: String {
  48. switch self {
  49. case .contacts: return "Контакты"
  50. case .rooms: return "Чаты"
  51. case .settings: return "Настройки"
  52. }
  53. }
  54. }
  55. }
  56. struct ContentView_Previews: PreviewProvider {
  57. static var previews: some View {
  58. ContentView()
  59. }
  60. }