From dde5daf00891896d803deb860575a9e0337941c7 Mon Sep 17 00:00:00 2001 From: John Sundell Date: Wed, 2 Oct 2024 14:57:49 +0200 Subject: [PATCH] Add option to customize spacing applied to SwiftUI-based paywall footer This patch makes it possible for API users to customize the amount of spacing that's applied to a `PaywallView` when presented as a footer using the `paywallFooter` SwiftUI modifier. That API uses SwiftUI's `safeAreaInset` modifier internally, which by default adds a system-defined amount of spacing between the view placed within the safe area inset and the host view that the modifier is applied to. With this change, API users are now free to remove or modify that spacing, which is required for certain app designs. This is a backward-compatible change, as the added `spacing` parameter is optional with a default value of `nil`, which retains the existing behavior when the new parameter isn't passed by the API user. --- RevenueCatUI/Data/PaywallViewConfiguration.swift | 3 +++ RevenueCatUI/View+PresentPaywallFooter.swift | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/RevenueCatUI/Data/PaywallViewConfiguration.swift b/RevenueCatUI/Data/PaywallViewConfiguration.swift index f29dfe6572..0a3a6bd62c 100644 --- a/RevenueCatUI/Data/PaywallViewConfiguration.swift +++ b/RevenueCatUI/Data/PaywallViewConfiguration.swift @@ -18,6 +18,7 @@ struct PaywallViewConfiguration { var customerInfo: CustomerInfo? var mode: PaywallViewMode var fonts: PaywallFontProvider + var spacing: CGFloat? var displayCloseButton: Bool var introEligibility: TrialOrIntroEligibilityChecker? var purchaseHandler: PurchaseHandler @@ -28,6 +29,7 @@ struct PaywallViewConfiguration { customerInfo: CustomerInfo? = nil, mode: PaywallViewMode = .default, fonts: PaywallFontProvider = DefaultPaywallFontProvider(), + spacing: CGFloat? = nil, displayCloseButton: Bool = false, introEligibility: TrialOrIntroEligibilityChecker? = nil, purchaseHandler: PurchaseHandler, @@ -37,6 +39,7 @@ struct PaywallViewConfiguration { self.customerInfo = customerInfo self.mode = mode self.fonts = fonts + self.spacing = spacing self.displayCloseButton = displayCloseButton self.introEligibility = introEligibility self.purchaseHandler = purchaseHandler diff --git a/RevenueCatUI/View+PresentPaywallFooter.swift b/RevenueCatUI/View+PresentPaywallFooter.swift index 8e23ca9c5d..270514673d 100644 --- a/RevenueCatUI/View+PresentPaywallFooter.swift +++ b/RevenueCatUI/View+PresentPaywallFooter.swift @@ -81,6 +81,7 @@ extension View { public func paywallFooter( condensed: Bool = false, fonts: PaywallFontProvider = DefaultPaywallFontProvider(), + spacing: CGFloat? = nil, myAppPurchaseLogic: MyAppPurchaseLogic? = nil, purchaseStarted: PurchaseOfPackageStartedHandler? = nil, purchaseCompleted: PurchaseOrRestoreCompletedHandler? = nil, @@ -97,6 +98,7 @@ extension View { customerInfo: nil, condensed: condensed, fonts: fonts, + spacing: spacing, introEligibility: nil, purchaseHandler: purchaseHandler, purchaseStarted: purchaseStarted, @@ -206,6 +208,7 @@ extension View { customerInfo: CustomerInfo?, condensed: Bool = false, fonts: PaywallFontProvider = DefaultPaywallFontProvider(), + spacing: CGFloat? = nil, introEligibility: TrialOrIntroEligibilityChecker? = nil, purchaseHandler: PurchaseHandler, purchaseStarted: PurchaseOfPackageStartedHandler? = nil, @@ -224,6 +227,7 @@ extension View { customerInfo: customerInfo, mode: condensed ? .condensedFooter : .footer, fonts: fonts, + spacing: spacing, displayCloseButton: false, introEligibility: introEligibility, purchaseHandler: purchaseHandler @@ -267,7 +271,7 @@ private struct PresentingPaywallFooterModifier: ViewModifier { func body(content: Content) -> some View { content - .safeAreaInset(edge: .bottom) { + .safeAreaInset(edge: .bottom, spacing: configuration.spacing) { PaywallView(configuration: self.configuration) .onPurchaseStarted { self.purchaseStarted?($0)