从 iOS 17 Observation 迁移至 iOS 16 兼容的 Combine 架构

将最低部署版本降至 iOS 16,以 ObservableObject 替换 @Observable,新增导航与 UI 兼容层,并补充登录冒烟 UI 测试。

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-06-26 10:16:35 +08:00
parent 0314033a7f
commit 703078352c
127 changed files with 2320 additions and 1465 deletions

View File

@ -6,7 +6,7 @@
//
import Foundation
import Observation
import Combine
///
@MainActor
@ -20,9 +20,8 @@ protocol InviteServing {
/// API
@MainActor
@Observable
final class InviteAPI: InviteServing {
@ObservationIgnored private let client: APIClient
private let client: APIClient
/// API
init(client: APIClient) {

View File

@ -7,22 +7,21 @@
import CoreImage.CIFilterBuiltins
import Foundation
import Observation
import Combine
import UIKit
/// ViewModel
@MainActor
@Observable
final class PhotographerInviteViewModel {
private(set) var loading = false
private(set) var inviteCode = ""
private(set) var inviteUrl = ""
private(set) var rules: [String] = []
private(set) var qrImage: UIImage?
var errorMessage: String?
final class PhotographerInviteViewModel: ObservableObject {
@Published private(set) var loading = false
@Published private(set) var inviteCode = ""
@Published private(set) var inviteUrl = ""
@Published private(set) var rules: [String] = []
@Published private(set) var qrImage: UIImage?
@Published var errorMessage: String?
@ObservationIgnored private let qrContext = CIContext()
@ObservationIgnored private let qrFilter = CIFilter.qrCodeGenerator()
private let qrContext = CIContext()
private let qrFilter = CIFilter.qrCodeGenerator()
///
func reload(api: any InviteServing) async {
@ -72,21 +71,20 @@ final class PhotographerInviteViewModel {
/// ViewModel
@MainActor
@Observable
final class InviteRecordViewModel {
var tab: InviteRecordTab = .invite
private(set) var totalRewardText = "¥ 0.00"
private(set) var withdrawableText = "¥ 0.00"
private(set) var displayRows: [InviteDisplayRow] = []
private(set) var loading = false
private(set) var loadingMore = false
private(set) var hasMore = false
var errorMessage: String?
final class InviteRecordViewModel: ObservableObject {
@Published var tab: InviteRecordTab = .invite
@Published private(set) var totalRewardText = "¥ 0.00"
@Published private(set) var withdrawableText = "¥ 0.00"
@Published private(set) var displayRows: [InviteDisplayRow] = []
@Published private(set) var loading = false
@Published private(set) var loadingMore = false
@Published private(set) var hasMore = false
@Published var errorMessage: String?
private var inviteRows: [InviteDisplayRow] = []
private var rewardRows: [InviteDisplayRow] = []
private var invitePage = 1
private var rewardPage = 1
@Published private var inviteRows: [InviteDisplayRow] = []
@Published private var rewardRows: [InviteDisplayRow] = []
@Published private var invitePage = 1
@Published private var rewardPage = 1
private let invitePageSize = 20
private let rewardPageSize = 10

View File

@ -9,10 +9,10 @@ import SwiftUI
///
struct PhotographerInviteView: View {
@Environment(InviteAPI.self) private var inviteAPI
@Environment(ToastCenter.self) private var toastCenter
@Environment(\.inviteAPI) private var inviteAPI
@EnvironmentObject private var toastCenter: ToastCenter
@Environment(\.globalLoading) private var globalLoading
@State private var viewModel = PhotographerInviteViewModel()
@StateObject private var viewModel = PhotographerInviteViewModel()
var body: some View {
ScrollView {
@ -140,10 +140,10 @@ struct PhotographerInviteView: View {
///
struct InviteRecordView: View {
@Environment(InviteAPI.self) private var inviteAPI
@Environment(WalletAPI.self) private var walletAPI
@Environment(\.inviteAPI) private var inviteAPI
@Environment(\.walletAPI) private var walletAPI
@Environment(\.globalLoading) private var globalLoading
@State private var viewModel = InviteRecordViewModel()
@StateObject private var viewModel = InviteRecordViewModel()
var body: some View {
VStack(spacing: 0) {
@ -155,7 +155,7 @@ struct InviteRecordView: View {
}
.pickerStyle(.segmented)
.padding(AppMetrics.Spacing.medium)
.onChange(of: viewModel.tab) { _, newValue in
.onChange(of: viewModel.tab) { newValue in
Task { await viewModel.selectTab(newValue, inviteAPI: inviteAPI, walletAPI: walletAPI) }
}
recordList
@ -205,7 +205,7 @@ struct InviteRecordView: View {
ScrollView {
LazyVStack(spacing: 0) {
if viewModel.displayRows.isEmpty && !viewModel.loading {
ContentUnavailableView("暂无记录", systemImage: "tray")
AppContentUnavailableView("暂无记录", systemImage: "tray")
.frame(minHeight: 280)
}
ForEach(viewModel.displayRows) { row in