Untitled

 avatar
unknown
swift
7 hours ago
2.1 kB
22
No Index
import SwiftUI

struct FeedItem<Icon: View, Title: View, Content: View>: View {
	@ViewBuilder var icon: () -> Icon
	@ViewBuilder var title: () -> Title
	@ViewBuilder var content: () -> Content

	var body: some View {
		HStack(alignment: .top, spacing: 4) {
			VStack(spacing: 4) {
				icon()

				Color.gray
					.frame(width: 1)
			}

			VStack(alignment: .leading, spacing: 4) {
				title()
				content()
			}
			.frame(maxWidth: .infinity, alignment: .leading)
		}
		.fixedSize(horizontal: false, vertical: true)
	}
}

struct Timestamp: View {
	let date: String

	var body: some View {
		Text(date)
			.font(.caption2)
			.italic()
			.foregroundStyle(Color.secondary)
			.frame(maxWidth: .infinity, alignment: .trailing)
	}
}

struct FeedIcon: View {
	let systemName: String

	var body: some View {
		Image(systemName: systemName)
			.font(.footnote)
	}
}

#Preview {
	VStack(alignment: .leading, spacing: 4) {
		FeedItem {
			FeedIcon(systemName: "bell.circle.fill")
				.foregroundStyle(Color.cyan)
		} title: {
			Text("This is a really long title that wraps to the next line because there are so many words")
				.font(.footnote)
		} content: {
			Timestamp(date: "Apr 23, 12 AM")
		}

		FeedItem {
			FeedIcon(systemName: "person.circle.fill")
				.foregroundStyle(Color.orange)
		} title: {
			Text("You have a new follower!")
				.font(.footnote)
		} content: {
			Timestamp(date: "Apr 23, 12 PM")
		}

		FeedItem {
			FeedIcon(systemName: "square.and.arrow.up.circle.fill")
				.foregroundStyle(Color.blue)
		} title: {
			Text("Left Hand RS3-48 Yard Club")
				.font(.footnote)
		} content: {
			VStack(alignment: .leading, spacing: 4) {
				Text("Designed to help first-time golfers learn to hit balls, enjoy the game, and achieve quick success, it features a super-lightweight, oversized head that provides a larger hitting area for easier, more accurate shots.")
					.font(.caption2)
					.foregroundStyle(Color.white)
					.padding(4)
					.background(Color.black.clipShape(RoundedRectangle(cornerRadius: 6)))

				Timestamp(date: "Apr 17, 12 PM")
			}
		}
	}
	.padding()
	.background(Color.black.opacity(0.1))
}
Editor is loading...