
- 在Package.swift中更新依赖路径,确保项目结构清晰。 - 在AppSettingFeature中新增初始化方法,支持用户信息、头像和昵称的设置。 - 更新FeedListFeature和MainFeature,新增测试按钮和导航功能,提升用户交互体验。 - 在MeFeature中优化用户信息加载逻辑,增强错误处理能力。 - 新增TestView以支持测试功能,验证导航跳转的有效性。 - 更新多个视图以整合新功能,提升代码可读性与维护性。
140 lines
6.9 KiB
Swift
140 lines
6.9 KiB
Swift
import SwiftUI
|
||
import ComposableArchitecture
|
||
//import OptimizedDynamicCardView // 导入新组件
|
||
|
||
struct FeedListView: View {
|
||
let store: StoreOf<FeedListFeature>
|
||
|
||
var body: some View {
|
||
WithViewStore(self.store, observe: { $0 }) { viewStore in
|
||
WithPerceptionTracking {
|
||
GeometryReader { geometry in
|
||
ZStack {
|
||
// 背景图片
|
||
Image("bg")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fill)
|
||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
.clipped()
|
||
.ignoresSafeArea(.all)
|
||
VStack(alignment: .center, spacing: 0) {
|
||
// 顶部栏
|
||
HStack {
|
||
Button(action: {
|
||
viewStore.send(.testButtonTapped)
|
||
}) {
|
||
Text("测试")
|
||
.font(.system(size: 14))
|
||
.foregroundColor(.white)
|
||
.padding(.horizontal, 12)
|
||
.padding(.vertical, 6)
|
||
.background(Color.blue.opacity(0.7))
|
||
.cornerRadius(8)
|
||
}
|
||
Spacer(minLength: 0)
|
||
Spacer(minLength: 0)
|
||
Text(NSLocalizedString("feedList.title", comment: "Enjoy your Life Time"))
|
||
.font(.system(size: 22, weight: .semibold))
|
||
.foregroundColor(.white)
|
||
.frame(maxWidth: .infinity, alignment: .center)
|
||
Spacer(minLength: 0)
|
||
Button(action: {
|
||
viewStore.send(.editFeedButtonTapped)
|
||
}) {
|
||
Image("add icon")
|
||
.resizable()
|
||
.frame(width: 36, height: 36)
|
||
}
|
||
}
|
||
.padding(.horizontal, 20)
|
||
.padding(.top, geometry.safeAreaInsets.top)
|
||
// 其他内容
|
||
Image(systemName: "heart.fill")
|
||
.font(.system(size: 60))
|
||
.foregroundColor(.red)
|
||
.padding(.top, 40)
|
||
Text(NSLocalizedString("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(.center)
|
||
.foregroundColor(.white.opacity(0.9))
|
||
.padding(.horizontal, 30)
|
||
.padding(.bottom, 30)
|
||
// 新增:动态内容列表
|
||
if viewStore.isLoading {
|
||
ProgressView()
|
||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||
.padding(.top, 20)
|
||
} else if let error = viewStore.error {
|
||
Text(error)
|
||
.font(.system(size: 14))
|
||
.foregroundColor(.red)
|
||
.multilineTextAlignment(.center)
|
||
.padding(.horizontal, 20)
|
||
.padding(.top, 20)
|
||
} else if viewStore.moments.isEmpty {
|
||
Text(NSLocalizedString("feedList.empty", comment: "暂无动态"))
|
||
.font(.system(size: 16))
|
||
.foregroundColor(.white.opacity(0.7))
|
||
.padding(.top, 20)
|
||
} else {
|
||
ScrollView {
|
||
WithPerceptionTracking {
|
||
LazyVStack(spacing: 16) {
|
||
ForEach(Array(viewStore.moments.enumerated()), id: \ .element.dynamicId) { index, moment in
|
||
OptimizedDynamicCardView(moment: moment, allMoments: viewStore.moments, currentIndex: index)
|
||
// 上拉加载更多触发点
|
||
if index == viewStore.moments.count - 1, viewStore.hasMore, !viewStore.isLoadingMore {
|
||
Color.clear
|
||
.frame(height: 1)
|
||
.onAppear {
|
||
viewStore.send(.loadMore)
|
||
}
|
||
}
|
||
}
|
||
// 加载更多指示器
|
||
if viewStore.isLoadingMore {
|
||
ProgressView()
|
||
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
||
.padding(.vertical, 8)
|
||
}
|
||
}
|
||
.padding(.horizontal, 16)
|
||
.padding(.top, 10)
|
||
.padding(.bottom, 20)
|
||
}
|
||
}
|
||
.refreshable {
|
||
viewStore.send(.reload)
|
||
}
|
||
}
|
||
Spacer()
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .top)
|
||
}
|
||
}
|
||
.onAppear {
|
||
viewStore.send(.onAppear)
|
||
}
|
||
.onReceive(NotificationCenter.default.publisher(for: Notification.Name("reloadFeedList"))) { _ in
|
||
viewStore.send(.reload)
|
||
}
|
||
.sheet(isPresented: viewStore.binding(
|
||
get: \.isEditFeedPresented,
|
||
send: { $0 ? .editFeedButtonTapped : .editFeedDismissed }
|
||
)) {
|
||
EditFeedView(
|
||
onDismiss: {
|
||
viewStore.send(.editFeedDismissed)
|
||
},
|
||
store: Store(
|
||
initialState: EditFeedFeature.State()
|
||
) {
|
||
EditFeedFeature()
|
||
}
|
||
)
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|