RoomsListCellView.swift 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // RoomsListCellView.swift
  3. // Chat (iOS)
  4. //
  5. // Created by Sergey Tarasov on 14.10.2022.
  6. //
  7. import SwiftUI
  8. struct RoomsListCellView: View {
  9. @Environment(\.colorScheme) var colorScheme
  10. let roomID: String
  11. let title: String
  12. let lastMessage: String
  13. let lastMessageTime: String
  14. let unreadMessagesCount: Int
  15. var body: some View {
  16. ZStack {
  17. HStack {
  18. Image(systemName: "person.crop.circle")
  19. .font(.system(size: 42))
  20. .foregroundColor(.secondary.opacity(0.5))
  21. VStack(alignment: .leading, spacing: 12) {
  22. HStack(alignment: .firstTextBaseline) {
  23. Text(title)
  24. Spacer()
  25. Text(lastMessageTime)
  26. .font(.callout)
  27. .foregroundColor(.secondary)
  28. }
  29. HStack(alignment: .firstTextBaseline) {
  30. Text(lastMessage)
  31. .foregroundColor(.secondary)
  32. Spacer()
  33. Text("\(unreadMessagesCount)")
  34. .font(.callout)
  35. .foregroundColor(colorScheme == .light ? .white : .black)
  36. .padding(.horizontal, 6)
  37. .background(
  38. Capsule().foregroundColor(.secondary)
  39. )
  40. .monospacedDigit()
  41. }
  42. }
  43. }
  44. .foregroundColor(.primary)
  45. .lineLimit(1)
  46. NavigationLink {
  47. ChatView(store: ChatStore(with: roomID))
  48. } label: {
  49. EmptyView()
  50. }
  51. .opacity(0.0)
  52. }
  53. }
  54. }
  55. struct RoomsListCellView_Previews: PreviewProvider {
  56. static var previews: some View {
  57. List {
  58. RoomsListCellView(
  59. roomID: "room@domain.com",
  60. title: "Room looooooooooooooong title",
  61. lastMessage: "Last message",
  62. lastMessageTime: "15:37",
  63. unreadMessagesCount: 3
  64. )
  65. RoomsListCellView(
  66. roomID: "room@domain.com",
  67. title: "Room title",
  68. lastMessage: "Last loooooooooooooooong message",
  69. lastMessageTime: "15:37",
  70. unreadMessagesCount: 3
  71. )
  72. }
  73. .listStyle(.plain)
  74. }
  75. }