ChatListView.swift 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. //
  2. // ChatListView.swift
  3. // Chat
  4. //
  5. // Created by Sergey Tarasov on 24.07.2022.
  6. //
  7. import SwiftUI
  8. struct ChatListView: View {
  9. @Environment(\.colorScheme) var colorScheme
  10. @ObservedObject var viewModel: ChatListViewModel
  11. var body: some View {
  12. Group {
  13. if viewModel.jids.isEmpty {
  14. ProgressView()
  15. } else {
  16. List {
  17. ForEach(viewModel.jids.indices, id: \.self) { index in
  18. ZStack {
  19. HStack {
  20. Image(systemName: "person.crop.circle")
  21. .resizable()
  22. .scaledToFit()
  23. .foregroundColor(.secondary.opacity(0.5))
  24. .padding(.vertical, 8)
  25. VStack(alignment: .leading, spacing: 0) {
  26. HStack {
  27. Text(viewModel.jids[index].user ?? "")
  28. Spacer()
  29. Text("23:04")
  30. .font(.callout)
  31. .foregroundColor(.secondary)
  32. }
  33. .padding(.vertical, 4)
  34. HStack {
  35. VStack {
  36. Text("Сообщение \(index)")
  37. .foregroundColor(.secondary)
  38. Spacer()
  39. }
  40. Spacer()
  41. Text("\(index)")
  42. .font(.callout)
  43. .foregroundColor(colorScheme == .light ? .white : .black)
  44. .padding(.horizontal, 6)
  45. .background(
  46. Capsule().foregroundColor(.secondary)
  47. )
  48. }
  49. .padding(.vertical, 6)
  50. }
  51. }
  52. .foregroundColor(.primary)
  53. .frame(height: 60)
  54. NavigationLink {
  55. ChatView()
  56. .navigationTitle(viewModel.jids[index].user ?? "")
  57. } label: {
  58. EmptyView()
  59. }
  60. .opacity(0.0)
  61. }
  62. }
  63. }
  64. .listStyle(.plain)
  65. }
  66. }
  67. .navigationTitle("Чаты")
  68. .navigationBarTitleDisplayMode(.inline)
  69. }
  70. }
  71. struct ChatListView_Previews: PreviewProvider {
  72. static var viewModel: ChatListViewModel = ChatListViewModel()
  73. static var previews: some View {
  74. Group {
  75. NavigationView {
  76. ChatListView(viewModel: viewModel)
  77. }
  78. NavigationView {
  79. ChatListView(viewModel: viewModel)
  80. }
  81. .preferredColorScheme(.dark)
  82. }
  83. }
  84. }