Skip to content

Commit

Permalink
Paywalls: added default template to SamplePaywallsList (#2928)
Browse files Browse the repository at this point in the history
This allows debugging the default template.

![Simulator Screenshot - iPhone 14 Pro - 2023-07-31 at 13 05
39](https://github.com/RevenueCat/purchases-ios/assets/685609/bb683d5d-31c1-402d-9213-064fd13071d6)
  • Loading branch information
NachoSoto committed Sep 8, 2023
1 parent f5be297 commit 9809bc8
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
10 changes: 10 additions & 0 deletions Tests/TestingApps/SimpleApp/SimpleApp/SamplePaywalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ final class SamplePaywallLoader {
)
}

func offeringWithDefaultPaywall() -> Offering {
return .init(
identifier: Self.offeringIdentifier,
serverDescription: Self.offeringIdentifier,
metadata: [:],
paywall: nil,
availablePackages: self.packages
)
}

private func paywall(for template: PaywallTemplate) -> PaywallData {
switch template {
case .onePackageStandard:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct SamplePaywallsList: View {
private var loader: Result<SamplePaywallLoader, NSError>?

@State
private var selectedTemplate: PaywallTemplate?
private var display: Display?

var body: some View {
self.content
Expand All @@ -35,8 +35,13 @@ struct SamplePaywallsList: View {
switch self.loader {
case let .success(loader):
self.list(with: loader)
.sheet(item: self.$selectedTemplate) { template in
PaywallView(offering: loader.offering(for: template))
.sheet(item: self.$display) { display in
switch display {
case let .template(template):
PaywallView(offering: loader.offering(for: template))
case .defaultTemplate:
PaywallView(offering: loader.offeringWithDefaultPaywall())
}
}

case let .failure(error):
Expand All @@ -52,26 +57,61 @@ struct SamplePaywallsList: View {
Section("Templates") {
ForEach(PaywallTemplate.allCases, id: \.rawValue) { template in
Button {
self.selectedTemplate = template
self.display = .template(template)
} label: {
Text(template.name)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
TemplateLabel(name: template.name)
}
.buttonStyle(.plain)
}
}

Section("Other") {
Button {
self.display = .defaultTemplate
} label: {
TemplateLabel(name: "Default template")
}
}
}
.frame(maxWidth: .infinity)
.buttonStyle(.plain)
}

}

private struct TemplateLabel: View {

var name: String

var body: some View {
Text(self.name)
.frame(maxWidth: .infinity, alignment: .leading)
.contentShape(Rectangle())
}

}

// MARK: -

extension PaywallTemplate: Identifiable {
private extension SamplePaywallsList {

enum Display {

case template(PaywallTemplate)
case defaultTemplate

}

}

extension SamplePaywallsList.Display: Identifiable {

public var id: String {
return self.rawValue
switch self {
case let .template(template):
return template.rawValue
case .defaultTemplate:
return "default"
}
}

}
Expand Down

0 comments on commit 9809bc8

Please sign in to comment.