123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- //
- // 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)
- }
- }
- }
|