-
Notifications
You must be signed in to change notification settings - Fork 316
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduced debugRevenueCatOverlay()
: new SwiftUI debug overlay
#2567
Merged
NachoSoto
merged 14 commits into
main
from
nacho/sdk-3152-purchase-tester-automatically-included-in-debug-mode
Jun 7, 2023
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a2071e5
Introduced `debugRevenueCatOverlay()`: new SwiftUI debug overlay
NachoSoto 2d7be1e
API tester
NachoSoto 5144fcb
Documentation
NachoSoto 12c3f27
Added missing `@available`
NachoSoto 4d88091
Added configuration
NachoSoto bc550ff
Only available on iOS
NachoSoto 1819057
Manual display
NachoSoto 98aa9f9
Fixed custom entitlement computation build
NachoSoto b34566f
Disable on Xcode 13.x
NachoSoto 3b3c19f
Added framework version
NachoSoto 51ed2f8
Removed hacks
NachoSoto 5485e1b
Simplified implementation
NachoSoto 4772581
Added `customerInfoStream`
NachoSoto fdc749b
Simplified `Configuration` creation
NachoSoto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,255 @@ | ||
// | ||
// Copyright RevenueCat Inc. All Rights Reserved. | ||
// | ||
// Licensed under the MIT License (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// https://opensource.org/licenses/MIT | ||
// | ||
// DebugViewContent.swift | ||
// | ||
// Created by Nacho Soto on 5/30/23. | ||
|
||
#if DEBUG && os(iOS) && swift(>=5.8) | ||
|
||
import SwiftUI | ||
|
||
@available(iOS 16.0, *) | ||
struct DebugSwiftUIRootView: View { | ||
|
||
@StateObject | ||
private var model = DebugViewModel() | ||
|
||
var body: some View { | ||
NavigationStack(path: self.$model.navigationPath) { | ||
DebugSummaryView(model: self.model) | ||
.navigationDestination(for: DebugViewPath.self) { path in | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. New SwiftUI navigation API 🤓 |
||
switch path { | ||
case let .offering(offering): | ||
DebugOfferingView(offering: offering) | ||
|
||
case let .package(package): | ||
DebugPackageView(package: package) | ||
} | ||
} | ||
.background( | ||
Rectangle() | ||
.foregroundStyle(Material.thinMaterial) | ||
.edgesIgnoringSafeArea(.all) | ||
) | ||
} | ||
.task { | ||
await self.model.load() | ||
} | ||
} | ||
|
||
} | ||
|
||
private enum DebugViewPath: Hashable { | ||
|
||
case offering(Offering) | ||
case package(Package) | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) | ||
private struct DebugSummaryView: View { | ||
|
||
@ObservedObject | ||
var model: DebugViewModel | ||
|
||
var body: some View { | ||
List { | ||
self.diagnosticsSection | ||
|
||
self.configurationSection | ||
|
||
#if !ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION | ||
self.customerInfoSection | ||
#endif | ||
|
||
self.offeringsSection | ||
} | ||
.listStyle(.insetGrouped) | ||
.scrollContentBackground(.hidden) | ||
.navigationTitle("RevenueCat Debug View") | ||
} | ||
|
||
private var diagnosticsSection: some View { | ||
Section("Diagnostics") { | ||
LabeledContent("Status") { | ||
HStack { | ||
Text(self.model.diagnosticsStatus) | ||
self.model.diagnosticsIcon | ||
} | ||
} | ||
} | ||
} | ||
|
||
private var configurationSection: some View { | ||
Section("Configuration") { | ||
switch self.model.configuration { | ||
case .loading: | ||
Text("Loading...") | ||
|
||
case let .loaded(config): | ||
LabeledContent("SDK version", value: SystemInfo.frameworkVersion) | ||
LabeledContent("Observer mode", value: config.observerMode.description) | ||
LabeledContent("Sandbox", value: config.sandbox.description) | ||
LabeledContent("StoreKit 2", value: config.storeKit2Enabled ? "on" : "off") | ||
LabeledContent("Offline Customer Info", | ||
value: config.offlineCustomerInfoSupport ? "enabled" : "disabled") | ||
LabeledContent("Entitlement Verification Mode", value: config.verificationMode.display) | ||
} | ||
} | ||
} | ||
|
||
#if !ENABLE_CUSTOM_ENTITLEMENT_COMPUTATION | ||
private var customerInfoSection: some View { | ||
Section("Customer Info") { | ||
switch self.model.customerInfo { | ||
case .loading: | ||
Text("Loading...") | ||
|
||
case let .loaded(info): | ||
LabeledContent("User ID", value: info.originalAppUserId) | ||
LabeledContent("Active Entitlements", value: info.entitlements.active.count.description) | ||
|
||
if let latestExpiration = info.latestExpirationDate { | ||
LabeledContent("Latest Expiration Date", | ||
value: latestExpiration.formatted(date: .abbreviated, | ||
time: .omitted)) | ||
} | ||
|
||
case let .failed(error): | ||
Text("Error loading customer info: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
#endif | ||
|
||
@ViewBuilder | ||
private var offeringsSection: some View { | ||
Section("Offerings") { | ||
switch self.model.offerings { | ||
case .loading: | ||
Text("Loading...") | ||
|
||
case let .loaded(offerings): | ||
ForEach(Array(offerings.all.values)) { offering in | ||
NavigationLink(value: DebugViewPath.offering(offering)) { | ||
VStack { | ||
LabeledContent( | ||
offering.identifier, | ||
value: "\(offering.availablePackages.count) package(s)" | ||
) | ||
} | ||
} | ||
} | ||
|
||
case let .failed(error): | ||
Text("Error loading offerings: \(error.localizedDescription)") | ||
} | ||
} | ||
} | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) | ||
private struct DebugOfferingView: View { | ||
|
||
var offering: Offering | ||
|
||
var body: some View { | ||
List { | ||
Section("Data") { | ||
LabeledContent("Identifier", value: self.offering.id) | ||
LabeledContent("Description", value: self.offering.serverDescription) | ||
} | ||
|
||
Section("Packages") { | ||
ForEach(self.offering.availablePackages) { package in | ||
NavigationLink(value: DebugViewPath.package(package)) { | ||
Text(package.identifier) | ||
} | ||
} | ||
} | ||
} | ||
.navigationTitle("Offering") | ||
} | ||
|
||
} | ||
|
||
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *) | ||
private struct DebugPackageView: View { | ||
|
||
var package: Package | ||
|
||
@State private var error: NSError? { | ||
didSet { | ||
if self.error != nil { | ||
self.displayError = true | ||
} | ||
} | ||
} | ||
|
||
@State private var displayError: Bool = false | ||
@State private var purchasing: Bool = false | ||
|
||
var body: some View { | ||
List { | ||
Section("Data") { | ||
LabeledContent("Identifier", value: self.package.identifier) | ||
LabeledContent("Price", value: self.package.localizedPriceString) | ||
LabeledContent("Product", value: self.package.storeProduct.productIdentifier) | ||
LabeledContent("Type", value: self.package.packageType.description ?? "") | ||
} | ||
|
||
Section("Purchasing") { | ||
Button { | ||
_ = Task<Void, Never> { | ||
do { | ||
self.purchasing = true | ||
try await self.purchase() | ||
} catch { | ||
self.error = error as NSError | ||
} | ||
|
||
self.purchasing = false | ||
} | ||
} label: { | ||
Text("Purchase") | ||
} | ||
.disabled(self.purchasing) | ||
} | ||
} | ||
.navigationTitle("Package") | ||
.alert( | ||
"Error", | ||
isPresented: self.$displayError, | ||
presenting: self.error | ||
) { error in | ||
Text(error.localizedDescription) | ||
} | ||
} | ||
|
||
private func purchase() async throws { | ||
_ = try await Purchases.shared.purchase(package: self.package) | ||
} | ||
|
||
} | ||
|
||
private extension Signing.ResponseVerificationMode { | ||
|
||
var display: String { | ||
switch self { | ||
case .disabled: return "disabled" | ||
case .informational: return "informational" | ||
case .enforced: return "enforced" | ||
} | ||
} | ||
|
||
} | ||
|
||
#endif |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we support macos as well? It probably shouldn't be a bottom sheet though... We can think about it and add in a future PR though
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah we'd have to make it slightly different cause that API isn't available there 👍🏻