Skip to content

Commit

Permalink
[Paywalls V2] Use V1 default paywall when footers are used with V2 pa…
Browse files Browse the repository at this point in the history
…ywalls (#4667)

* Start of some fallback fixes

* Better fallback paywall stuff

* Use default v1 footers for v2 footers

* This feels better

* Link

* Undid this
  • Loading branch information
joshdholtz authored Jan 15, 2025
1 parent 4413503 commit 6f82e59
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 39 deletions.
81 changes: 51 additions & 30 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -255,39 +255,60 @@ public struct PaywallView: View {

#if PAYWALL_COMPONENTS
if let paywallComponents = offering.paywallComponents {
// For fallback view

// For fallback view or footer
let paywall: PaywallData = .createDefault(with: offering.availablePackages,
locale: self.locale)
let paywallView = LoadedOfferingPaywallView(
offering: offering,
activelySubscribedProductIdentifiers: activelySubscribedProductIdentifiers,
paywall: paywall,
template: PaywallData.defaultTemplate,
mode: self.mode,
fonts: fonts,
displayCloseButton: self.displayCloseButton,
introEligibility: checker,
purchaseHandler: purchaseHandler,
locale: self.locale,
showZeroDecimalPlacePrices: showZeroDecimalPlacePrices
)

PaywallsV2View(
paywallComponents: paywallComponents,
offering: offering,
introEligibilityChecker: .default(),
showZeroDecimalPlacePrices: showZeroDecimalPlacePrices,
onDismiss: {
guard let onRequestedDismissal = self.onRequestedDismissal else {
self.dismiss()
return
}
onRequestedDismissal()
},
fallbackView: paywallView
)
.environmentObject(self.introEligibility)
.environmentObject(self.purchaseHandler)
switch self.mode {
// Show the default/fallback paywall for Paywalls V2 footer views
case .footer, .condensedFooter:
LoadedOfferingPaywallView(
offering: offering,
activelySubscribedProductIdentifiers: activelySubscribedProductIdentifiers,
paywall: paywall,
template: PaywallData.defaultTemplate,
mode: self.mode,
fonts: fonts,
displayCloseButton: self.displayCloseButton,
introEligibility: checker,
purchaseHandler: purchaseHandler,
locale: locale,
showZeroDecimalPlacePrices: showZeroDecimalPlacePrices
)
// Show the actually V2 paywall for full screen
case .fullScreen:
let dataForV1DefaultPaywall = DataForV1DefaultPaywall(
offering: offering,
activelySubscribedProductIdentifiers: activelySubscribedProductIdentifiers,
paywall: paywall,
template: PaywallData.defaultTemplate,
mode: self.mode,
fonts: fonts,
displayCloseButton: self.displayCloseButton,
introEligibility: checker,
purchaseHandler: purchaseHandler,
locale: self.locale,
showZeroDecimalPlacePrices: showZeroDecimalPlacePrices
)

PaywallsV2View(
paywallComponents: paywallComponents,
offering: offering,
introEligibilityChecker: .default(),
showZeroDecimalPlacePrices: showZeroDecimalPlacePrices,
onDismiss: {
guard let onRequestedDismissal = self.onRequestedDismissal else {
self.dismiss()
return
}
onRequestedDismissal()
},
fallbackContent: .paywallV1View(dataForV1DefaultPaywall)
)
.environmentObject(self.introEligibility)
.environmentObject(self.purchaseHandler)
}
} else {

let (paywall, displayedLocale, template, error) = offering.validatedPaywall(locale: self.locale)
Expand Down
57 changes: 51 additions & 6 deletions RevenueCatUI/Templates/V2/PaywallsV2View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//
// Created by Josh Holtz on 6/11/24.
//
// swiftlint:disable missing_docs
// swiftlint:disable missing_docs file_length

import RevenueCat
import SwiftUI
Expand Down Expand Up @@ -32,7 +32,52 @@ private struct PaywallState {
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct PaywallsV2View<Content: View>: View {
struct DataForV1DefaultPaywall {

let offering: Offering
let activelySubscribedProductIdentifiers: Set<String>
let paywall: PaywallData
let template: PaywallTemplate
let mode: PaywallViewMode
let fonts: PaywallFontProvider
let displayCloseButton: Bool
let introEligibility: TrialOrIntroEligibilityChecker
let purchaseHandler: PurchaseHandler
let locale: Locale
let showZeroDecimalPlacePrices: Bool

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
enum FallbackContent {
case paywallV1View(DataForV1DefaultPaywall)
case customView(AnyView)

@ViewBuilder
func view() -> some View {
switch self {
case .paywallV1View(let data):
LoadedOfferingPaywallView(
offering: data.offering,
activelySubscribedProductIdentifiers: data.activelySubscribedProductIdentifiers,
paywall: data.paywall,
template: data.template,
mode: data.mode,
fonts: data.fonts,
displayCloseButton: data.displayCloseButton,
introEligibility: data.introEligibility,
purchaseHandler: data.purchaseHandler,
locale: data.locale,
showZeroDecimalPlacePrices: data.showZeroDecimalPlacePrices
)
case .customView(let view):
view
}
}
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
struct PaywallsV2View: View {

@Environment(\.horizontalSizeClass)
private var horizontalSizeClass
Expand All @@ -53,23 +98,23 @@ struct PaywallsV2View<Content: View>: View {
private let uiConfigProvider: UIConfigProvider
private let offering: Offering
private let onDismiss: () -> Void
private let fallbackView: Content
private let fallbackContent: FallbackContent

public init(
paywallComponents: Offering.PaywallComponents,
offering: Offering,
introEligibilityChecker: TrialOrIntroEligibilityChecker,
showZeroDecimalPlacePrices: Bool,
onDismiss: @escaping () -> Void,
fallbackView: Content
fallbackContent: FallbackContent
) {
let uiConfigProvider = UIConfigProvider(uiConfig: paywallComponents.uiConfig)

self.fallbackView = fallbackView
self.paywallComponentsData = paywallComponents.data
self.uiConfigProvider = uiConfigProvider
self.offering = offering
self.onDismiss = onDismiss
self.fallbackContent = fallbackContent
self._introOfferEligibilityContext = .init(
wrappedValue: .init(introEligibilityChecker: introEligibilityChecker)
)
Expand Down Expand Up @@ -148,7 +193,7 @@ struct PaywallsV2View<Content: View>: View {

DebugErrorView(
fullMessage,
replacement: self.fallbackView
replacement: self.fallbackContent.view()
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ struct FamilySharingTogglePreview_Previews: PreviewProvider {
introEligibilityChecker: .default(),
showZeroDecimalPlacePrices: true,
onDismiss: { },
fallbackView: EmptyView()
fallbackContent: .customView(AnyView(Text("Fallback paywall")))
)
.previewRequiredEnvironmentProperties()
.previewLayout(.fixed(width: 400, height: 800))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ struct MultiTierPreview_Previews: PreviewProvider {
introEligibilityChecker: .default(),
showZeroDecimalPlacePrices: true,
onDismiss: { },
fallbackView: EmptyView()
fallbackContent: .customView(AnyView(Text("Fallback paywall")))
)
.previewRequiredEnvironmentProperties()
.previewLayout(.fixed(width: 400, height: 800))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ struct Template1Preview_Previews: PreviewProvider {
introEligibilityChecker: .default(),
showZeroDecimalPlacePrices: true,
onDismiss: { },
fallbackView: EmptyView()
fallbackContent: .customView(AnyView(Text("Fallback paywall")))
)
.previewRequiredEnvironmentProperties()
.previewLayout(.fixed(width: 400, height: 800))
Expand Down

0 comments on commit 6f82e59

Please sign in to comment.