Created
March 24, 2021 10:45
-
-
Save karenxpn/1faf82461ca70c9887e6c3251d1f81b8 to your computer and use it in GitHub Desktop.
View to present our chat List
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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