another.im-ios/ConversationsClassic/View/Screens/ChatsListScreen.swift

97 lines
2.5 KiB
Swift
Raw Normal View History

2024-06-19 15:15:27 +00:00
import SwiftUI
struct ChatsListScreen: View {
@EnvironmentObject var store: AppStore
var body: some View {
ZStack {
// Background color
Color.Main.backgroundLight
.ignoresSafeArea()
// Content
VStack(spacing: 0) {
// Header
ChatsScreenHeader()
// Chats list
if !store.state.chatsState.chats.isEmpty {
List {
ForEach(store.state.chatsState.chats) { chat in
ChatsRow(chat: chat)
}
}
.listStyle(.plain)
.background(Color.Main.backgroundLight)
} else {
Spacer()
}
// Tab bar
SharedTabBar()
}
}
}
}
private struct ChatsScreenHeader: View {
var body: some View {
ZStack {
// bg
Color.Main.backgroundDark
.ignoresSafeArea()
// title
Text(L10n.Chats.title)
.font(.head2)
.foregroundColor(Color.Main.black)
HStack {
Spacer()
Image(systemName: "plus")
.foregroundColor(.Material.greenDark500)
.tappablePadding(.symmetric(12)) {
print("Add contact")
}
}
.padding(.horizontal, 16)
}
.frame(height: 44)
}
}
private struct ChatsRow: View {
@EnvironmentObject var store: AppStore
var chat: Chat
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 8) {
ZStack {
Circle()
.frame(width: 44, height: 44)
.foregroundColor(.red)
Text(chat.participant.firstLetter)
.foregroundColor(.white)
.font(.body1)
}
Text(chat.participant)
.foregroundColor(Color.Main.black)
.font(.body2)
Spacer()
}
.padding(.horizontal, 16)
.padding(.vertical, 4)
Rectangle()
.frame(maxWidth: .infinity)
.frame(height: 1)
.foregroundColor(.Main.backgroundDark)
}
.sharedListRow()
.onTapGesture {
// state.startChat(chat)
}
}
}