import SwiftUI // MARK: - BackgroundView struct MomentListBackgroundView: View { var body: some View { Image("bg") .resizable() .aspectRatio(contentMode: .fill) .frame(maxWidth: .infinity, maxHeight: .infinity) .clipped() .ignoresSafeArea(.all) } } // MARK: - MomentListHomePage struct MomentListHomePage: View { @StateObject private var viewModel = MomentListHomeViewModel() var body: some View { GeometryReader { geometry in ZStack { // 背景 MomentListBackgroundView() VStack(alignment: .center, spacing: 0) { // 标题 Text(LocalizedString("feedList.title", comment: "Enjoy your Life Time")) .font(.system(size: 22, weight: .semibold)) .foregroundColor(.white) .frame(maxWidth: .infinity, alignment: .center) .padding(.top, 60) // Volume 图标 Image("Volume") .frame(width: 56, height: 41) .padding(.top, 16) // 标语 Text(LocalizedString("feedList.slogan", comment: "The disease is like a cruel ruler,\nand time is our most precious treasure.\nEvery moment we live is a victory\nagainst the inevitable.")) .font(.system(size: 16)) .multilineTextAlignment(.leading) .foregroundColor(.white.opacity(0.9)) .padding(.horizontal, 30) .padding(.bottom, 30) // 动态列表内容 if !viewModel.moments.isEmpty { // 显示第一个数据来测试效果 MomentListItem(moment: viewModel.moments[0]) .padding(.horizontal, 16) .padding(.bottom, 20) } else if viewModel.isLoading { ProgressView() .progressViewStyle(CircularProgressViewStyle(tint: .white)) .padding(.top, 20) } else if let error = viewModel.error { Text(error) .font(.system(size: 14)) .foregroundColor(.red) .multilineTextAlignment(.center) .padding(.horizontal, 20) .padding(.top, 20) } Spacer() } } } .ignoresSafeArea() .onAppear { viewModel.onAppear() } } }