отступы между карточек

This commit is contained in:
cheykrym 2025-08-13 02:32:18 +03:00
parent b0d5429ae6
commit 4ec99934e4

View File

@ -17,25 +17,26 @@ struct NewHomeTab: View {
ProgressView("Загрузка ленты...") ProgressView("Загрузка ленты...")
} else { } else {
ScrollView { ScrollView {
HStack(alignment: .top, spacing: 2) { HStack(alignment: .top, spacing: 6) {
LazyVStack(spacing: 8) { LazyVStack(spacing: 6) {
ForEach(column1Posts) { post in ForEach(column1Posts) { post in
PostGridItem(post: post) PostGridItem(post: post)
} }
} }
LazyVStack(spacing: 8) { LazyVStack(spacing: 6) {
ForEach(column2Posts) { post in ForEach(column2Posts) { post in
PostGridItem(post: post) PostGridItem(post: post)
} }
} }
} }
.padding(.horizontal, 2) .padding(.horizontal, 4)
} }
} }
} }
.onAppear { .onAppear {
viewModel.fetchDataIfNeeded() viewModel.fetchDataIfNeeded()
} }
.background(Color(.secondarySystemBackground)) // Фон для всей вкладки
} }
} }
@ -43,57 +44,55 @@ struct PostGridItem: View {
let post: Post let post: Post
private var randomHeight: CGFloat { private var randomHeight: CGFloat {
// Мы можем сделать высоту зависимой от типа контента, если нужно
// пока оставим случайной для визуального разнообразия
CGFloat.random(in: 150...300) CGFloat.random(in: 150...300)
} }
var body: some View { var body: some View {
VStack(alignment: .leading, spacing: 8) { VStack(alignment: .leading, spacing: 0) { // Убираем отступ между картинкой и текстом
// 1. Медиа контент // 1. Медиа контент
if let _ = post.media.first { if let _ = post.media.first {
Image("placeholderPhoto") // Используем локальный плейсхолдер Image("placeholderPhoto")
.resizable() .resizable()
.aspectRatio(contentMode: .fill) .aspectRatio(contentMode: .fill)
.frame(height: randomHeight) .frame(height: randomHeight)
.clipped()
.cornerRadius(10)
} }
// 2. Название поста // Контейнер для текста, который создает эффект "расширения"
if let title = post.title, !title.isEmpty { VStack(alignment: .leading, spacing: 8) {
Text(title) // 2. Название поста
.font(.headline) if let title = post.title, !title.isEmpty {
.lineLimit(2) Text(title)
}
// 3. Информация об авторе и лайки
HStack {
// Аватар и имя пользователя
HStack(spacing: 4) {
Image(systemName: "person.circle.fill")
.resizable()
.frame(width: 24, height: 24)
.foregroundColor(.gray)
Text(post.authorUsername)
.font(.subheadline) .font(.subheadline)
.lineLimit(1) .lineLimit(2)
} }
Spacer() // 3. Информация об авторе и лайки
HStack {
// Лайки HStack(spacing: 4) {
HStack(spacing: 4) { Image(systemName: "person.circle.fill")
Image(systemName: post.isLikedByCurrentUser ? "heart.fill" : "heart") .resizable()
.foregroundColor(post.isLikedByCurrentUser ? .red : .primary) .frame(width: 20, height: 20)
Text("\(post.likes)") .foregroundColor(.gray)
.font(.subheadline) Text(post.authorUsername)
.font(.footnote)
.lineLimit(1)
}
Spacer()
HStack(spacing: 4) {
Image(systemName: post.isLikedByCurrentUser ? "heart.fill" : "heart")
.foregroundColor(post.isLikedByCurrentUser ? .red : .primary)
Text("\(post.likes)")
.font(.subheadline)
}
} }
} }
.padding(8)
.background(Color(UIColor.systemBackground)) // Фон только для текстовой части
} }
.padding(8) .cornerRadius(6) // Закругляем всю карточку
.background(Color(UIColor.systemBackground)) // Для поддержки темной/светлой темы .clipped() // Обрезаем дочерние вью по закругленной форме родителя
.cornerRadius(12)
.shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 2) .shadow(color: Color.black.opacity(0.1), radius: 5, x: 0, y: 2)
} }
} }