
- 将MeDynamicFeature重命名为MeFeature,并在MainFeature中进行相应更新。 - 更新MainFeature的状态管理,整合用户动态相关逻辑。 - 新增MeFeature以管理用户信息和动态加载,提升代码结构清晰度。 - 更新MainView和MeView以适应新的MeFeature,优化用户体验。 - 删除冗余的MeDynamicView,简化视图结构,提升代码可维护性。
108 lines
5.4 KiB
Swift
108 lines
5.4 KiB
Swift
import SwiftUI
|
|
import ComposableArchitecture
|
|
|
|
struct MeView: View {
|
|
let store: StoreOf<MeFeature>
|
|
|
|
var body: some View {
|
|
WithViewStore(self.store, observe: { $0 }) { viewStore in
|
|
GeometryReader { geometry in
|
|
ZStack {
|
|
Image("bg")
|
|
.resizable()
|
|
.aspectRatio(contentMode: .fill)
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
.clipped()
|
|
.ignoresSafeArea(.all)
|
|
VStack(spacing: 0) {
|
|
// 用户信息区域
|
|
if viewStore.isLoadingUserInfo {
|
|
ProgressView()
|
|
.progressViewStyle(CircularProgressViewStyle(tint: .white))
|
|
.frame(height: 130)
|
|
} else if let error = viewStore.userInfoError {
|
|
Text(error)
|
|
.font(.system(size: 14))
|
|
.foregroundColor(.red)
|
|
.frame(height: 130)
|
|
} else if let userInfo = viewStore.userInfo {
|
|
VStack(spacing: 8) {
|
|
if let avatarUrl = userInfo.avatar, !avatarUrl.isEmpty {
|
|
AsyncImage(url: URL(string: avatarUrl)) { image in
|
|
image.resizable().aspectRatio(contentMode: .fill).clipShape(Circle())
|
|
} placeholder: {
|
|
Image(systemName: "person.fill").font(.system(size: 40)).foregroundColor(.white)
|
|
}
|
|
.frame(width: 90, height: 90)
|
|
} else {
|
|
Image(systemName: "person.fill").font(.system(size: 40)).foregroundColor(.white)
|
|
.frame(width: 90, height: 90)
|
|
}
|
|
Text(userInfo.nick ?? "用户昵称")
|
|
.font(.system(size: 18, weight: .medium))
|
|
.foregroundColor(.white)
|
|
Text("ID: \(userInfo.uid ?? 0)")
|
|
.font(.system(size: 14))
|
|
.foregroundColor(.white.opacity(0.7))
|
|
}
|
|
.frame(height: 130)
|
|
} else {
|
|
Spacer().frame(height: 130)
|
|
}
|
|
// 动态内容区域
|
|
if viewStore.isLoadingMoments && viewStore.moments.isEmpty {
|
|
ProgressView("加载中...")
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
} else if let error = viewStore.momentsError {
|
|
VStack(spacing: 16) {
|
|
Image(systemName: "exclamationmark.triangle.fill")
|
|
.font(.system(size: 40))
|
|
.foregroundColor(.yellow)
|
|
Text(error)
|
|
.foregroundColor(.red)
|
|
Button("重试") {
|
|
viewStore.send(.onAppear)
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
} else if viewStore.moments.isEmpty {
|
|
VStack(spacing: 16) {
|
|
Image(systemName: "tray")
|
|
.font(.system(size: 40))
|
|
.foregroundColor(.gray)
|
|
Text("暂无动态")
|
|
.foregroundColor(.white.opacity(0.8))
|
|
}
|
|
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
|
} else {
|
|
ScrollView {
|
|
LazyVStack(spacing: 12) {
|
|
ForEach(Array(viewStore.moments.enumerated()), id: \ .element.dynamicId) { index, moment in
|
|
OptimizedDynamicCardView(moment: moment, allMoments: viewStore.moments, currentIndex: index)
|
|
.padding(.horizontal, 12)
|
|
}
|
|
if viewStore.hasMore {
|
|
ProgressView()
|
|
.onAppear {
|
|
viewStore.send(.loadMore)
|
|
}
|
|
}
|
|
}
|
|
.padding(.top, 8)
|
|
}
|
|
.refreshable {
|
|
viewStore.send(.refresh)
|
|
}
|
|
}
|
|
Spacer()
|
|
}
|
|
.frame(maxWidth: .infinity, alignment: .top)
|
|
}
|
|
}
|
|
.onAppear {
|
|
viewStore.send(.onAppear)
|
|
}
|
|
}
|
|
}
|
|
}
|