π΄ Let's Build Twitter with SwiftUI (iOS 15, Xcode 13, Firebase, SwiftUI 3.0)
import SwiftUI
struct FeedView: View {
var body: some View {
ScrollView {
LazyVStack {
ForEach(0...20, id: \.self) { _ in
TweetRowView()
.padding()
}
}
}
}
}
import SwiftUI
struct TweetRowView: View {
var body: some View {
VStack(alignment: .leading) {
// profile image + user info + tweet
HStack(alignment: .top, spacing: 12) {
profileImageView
VStack(alignment: .leading, spacing: 4) {
// user info
userInfoView
// tweet caption
captionView
}
}
// action button
HStack {
messageButton
Spacer()
arrowButton
Spacer()
heartButton
Spacer()
bookmarkButton
}
.padding()
.foregroundColor(.gray)
Divider()
}
}
}
extension TweetRowView {
private var profileImageView: some View {
Circle()
.frame(width: 56, height: 56)
.foregroundColor(Color(.systemBlue))
}
private var userInfoView: some View {
HStack {
Text("Rober Dawny Junior")
.font(.subheadline)
.bold()
Text("@Ironman")
.foregroundColor(.gray)
.font(.caption)
Text("2w")
.foregroundColor(.gray)
.font(.caption)
}
}
private var captionView: some View {
Text("I'm Ironman")
.font(.subheadline)
.multilineTextAlignment(.leading)
}
private var messageButton: some View {
Button {
// action for button
} label: {
Image(systemName: "bubble.left")
.font(.subheadline)
}
}
private var arrowButton: some View {
Button {
// action for button
} label: {
Image(systemName: "arrow.2.squarepath")
.font(.subheadline)
}
}
private var heartButton: some View {
Button {
// action for button
} label: {
Image(systemName: "heart")
.font(.subheadline)
}
}
private var bookmarkButton: some View {
Button {
// action for button
} label: {
Image(systemName: "bookmark")
.font(.subheadline)
}
}
}
SwiftUI λ³΅μ΅ κ²Έ decentν UI ꡬν λ°©λ²μ λ€μ!