Skip to content

Commit

Permalink
Paywalls: fixed IntroEligibilityViewModel data lifetime (#3194)
Browse files Browse the repository at this point in the history
Follow up to #3187.
Thanks to @charliemchapman for reporting.

`IntroEligibilityViewModel` was being recreated, which meant that we
were losing the internal state on redraws.

I've also simplified the initialization of
`TrialOrIntroEligibilityChecker` and `PurchaseHandler` to avoid
duplicated calls to `.default()`.
  • Loading branch information
NachoSoto committed Sep 15, 2023
1 parent 4fa8c61 commit 8efdf57
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
20 changes: 10 additions & 10 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public struct PaywallView: View {
offering: nil,
customerInfo: nil,
fonts: fonts,
introEligibility: .default(),
purchaseHandler: .default()
introEligibility: nil,
purchaseHandler: nil
)
}

Expand All @@ -69,8 +69,8 @@ public struct PaywallView: View {
offering: offering,
customerInfo: nil,
fonts: fonts,
introEligibility: .default(),
purchaseHandler: .default()
introEligibility: nil,
purchaseHandler: nil
)
}

Expand All @@ -79,13 +79,13 @@ public struct PaywallView: View {
customerInfo: CustomerInfo?,
mode: PaywallViewMode = .default,
fonts: PaywallFontProvider = DefaultPaywallFontProvider(),
introEligibility: TrialOrIntroEligibilityChecker,
purchaseHandler: PurchaseHandler
introEligibility: TrialOrIntroEligibilityChecker?,
purchaseHandler: PurchaseHandler?
) {
self._offering = .init(initialValue: offering)
self._customerInfo = .init(initialValue: customerInfo)
self._introEligibility = .init(wrappedValue: introEligibility)
self._purchaseHandler = .init(wrappedValue: purchaseHandler)
self._introEligibility = .init(wrappedValue: introEligibility ?? .default())
self._purchaseHandler = .init(wrappedValue: purchaseHandler ?? .default())
self.mode = mode
self.fonts = fonts
}
Expand Down Expand Up @@ -187,7 +187,7 @@ struct LoadedOfferingPaywallView: View {
private let mode: PaywallViewMode
private let fonts: PaywallFontProvider

@ObservedObject
@StateObject
private var introEligibility: IntroEligibilityViewModel
@ObservedObject
private var purchaseHandler: PurchaseHandler
Expand All @@ -212,7 +212,7 @@ struct LoadedOfferingPaywallView: View {
self.mode = mode
self.fonts = fonts
self._introEligibility = .init(
initialValue: .init(introEligibilityChecker: introEligibility)
wrappedValue: .init(introEligibilityChecker: introEligibility)
)
self._purchaseHandler = .init(initialValue: purchaseHandler)
}
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/View+PresentPaywall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ private struct PresentingPaywallModifier: ViewModifier {
offering: self.offering,
customerInfo: data.customerInfo,
fonts: self.fontProvider,
introEligibility: self.introEligibility ?? .default(),
purchaseHandler: self.purchaseHandler ?? .default()
introEligibility: self.introEligibility,
purchaseHandler: self.purchaseHandler
)
.onPurchaseCompleted {
self.purchaseCompleted?($0)
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/View+PresentPaywallFooter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ private struct PresentingPaywallFooterModifier: ViewModifier {
customerInfo: self.customerInfo,
mode: self.condensed ? .condensedFooter : .footer,
fonts: self.fontProvider,
introEligibility: self.introEligibility ?? .default(),
purchaseHandler: self.purchaseHandler ?? .default()
introEligibility: self.introEligibility,
purchaseHandler: self.purchaseHandler
)
.onPurchaseCompleted {
self.purchaseCompleted?($0)
Expand Down

0 comments on commit 8efdf57

Please sign in to comment.