
- 移除DataMigrationManager类,简化数据迁移逻辑。 - 在FeedListView和MeView中新增图片预览功能,提升用户体验。 - 更新OptimizedDynamicCardView以支持图片点击回调,增强交互性。 - 新增PreviewItem结构体以管理图片预览状态,提升代码可读性与维护性。 - 清理AppDelegate中的冗余代码,优化启动流程。
152 lines
7.5 KiB
Swift
152 lines
7.5 KiB
Swift
import SwiftUI
|
||
import ComposableArchitecture
|
||
|
||
struct MeView: View {
|
||
let store: StoreOf<MeFeature>
|
||
// 新增:图片预览状态
|
||
@State private var previewItem: PreviewItem? = nil
|
||
|
||
var body: some View {
|
||
WithPerceptionTracking {
|
||
GeometryReader { geometry in
|
||
ZStack {
|
||
Image("bg")
|
||
.resizable()
|
||
.aspectRatio(contentMode: .fill)
|
||
.frame(maxWidth: .infinity, maxHeight: .infinity)
|
||
.clipped()
|
||
.ignoresSafeArea(.all)
|
||
// 顶部栏,右上角设置按钮
|
||
VStack {
|
||
HStack {
|
||
Spacer()
|
||
WithViewStore(self.store, observe: { $0 }) { viewStore in
|
||
Button(action: {
|
||
viewStore.send(.settingButtonTapped)
|
||
}) {
|
||
Image(systemName: "gearshape")
|
||
.font(.system(size: 33, weight: .medium))
|
||
.foregroundColor(.white)
|
||
}
|
||
.padding(.trailing, 16)
|
||
.padding(.top, 8)
|
||
}
|
||
}
|
||
Spacer()
|
||
}
|
||
VStack(spacing: 16) {
|
||
// 用户信息区域
|
||
WithViewStore(self.store, observe: { $0 }) { viewStore in
|
||
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))
|
||
}
|
||
.padding(.top, 0)
|
||
.frame(height: 130)
|
||
} else {
|
||
Spacer().frame(height: 130)
|
||
}
|
||
}
|
||
// 动态内容区域
|
||
WithViewStore(self.store, observe: { $0 }) { viewStore in
|
||
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 {
|
||
WithPerceptionTracking {
|
||
LazyVStack(spacing: 12) {
|
||
ForEach(viewStore.moments.indices, id: \ .self) { index in
|
||
let moment = viewStore.moments[index]
|
||
OptimizedDynamicCardView(
|
||
moment: moment,
|
||
allMoments: viewStore.moments,
|
||
currentIndex: index,
|
||
onImageTap: { images, tappedIndex in
|
||
previewItem = PreviewItem(images: images, index: tappedIndex)
|
||
}
|
||
)
|
||
.padding(.horizontal, 12)
|
||
}
|
||
if viewStore.hasMore {
|
||
ProgressView()
|
||
.onAppear {
|
||
viewStore.send(.loadMore)
|
||
}
|
||
}
|
||
// 新增底部间距
|
||
Color.clear.frame(height: 120)
|
||
}
|
||
.padding(.top, 8)
|
||
}
|
||
}
|
||
.refreshable {
|
||
viewStore.send(.refresh)
|
||
}
|
||
}
|
||
}
|
||
Spacer()
|
||
}
|
||
.frame(maxWidth: .infinity, alignment: .top)
|
||
.padding(.top, 8)
|
||
}
|
||
}
|
||
.onAppear {
|
||
ViewStore(self.store, observe: { $0 }).send(.onAppear)
|
||
}
|
||
// 新增:图片预览弹窗
|
||
.fullScreenCover(item: $previewItem) { item in
|
||
ImagePreviewPager(images: item.images, currentIndex: .constant(item.index)) {
|
||
previewItem = nil
|
||
}
|
||
}
|
||
}
|
||
}
|
||
}
|