mirror of
https://github.com/RevenueCat/purchases-ios
synced 2026-11-11 22:55:55 +05:45
Follow up to #2518. Also fixed the `CustomerInfo` `Picker`, which wasn't working on iOS due to its design.
59 lines
1.4 KiB
Swift
59 lines
1.4 KiB
Swift
//
|
|
// ProxyView.swift
|
|
// PurchaseTester
|
|
//
|
|
// Created by Nacho Soto on 5/19/23.
|
|
//
|
|
|
|
import Foundation
|
|
import SwiftUI
|
|
|
|
struct ProxyView: View {
|
|
|
|
@StateObject
|
|
private var viewModel: ProxyViewModel = .init()
|
|
@State
|
|
private var changingMode: Bool = false
|
|
|
|
let proxyURL: URL?
|
|
|
|
var body: some View {
|
|
if let proxyURL {
|
|
VStack {
|
|
Text(verbatim: "\(self.viewModel.proxyStatus?.description ?? "loading...")")
|
|
.task(id: proxyURL) {
|
|
await self.viewModel.refreshStatus(proxyURL: proxyURL)
|
|
}
|
|
|
|
|
|
HStack(spacing: 5) {
|
|
ForEach(ProxyStatus.Mode.allCases, id: \.self) { mode in
|
|
self.modeButton(mode, proxyURL: proxyURL)
|
|
}
|
|
}
|
|
.frame(maxWidth: .infinity)
|
|
}
|
|
} else {
|
|
EmptyView()
|
|
}
|
|
}
|
|
|
|
@ViewBuilder
|
|
private func modeButton(_ mode: ProxyStatus.Mode, proxyURL: URL) -> some View {
|
|
Button {
|
|
self.changingMode = true
|
|
|
|
Task<Void, Never> {
|
|
await self.viewModel.changeMode(to: mode, proxyURL: proxyURL)
|
|
|
|
self.changingMode = false
|
|
}
|
|
} label: {
|
|
Text(mode.description)
|
|
}
|
|
.buttonStyle(.borderedProminent)
|
|
.disabled(self.changingMode)
|
|
}
|
|
|
|
}
|