1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- //
- // RoomsListCellView.swift
- // Chat (iOS)
- //
- // Created by Sergey Tarasov on 14.10.2022.
- //
- import SwiftUI
- struct RoomsListCellView: View {
- @Environment(\.colorScheme) var colorScheme
- let roomID: String
- let title: String
- let lastMessage: String
- let lastMessageTime: String
- let unreadMessagesCount: Int
- var body: some View {
- ZStack {
- HStack {
- Image(systemName: "person.crop.circle")
- .font(.system(size: 42))
- .foregroundColor(.secondary.opacity(0.5))
- VStack(alignment: .leading, spacing: 12) {
- HStack(alignment: .firstTextBaseline) {
- Text(title)
- Spacer()
- Text(lastMessageTime)
- .font(.callout)
- .foregroundColor(.secondary)
- }
- HStack(alignment: .firstTextBaseline) {
- Text(lastMessage)
- .foregroundColor(.secondary)
- Spacer()
- Text("\(unreadMessagesCount)")
- .font(.callout)
- .foregroundColor(colorScheme == .light ? .white : .black)
- .padding(.horizontal, 6)
- .background(
- Capsule().foregroundColor(.secondary)
- )
- .monospacedDigit()
- }
- }
- }
- .foregroundColor(.primary)
- .lineLimit(1)
- NavigationLink {
- ChatView(store: ChatStore(with: roomID))
- } label: {
- EmptyView()
- }
- .opacity(0.0)
- }
- }
- }
- struct RoomsListCellView_Previews: PreviewProvider {
- static var previews: some View {
- List {
- RoomsListCellView(
- roomID: "room@domain.com",
- title: "Room looooooooooooooong title",
- lastMessage: "Last message",
- lastMessageTime: "15:37",
- unreadMessagesCount: 3
- )
- RoomsListCellView(
- roomID: "room@domain.com",
- title: "Room title",
- lastMessage: "Last loooooooooooooooong message",
- lastMessageTime: "15:37",
- unreadMessagesCount: 3
- )
- }
- .listStyle(.plain)
- }
- }
|