Components
Feed
An activity feed with avatars, mixed item types and timestamps. Built in all 5 Effect UI styles, in light and dark mode.










Source: Ledger
FeedView.swift in the free Ledger style. It needs Ledger's Theme.swift, which comes with the style: join early access on the home page and it's emailed to you.
import SwiftUI
// MARK: - Sample data
private enum FeedFilter: String, CaseIterable, Identifiable {
case all = "All", following = "Following", you = "You"
var id: String { rawValue }
}
private enum FeedKind {
case post(String)
case goal(name: String, target: Double, months: Int)
case reply(thread: String, quoted: String, body: String)
case follow(bio: String)
case template(title: String, lines: [(String, String)], uses: Int)
}
private struct FeedItem: Identifiable {
let id: Int
let name: String
let initials: String
let verb: String?
let when: String
let aboutYou: Bool
let kind: FeedKind
let likes: Int
let replies: Int
}
private let feed: [FeedItem] = [
FeedItem(id: 1, name: "Priya Nair", initials: "PN", verb: nil, when: "2h ago", aboutYou: false,
kind: .post("Moved our emergency fund to a 4.35% high-yield account. It took twenty minutes, most of it waiting on the transfer. That is about $380 a year we were leaving on the table."),
likes: 24, replies: 6),
FeedItem(id: 2, name: "Daniel Osei", initials: "DO", verb: "reached a goal", when: "4h ago", aboutYou: false,
kind: .goal(name: "Emergency fund", target: 10000, months: 14),
likes: 51, replies: 9),
FeedItem(id: 3, name: "Sam Whitaker", initials: "SW", verb: "replied to your comment", when: "6h ago", aboutYou: true,
kind: .reply(thread: "Is 50/30/20 realistic in New York?",
quoted: "I take rent out first, then apply the ratios to what is left.",
body: "Same here. Once rent is its own line, the 30 stops looking impossible."),
likes: 3, replies: 1),
FeedItem(id: 4, name: "Lena Fischer", initials: "LF", verb: "started following you", when: "1d ago", aboutYou: true,
kind: .follow(bio: "Tracks 4 budgets · 128 followers"),
likes: 0, replies: 0),
FeedItem(id: 5, name: "Marco Bianchi", initials: "MB", verb: "shared a budget template", when: "1d ago", aboutYou: false,
kind: .template(title: "Freelancer, quarterly taxes",
lines: [("Estimated tax", "28%"), ("Operating costs", "15%"), ("Pay yourself", "57%")],
uses: 2140),
likes: 88, replies: 14),
FeedItem(id: 6, name: "Ana Torres", initials: "AT", verb: nil, when: "3d ago", aboutYou: false,
kind: .post("Cancelled three subscriptions I had forgotten about. $41.97 a month back. The recurring list found all of them in one go."),
likes: 37, replies: 4),
]
// MARK: - Screen
struct FeedView: View {
@State private var filter: FeedFilter = .all
@State private var liked: Set<Int> = [2]
@State private var followedBack = false
private var visible: [FeedItem] {
switch filter {
case .all: return feed
case .following: return feed.filter { !$0.aboutYou }
case .you: return feed.filter { $0.aboutYou }
}
}
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: Theme.Space.xl) {
ScreenHeader(eyebrow: "Tilde community", title: "Activity") {
IconButton(symbol: "square.and.pencil")
}
Picker("Filter", selection: $filter) {
ForEach(FeedFilter.allCases) { Text($0.rawValue).tag($0) }
}
.pickerStyle(.segmented)
VStack(alignment: .leading, spacing: 0) {
SectionHeader(title: filter == .you ? "About you" : "Latest", detail: "\(visible.count) updates")
RuledStack {
ForEach(visible) { item in
FeedRow(
item: item,
liked: liked.contains(item.id),
followedBack: $followedBack,
onLike: { toggleLike(item.id) }
)
.transition(.opacity)
}
}
}
}
.padding(.horizontal, Theme.Space.margin)
.padding(.top, Theme.Space.sm)
.padding(.bottom, Theme.Space.xxl)
}
.scrollIndicators(.hidden)
.paperBackground()
.animation(Theme.Motion.surfaceEnter, value: filter)
.sensoryFeedback(.selection, trigger: filter)
}
private func toggleLike(_ id: Int) {
withAnimation(Theme.Motion.stateChange) {
if liked.contains(id) { liked.remove(id) } else { liked.insert(id) }
}
}
}
// MARK: - Row
private struct FeedRow: View {
let item: FeedItem
let liked: Bool
@Binding var followedBack: Bool
let onLike: () -> Void
var body: some View {
HStack(alignment: .top, spacing: Theme.Space.md) {
Avatar(initials: item.initials, size: 36)
VStack(alignment: .leading, spacing: Theme.Space.sm) {
headline
content
if hasActions { actions }
}
}
.padding(.vertical, Theme.Space.lg)
}
private var headline: some View {
HStack(alignment: .firstTextBaseline, spacing: Theme.Space.sm) {
Group {
if let verb = item.verb {
Text("\(Text(item.name).fontWeight(.semibold)) \(Text(verb).foregroundStyle(Theme.onSurfaceVariant))")
} else {
Text(item.name).fontWeight(.semibold)
}
}
.ledgerType(.bodyMd)
.foregroundStyle(Theme.onSurface)
.fixedSize(horizontal: false, vertical: true)
Spacer(minLength: 0)
Text(item.when)
.ledgerType(.bodySm)
.monospacedDigit()
.foregroundStyle(Theme.onSurfaceMuted)
.fixedSize()
}
}
@ViewBuilder
private var content: some View {
switch item.kind {
case .post(let text):
Text(text)
.ledgerType(.bodyMd)
.foregroundStyle(Theme.onSurface)
.fixedSize(horizontal: false, vertical: true)
case let .goal(name, target, months):
VStack(alignment: .leading, spacing: Theme.Space.sm) {
HStack(alignment: .firstTextBaseline) {
Image(systemName: "flag.checkered")
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(Theme.onSurface)
Text(name)
.ledgerType(.bodyMd)
.foregroundStyle(Theme.onSurface)
Spacer()
AmountText(value: target)
}
LedgerProgress(fraction: 1)
Text("\(Money.format(target, decimals: 2)) of \(Money.format(target, decimals: 2)) · in \(months) months")
.ledgerType(.bodySm)
.monospacedDigit()
.foregroundStyle(Theme.onSurfaceVariant)
}
.padding(.vertical, Theme.Space.xs)
case let .reply(thread, quoted, body):
VStack(alignment: .leading, spacing: Theme.Space.sm) {
HStack(alignment: .top, spacing: Theme.Space.sm) {
Rectangle()
.fill(Theme.ruleStrong)
.frame(width: 1)
VStack(alignment: .leading, spacing: Theme.Space.xxs) {
MicroLabel("You · on \u{201C}\(thread)\u{201D}")
.lineLimit(1)
Text(quoted)
.ledgerType(.bodySm)
.foregroundStyle(Theme.onSurfaceVariant)
.fixedSize(horizontal: false, vertical: true)
}
}
.fixedSize(horizontal: false, vertical: true)
Text(body)
.ledgerType(.bodyMd)
.foregroundStyle(Theme.onSurface)
.fixedSize(horizontal: false, vertical: true)
}
case .follow(let bio):
HStack {
Text(bio)
.ledgerType(.bodySm)
.monospacedDigit()
.foregroundStyle(Theme.onSurfaceVariant)
Spacer()
Button {
withAnimation(Theme.Motion.stateChange) { followedBack.toggle() }
} label: {
Text(followedBack ? "Following" : "Follow back")
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(Theme.onSurface)
.padding(.horizontal, Theme.Space.md)
.frame(height: 32)
.background(
RoundedRectangle(cornerRadius: Theme.Radius.md, style: .continuous)
.fill(followedBack ? Theme.surface : Theme.surfaceRaised)
)
.overlay(
RoundedRectangle(cornerRadius: Theme.Radius.md, style: .continuous)
.strokeBorder(followedBack ? Theme.rule : Theme.ruleStrong, lineWidth: followedBack ? 0.5 : 1)
)
}
.buttonStyle(.plain)
.sensoryFeedback(.impact(weight: .light), trigger: followedBack)
}
case let .template(title, lines, uses):
VStack(alignment: .leading, spacing: 0) {
HStack(alignment: .firstTextBaseline) {
Text(title)
.ledgerType(.headlineMd)
.foregroundStyle(Theme.onSurface)
Spacer()
Tag("Template")
}
.padding(.bottom, Theme.Space.sm)
Hairline(strong: true)
ForEach(lines.indices, id: \.self) { i in
HStack {
Text(lines[i].0)
.ledgerType(.bodySm)
.foregroundStyle(Theme.onSurfaceVariant)
Spacer()
Text(lines[i].1)
.font(.system(size: 13, weight: .regular, design: .monospaced))
.foregroundStyle(Theme.onSurface)
}
.frame(height: 36)
if i < lines.count - 1 { Hairline() }
}
Hairline()
HStack {
Text("Copied by \(uses.formatted())")
.ledgerType(.bodySm)
.monospacedDigit()
.foregroundStyle(Theme.onSurfaceMuted)
Spacer()
Button("Copy template") {}
.font(.system(size: 13, weight: .semibold))
.foregroundStyle(Theme.primaryInk)
}
.padding(.top, Theme.Space.sm)
}
.ledgerCard(padding: Theme.Space.md)
}
}
private var hasActions: Bool {
if case .follow = item.kind { return false }
return true
}
private var actions: some View {
HStack(spacing: Theme.Space.xl) {
Button(action: onLike) {
HStack(spacing: Theme.Space.xs) {
Image(systemName: liked ? "heart.fill" : "heart")
.font(.system(size: 13, weight: .semibold))
Text("\(item.likes + (liked ? 1 : 0))")
.font(.system(size: 13, weight: .regular, design: .monospaced))
.contentTransition(.numericText(value: Double(item.likes + (liked ? 1 : 0))))
}
.foregroundStyle(liked ? Theme.onSurface : Theme.onSurfaceMuted)
.frame(minHeight: 32)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.sensoryFeedback(.impact(weight: .light), trigger: liked)
.accessibilityLabel(liked ? "Unlike" : "Like")
Button {} label: {
HStack(spacing: Theme.Space.xs) {
Image(systemName: "arrowshape.turn.up.left")
.font(.system(size: 13, weight: .semibold))
Text(item.replies > 0 ? "\(item.replies)" : "Reply")
.font(.system(size: 13, weight: .regular, design: .monospaced))
}
.foregroundStyle(Theme.onSurfaceMuted)
.frame(minHeight: 32)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityLabel("Reply")
Spacer()
}
}
}
#Preview("Light") {
FeedView()
}
#Preview("Dark") {
FeedView().preferredColorScheme(.dark)
}
More screens





