From 347c662a83bc49842eee4f488d5a2a522ec9a52e Mon Sep 17 00:00:00 2001 From: Junhui Chen Date: Tue, 9 Sep 2025 12:20:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E9=87=8D=E6=9E=84=E7=9B=AE?= =?UTF-8?q?=E5=BD=95=E7=BB=93=E6=9E=84=E5=B9=B6=E9=80=82=E9=85=8D=20SwiftU?= =?UTF-8?q?I=20onChange=20=E6=96=B0=E8=AF=AD=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- specs/refactor_spec.md | 6 +++++- .../View/{ContentView.swift => BlindBoxView.swift} | 10 +++++----- wake/SharedUI/{Animation => Media}/GIFView.swift | 0 wake/SharedUI/{Animation => Media}/SVGImage.swift | 0 wake/SharedUI/{Animation => Modals}/SheetModal.swift | 0 wake/View/Components/Upload/ImageMultiUploader.swift | 8 ++++---- wake/View/Examples/MediaDemo.swift | 2 +- wake/View/OnBoarding/MediaUploadView.swift | 2 +- wake/View/OnBoarding/UserInfo.swift | 2 +- wake/View/Owner/UserInfo/AvatarPicker.swift | 2 +- wake/View/Subscribe/SubscribeView.swift | 4 ++-- 11 files changed, 20 insertions(+), 16 deletions(-) rename wake/Features/BlindBox/View/{ContentView.swift => BlindBoxView.swift} (99%) rename wake/SharedUI/{Animation => Media}/GIFView.swift (100%) rename wake/SharedUI/{Animation => Media}/SVGImage.swift (100%) rename wake/SharedUI/{Animation => Modals}/SheetModal.swift (100%) diff --git a/specs/refactor_spec.md b/specs/refactor_spec.md index 7b5b743..ff9c159 100644 --- a/specs/refactor_spec.md +++ b/specs/refactor_spec.md @@ -109,7 +109,11 @@ - 完成 SharedUI 与 Core 的第 1–3 步迁移: - SharedUI:`LottieView.swift`、`GIFView.swift`、`SVGImage.swift`、`SheetModal.swift` 已迁移至 `wake/SharedUI/...`(当前均放在 `Animation/` 分组,后续可按需细分 `Media/`、`Modals/`)。 - Core:`Router.swift` 已迁至 `Core/Navigation/`,`NetworkService.swift` 已迁至 `Core/Network/`,`Theme.swift` 与 `Typography.swift` 已迁至 `Core/DesignSystem/`。 - - 待迁移:`Performance.swift` → `Core/Diagnostics/`,`APIConfig.swift` → `Core/Network/`。 + + - 2025-09-09 11:30 +08: 更新 structure-1: + - 已完成 `Performance.swift` → `Core/Diagnostics/`,`APIConfig.swift` → `Core/Network/`。 + - 已完成 `SVGImageHtml.swift` → `SharedUI/Media/`。 + - 待优化(可选):将 `GIFView.swift`、`SVGImage.swift` 从 `SharedUI/Animation/` 细分到 `SharedUI/Media/`;将 `SheetModal.swift` 从 `SharedUI/Animation/` 移至 `SharedUI/Modals/`。 ## structure-1 目录重构计划与迁移步骤 diff --git a/wake/Features/BlindBox/View/ContentView.swift b/wake/Features/BlindBox/View/BlindBoxView.swift similarity index 99% rename from wake/Features/BlindBox/View/ContentView.swift rename to wake/Features/BlindBox/View/BlindBoxView.swift index b3ba13e..91baf70 100644 --- a/wake/Features/BlindBox/View/ContentView.swift +++ b/wake/Features/BlindBox/View/BlindBoxView.swift @@ -193,7 +193,7 @@ struct BlindBoxView: View { object: nil ) } - .onChange(of: viewModel.blindGenerate?.status) { status in + .onChange(of: viewModel.blindGenerate?.status) { _, status in guard let status = status?.lowercased() else { return } if status == "unopened" { Perf.event("BlindBox_Status_Unopened") @@ -203,22 +203,22 @@ struct BlindBoxView: View { withAnimation { self.animationPhase = .loading } } } - .onChange(of: animationPhase) { phase in + .onChange(of: animationPhase) { _, phase in if phase != .loading { // 仅用于迁移前清理;现倒计时在 VM 中管理 } } - .onChange(of: viewModel.videoURL) { url in + .onChange(of: viewModel.videoURL) { _, url in if !url.isEmpty { withAnimation { self.animationPhase = .ready } } } - .onChange(of: viewModel.imageURL) { url in + .onChange(of: viewModel.imageURL) { _, url in if !url.isEmpty { withAnimation { self.animationPhase = .ready } } } - .onChange(of: viewModel.didBootstrap) { done in + .onChange(of: viewModel.didBootstrap) { _, done in guard done else { return } // 根据首帧状态决定初始动画态,避免先显示 loading 再跳到 ready 的割裂感 let initialStatus = viewModel.blindGenerate?.status.lowercased() ?? "" diff --git a/wake/SharedUI/Animation/GIFView.swift b/wake/SharedUI/Media/GIFView.swift similarity index 100% rename from wake/SharedUI/Animation/GIFView.swift rename to wake/SharedUI/Media/GIFView.swift diff --git a/wake/SharedUI/Animation/SVGImage.swift b/wake/SharedUI/Media/SVGImage.swift similarity index 100% rename from wake/SharedUI/Animation/SVGImage.swift rename to wake/SharedUI/Media/SVGImage.swift diff --git a/wake/SharedUI/Animation/SheetModal.swift b/wake/SharedUI/Modals/SheetModal.swift similarity index 100% rename from wake/SharedUI/Animation/SheetModal.swift rename to wake/SharedUI/Modals/SheetModal.swift diff --git a/wake/View/Components/Upload/ImageMultiUploader.swift b/wake/View/Components/Upload/ImageMultiUploader.swift index 788ea11..88d0ba8 100644 --- a/wake/View/Components/Upload/ImageMultiUploader.swift +++ b/wake/View/Components/Upload/ImageMultiUploader.swift @@ -99,20 +99,20 @@ public struct MultiImageUploader: View { } } } - .onChange(of: isImagePickerPresented) { newValue in + .onChange(of: isImagePickerPresented) { _, newValue in if newValue { showingImagePicker = true } } - .onChange(of: showingImagePicker) { newValue in + .onChange(of: showingImagePicker) { _, newValue in if !newValue { isImagePickerPresented = false } } - .onChange(of: selectedImages) { newValue in + .onChange(of: selectedImages) { _, newValue in selectedImagesBinding = newValue } - .onChange(of: needsViewUpdate) { _ in + .onChange(of: needsViewUpdate) { _, _ in // Trigger view update } } diff --git a/wake/View/Examples/MediaDemo.swift b/wake/View/Examples/MediaDemo.swift index 304ad8c..aa25f5b 100644 --- a/wake/View/Examples/MediaDemo.swift +++ b/wake/View/Examples/MediaDemo.swift @@ -111,7 +111,7 @@ struct MediaUploadDemo: View { dismissButton: .default(Text("确定")) ) } - .onChange(of: uploadManager.uploadStatus) { _ in + .onChange(of: uploadManager.uploadStatus) { _, _ in // 检查是否所有上传都已完成或失败 let allFinished = uploadManager.uploadStatus.values.allSatisfy { status in if case .completed = status { return true } diff --git a/wake/View/OnBoarding/MediaUploadView.swift b/wake/View/OnBoarding/MediaUploadView.swift index 4f25b55..be4435f 100644 --- a/wake/View/OnBoarding/MediaUploadView.swift +++ b/wake/View/OnBoarding/MediaUploadView.swift @@ -85,7 +85,7 @@ struct MediaUploadView: View { // 媒体选择器 mediaPickerView } - .onChange(of: uploadManager.uploadResults) { newResults in + .onChange(of: uploadManager.uploadResults) { _, newResults in handleUploadCompletion(results: newResults) } } diff --git a/wake/View/OnBoarding/UserInfo.swift b/wake/View/OnBoarding/UserInfo.swift index 18d1202..b57340b 100644 --- a/wake/View/OnBoarding/UserInfo.swift +++ b/wake/View/OnBoarding/UserInfo.swift @@ -291,7 +291,7 @@ struct UserInfo: View { isKeyboardVisible = isVisible } } - .onChange(of: isTextFieldFocused) { newValue in + .onChange(of: isTextFieldFocused) { _, newValue in withAnimation(.easeInOut(duration: 0.2)) { isKeyboardVisible = newValue } diff --git a/wake/View/Owner/UserInfo/AvatarPicker.swift b/wake/View/Owner/UserInfo/AvatarPicker.swift index ed7dcd4..08d94de 100644 --- a/wake/View/Owner/UserInfo/AvatarPicker.swift +++ b/wake/View/Owner/UserInfo/AvatarPicker.swift @@ -156,7 +156,7 @@ public struct AvatarPicker: View { } ) } - .onChange(of: uploadManager.uploadStatus) { status in + .onChange(of: uploadManager.uploadStatus) { _, status in print("🔄 Upload status changed: ", status) // 检查是否有待处理的上传 diff --git a/wake/View/Subscribe/SubscribeView.swift b/wake/View/Subscribe/SubscribeView.swift index 02a886b..0342efa 100644 --- a/wake/View/Subscribe/SubscribeView.swift +++ b/wake/View/Subscribe/SubscribeView.swift @@ -109,11 +109,11 @@ struct SubscribeView: View { await store.loadProducts() await store.refreshEntitlements() } - .onChange(of: store.isPurchasing) { newValue in + .onChange(of: store.isPurchasing) { _, newValue in // Bind purchasing state to button loading isLoading = newValue } - .onChange(of: store.errorMessage) { newValue in + .onChange(of: store.errorMessage) { _, newValue in if let message = newValue, !message.isEmpty { errorText = message showErrorAlert = true