Skip to content

Commit

Permalink
Paywalls: changed default PaywallData to display available packag…
Browse files Browse the repository at this point in the history
…es (#2964)

Currently it was doing a best effort and showing
`weekly`/`monthly`/`annual` if those existed in the offering. This makes
it so it doesn't have to guess, and it creates a `Paywall` using the
`availablePackages`.
  • Loading branch information
NachoSoto committed Aug 31, 2023
1 parent 879f955 commit 9a815a7
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
40 changes: 23 additions & 17 deletions RevenueCatUI/Helpers/PaywallData+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@ extension PaywallData {

/// Default `PaywallData` to display when attempting to present a ``PaywallView`` with an offering
/// that has no paywall configuration, or when that configuration is invalid.
public static let `default`: Self = .init(
template: .multiPackageBold,
config: .init(
packages: [
Package.string(from: .weekly)!,
Package.string(from: .monthly)!,
Package.string(from: .annual)!
],
images: .init(background: Self.backgroundImage),
colors: Self.colors,
blurredBackgroundImage: true,
displayRestorePurchases: true
),
localization: Self.localization,
assetBaseURL: Self.defaultTemplateBaseURL
)
static func createDefault(with packages: [Package]) -> Self {
return self.createDefault(with: packages.map(\.identifier))
}

static func createDefault(with packageIdentifiers: [String]) -> Self {
return .init(
template: .multiPackageBold,
config: .init(
packages: packageIdentifiers,
images: .init(background: Self.backgroundImage),
colors: Self.colors,
blurredBackgroundImage: true,
displayRestorePurchases: true
),
localization: Self.localization,
assetBaseURL: Self.defaultTemplateBaseURL
)
}

}

Expand Down Expand Up @@ -91,7 +93,11 @@ struct DefaultPaywall_Previews: PreviewProvider {
identifier: "offering",
serverDescription: "Main offering",
metadata: [:],
paywall: .default,
paywall: .createDefault(with: [
TestData.weeklyPackage,
TestData.monthlyPackage,
TestData.annualPackage
]),
availablePackages: TestData.packages
)

Expand Down
6 changes: 3 additions & 3 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public struct PaywallView: View {
LoadedOfferingPaywallView(
offering: offering,
paywall: paywall,
mode: mode,
mode: self.mode,
introEligibility: checker,
purchaseHandler: purchaseHandler
)
Expand All @@ -121,8 +121,8 @@ public struct PaywallView: View {
AnyView(
LoadedOfferingPaywallView(
offering: offering,
paywall: .default,
mode: mode,
paywall: .createDefault(with: offering.availablePackages),
mode: self.mode,
introEligibility: checker,
purchaseHandler: purchaseHandler
)
Expand Down
18 changes: 11 additions & 7 deletions RevenueCatUI/Views/LoadingPaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,10 @@ struct LoadingPaywallView: View {
identifier: Self.offeringIdentifier,
serverDescription: "",
metadata: [:],
paywall: .default,
availablePackages: [
Self.monthlyPackage,
Self.weeklyPackage,
Self.annualPackage
]
paywall: Self.defaultPaywall,
availablePackages: Self.packages
),
paywall: .default,
paywall: Self.defaultPaywall,
mode: .fullScreen,
introEligibility: Self.introEligibility,
purchaseHandler: Self.purchaseHandler
Expand All @@ -37,6 +33,14 @@ struct LoadingPaywallView: View {
.redacted(reason: .placeholder)
}

private static let defaultPaywall: PaywallData = .createDefault(with: Self.packages)

private static let packages: [Package] = [
Self.monthlyPackage,
Self.weeklyPackage,
Self.annualPackage
]

}

@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
Expand Down

0 comments on commit 9a815a7

Please sign in to comment.