Skip to content

Instantly share code, notes, and snippets.

@karenxpn
Created March 24, 2021 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save karenxpn/1faf82461ca70c9887e6c3251d1f81b8 to your computer and use it in GitHub Desktop.
Save karenxpn/1faf82461ca70c9887e6c3251d1f81b8 to your computer and use it in GitHub Desktop.
View to present our chat List
import SwiftUI
struct ContentView: View {
@ObservedObject var viewModel = ViewModel()
var body: some View {
ScrollView {
LazyVStack {
ForEach(viewModel.chats, id: \.id) { chat in
HStack {
// you can show image here by importing SDWebImageSwiftUI
VStack(alignment: .leading) {
Text(chat.chatName)
.foregroundColor(.white)
.font(.custom("Avenir", size: 16))
.fontWeight(.heavy)
if chat.message != nil {
HStack {
Text(chat.message!.content)
.foregroundColor(.white)
.font(.custom("Avenir", size: 14))
.lineLimit(1)
Text(chat.message!.created_at)
.foregroundColor(.white)
.font(.custom("Avenir", size: 14))
}
}
}.padding(.horizontal)
Spacer()
if !chat.read {
Circle()
.fill(Color(UIColor(red: 0/255, green: 148/255, blue: 255/255, alpha: 1)))
.frame(width: 14, height: 14)
}
}.padding(.vertical, 8)
.padding(.horizontal)
.background(!chat.read ? Color(UIColor(red: 83/255, green: 90/255, blue: 97/255, alpha: 1)) : Color.clear)
}
}
}
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment