// // ChatListView.swift // Chat // // Created by Sergey Tarasov on 24.07.2022. // import SwiftUI struct ChatListView: View { @Environment(\.colorScheme) var colorScheme @ObservedObject var viewModel: ChatListViewModel var body: some View { Group { if viewModel.jids.isEmpty { ProgressView() } else { List { ForEach(viewModel.jids.indices, id: \.self) { index in ZStack { HStack { Image(systemName: "person.crop.circle") .resizable() .scaledToFit() .foregroundColor(.secondary.opacity(0.5)) .padding(.vertical, 8) VStack(alignment: .leading, spacing: 0) { HStack { Text(viewModel.jids[index].user ?? "") Spacer() Text("23:04") .font(.callout) .foregroundColor(.secondary) } .padding(.vertical, 4) HStack { VStack { Text("Сообщение \(index)") .foregroundColor(.secondary) Spacer() } Spacer() Text("\(index)") .font(.callout) .foregroundColor(colorScheme == .light ? .white : .black) .padding(.horizontal, 6) .background( Capsule().foregroundColor(.secondary) ) } .padding(.vertical, 6) } } .foregroundColor(.primary) .frame(height: 60) NavigationLink { ChatView() .navigationTitle(viewModel.jids[index].user ?? "") } label: { EmptyView() } .opacity(0.0) } } } .listStyle(.plain) } } .navigationTitle("Чаты") .navigationBarTitleDisplayMode(.inline) } } struct ChatListView_Previews: PreviewProvider { static var viewModel: ChatListViewModel = ChatListViewModel() static var previews: some View { Group { NavigationView { ChatListView(viewModel: viewModel) } NavigationView { ChatListView(viewModel: viewModel) } .preferredColorScheme(.dark) } } }