Skip to content

Commit

Permalink
Paywalls: avoid flickering when displaying paywalls with available …
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto authored Oct 9, 2023
1 parent ceae31f commit cc6c846
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,14 @@ public struct PaywallView: View {
introEligibility: TrialOrIntroEligibilityChecker?,
purchaseHandler: PurchaseHandler?
) {
self._offering = .init(initialValue: offering)
self._customerInfo = .init(initialValue: customerInfo)
self._introEligibility = .init(wrappedValue: introEligibility ?? .default())
self._purchaseHandler = .init(wrappedValue: purchaseHandler ?? .default())
self._offering = .init(
initialValue: offering ?? Self.loadCachedCurrentOfferingIfPossible()
)
self._customerInfo = .init(
initialValue: customerInfo ?? Self.loadCachedCustomerInfoIfPossible()
)
self.mode = mode
self.fonts = fonts
}
Expand Down Expand Up @@ -176,6 +180,32 @@ public struct PaywallView: View {

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
private extension PaywallView {

static func loadCachedCustomerInfoIfPossible() -> CustomerInfo? {
if Purchases.isConfigured {
return Purchases.shared.cachedCustomerInfo
} else {
return nil
}
}

static func loadCachedCurrentOfferingIfPossible() -> Offering? {
if Purchases.isConfigured {
return Purchases.shared.cachedOfferings?.current
} else {
return nil
}
}

}

// MARK: -

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
@available(tvOS, unavailable)
struct LoadedOfferingPaywallView: View {
Expand Down Expand Up @@ -357,19 +387,4 @@ private extension PaywallViewMode {

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
private extension PaywallTemplate {

var name: String {
switch self {
case .template1: return "Minimalist"
case .template2: return "Bold Packages"
case .template3: return "Feature List"
case .template4: return "Horizontal"
case .template5: return "Small Banner"
}
}

}

#endif

0 comments on commit cc6c846

Please sign in to comment.