Migrate from iOS 17 Observation to iOS 16-compatible Combine architecture.
Lower deployment target to iOS 16, replace @Observable with ObservableObject, add navigation and UI compatibility shims, and include login smoke UI tests. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@ -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) {
|
||||
|
||||
@ -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
|
||||
|
||||
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user