Skip to content

Commit

Permalink
Paywalls: added JSON debug screen to debugRevenueCatOverlay (#2972)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto authored Aug 7, 2023
1 parent ac968ff commit cddeb95
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Sources/Paywalls/PaywallColor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,14 @@ extension PaywallColor: Equatable {

}

extension PaywallColor: Hashable {

public func hash(into hasher: inout Hasher) {
hasher.combine(self.stringRepresentation)
}

Check warning on line 232 in Sources/Paywalls/PaywallColor.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Paywalls/PaywallColor.swift#L230-L232

Added lines #L230 - L232 were not covered by tests

}

extension PaywallColor: Sendable {}
extension PaywallColor: Codable {

Expand Down
14 changes: 7 additions & 7 deletions Sources/Paywalls/PaywallData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -442,13 +442,13 @@ extension PaywallData: Codable {

// MARK: - Equatable

extension PaywallData.LocalizedConfiguration.Feature: Equatable {}
extension PaywallData.LocalizedConfiguration: Equatable {}
extension PaywallData.Configuration.ColorInformation: Equatable {}
extension PaywallData.Configuration.Colors: Equatable {}
extension PaywallData.Configuration.Images: Equatable {}
extension PaywallData.Configuration: Equatable {}
extension PaywallData: Equatable {}
extension PaywallData.LocalizedConfiguration.Feature: Hashable {}
extension PaywallData.LocalizedConfiguration: Hashable {}
extension PaywallData.Configuration.ColorInformation: Hashable {}
extension PaywallData.Configuration.Colors: Hashable {}
extension PaywallData.Configuration.Images: Hashable {}
extension PaywallData.Configuration: Hashable {}
extension PaywallData: Hashable {}

// MARK: - Sendable

Expand Down
59 changes: 59 additions & 0 deletions Sources/Support/DebugUI/DebugContentViews.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ struct DebugSwiftUIRootView: View {

case let .package(package):
DebugPackageView(package: package)

case let .paywall(paywall):
DebugPaywallJSONView(paywall: paywall)

Check warning on line 46 in Sources/Support/DebugUI/DebugContentViews.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Support/DebugUI/DebugContentViews.swift#L44-L46

Added lines #L44 - L46 were not covered by tests
}
}
.background(
Expand Down Expand Up @@ -73,6 +76,7 @@ private enum DebugViewPath: Hashable {

case offering(Offering)
case package(Package)
case paywall(PaywallData)

}

Expand Down Expand Up @@ -242,6 +246,14 @@ private struct DebugOfferingView: View {
}
}

if let paywall = self.offering.paywall {
Section("RevenueCatUI paywall") {
NavigationLink(value: DebugViewPath.paywall(paywall)) {
Text("View data")
}
}
}

Check warning on line 256 in Sources/Support/DebugUI/DebugContentViews.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Support/DebugUI/DebugContentViews.swift#L249-L256

Added lines #L249 - L256 were not covered by tests
if #available(iOS 17.0, macOS 14.0, tvOS 17.0, *) {
Section("Paywalls") {
Button {
Expand Down Expand Up @@ -375,6 +387,38 @@ private struct DebugPackageView: View {

}

@available(iOS 16.0, macOS 13.0, *)
private struct DebugPaywallJSONView: View {

let paywall: PaywallData

var body: some View {
ScrollView(.vertical) {
Text(self.json)
.multilineTextAlignment(.leading)
.font(.caption)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.navigationTitle("RevenueCatUI Paywall")
.toolbar {
ToolbarItem(placement: .primaryAction) {
ShareLink(item: self.paywall, preview: .init("Paywall")) {
Label("Export", systemImage: "square.and.arrow.up")
}
}
}
}

Check warning on line 412 in Sources/Support/DebugUI/DebugContentViews.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Support/DebugUI/DebugContentViews.swift#L395-L412

Added lines #L395 - L412 were not covered by tests

private var json: String {
return (try? self.paywall.prettyPrintedJSON) ?? ""
}

Check warning on line 416 in Sources/Support/DebugUI/DebugContentViews.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Support/DebugUI/DebugContentViews.swift#L414-L416

Added lines #L414 - L416 were not covered by tests

}

// MARK: - Transferable

@available(iOS 16.0, macOS 13.0, *)
extension DebugViewModel.Configuration: Transferable {

Expand All @@ -389,6 +433,21 @@ extension DebugViewModel.Configuration: Transferable {

}

@available(iOS 16.0, macOS 13.0, *)
extension PaywallData: Transferable {

// swiftlint:disable:next missing_docs
public static var transferRepresentation: some TransferRepresentation {
return CodableRepresentation(
for: PaywallData.self,
contentType: .plainText,
encoder: JSONEncoder.prettyPrinted,
decoder: JSONDecoder.default
)
}

Check warning on line 447 in Sources/Support/DebugUI/DebugContentViews.swift

View check run for this annotation

Codecov / codecov/patch

Sources/Support/DebugUI/DebugContentViews.swift#L440-L447

Added lines #L440 - L447 were not covered by tests

}

#if swift(>=5.9)
@available(iOS 17.0, macOS 14.0, *)
private struct ProductStyle: ProductViewStyle {
Expand Down

0 comments on commit cddeb95

Please sign in to comment.