import SwiftUI private struct CenteredPost: View where Content: View { let content: Content init(@ViewBuilder content: () -> Content) { self.content = content() } var body: some View { HorizontalCenter { content } .listRowBackground(ColorPalette.listBackground) } } struct PostList: View { @EnvironmentObject private var content: Content var body: some View { List { if content.posts.isEmpty { CenteredPost { Text("No posts yet.") .padding() } .listRowSeparator(.hidden) } CenteredPost { Button(action: addNewPost) { Text("Add post") } .padding() .listRowSeparator(.hidden) } ForEach(content.posts) { post in CenteredPost { PostView(post: post) .frame(maxWidth: 600) } .listRowSeparator(.hidden) .listRowInsets(.init(top: 0, leading: 0, bottom: 30, trailing: 0)) } } .listStyle(.plain) .background(ColorPalette.listBackground) .scrollContentBackground(.hidden) } private func addNewPost() { let post = Post( id: "new", isDraft: true, createdDate: .now, startDate: .now, endDate: nil, tags: [], german: .init(title: "Titel", content: "Text"), english: .init(title: "Title", content: "Text")) content.posts.insert(post, at: 0) } } #Preview { PostList() .environmentObject(Content()) }