From 10547027d8ed7968e7c83c44c73799fe1a516c0f Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Fri, 28 Jul 2023 00:14:23 +0200 Subject: [PATCH] `Paywalls`: changed `subtitle` to be optional (#2900) Not all templates require it, so it's optional from here on. --- RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift | 6 +++--- RevenueCatUI/Templates/MultiPackageBoldTemplate.swift | 2 +- RevenueCatUI/Templates/SinglePackageStandardTemplate.swift | 4 ++-- Sources/Paywalls/PaywallData.swift | 6 +++--- .../SwiftAPITester/SwiftAPITester/PaywallAPI.swift | 2 +- .../UnitTests/Networking/Responses/Fixtures/Offerings.json | 1 - .../Networking/Responses/Fixtures/PaywallData-Sample1.json | 1 - .../Networking/Responses/OfferingsDecodingTests.swift | 2 +- Tests/UnitTests/Paywalls/PaywallDataTests.swift | 2 +- 9 files changed, 12 insertions(+), 14 deletions(-) diff --git a/RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift b/RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift index 5f5e7878fd..e477cbdd75 100644 --- a/RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift +++ b/RevenueCatUI/Data/ProcessedLocalizedConfiguration.swift @@ -8,7 +8,7 @@ struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration { typealias Feature = PaywallData.LocalizedConfiguration.Feature var title: String - var subtitle: String + var subtitle: String? var callToAction: String var callToActionWithIntroOffer: String? var offerDetails: String @@ -23,7 +23,7 @@ struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration { ) { self.init( title: configuration.title.processed(with: dataProvider, locale: locale), - subtitle: configuration.subtitle.processed(with: dataProvider, locale: locale), + subtitle: configuration.subtitle?.processed(with: dataProvider, locale: locale), callToAction: configuration.callToAction.processed(with: dataProvider, locale: locale), callToActionWithIntroOffer: configuration.callToActionWithIntroOffer?.processed(with: dataProvider, locale: locale), @@ -41,7 +41,7 @@ struct ProcessedLocalizedConfiguration: PaywallLocalizedConfiguration { private init( title: String, - subtitle: String, + subtitle: String?, callToAction: String, callToActionWithIntroOffer: String?, offerDetails: String, diff --git a/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift b/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift index 324efba430..a0dcd6cacd 100644 --- a/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift +++ b/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift @@ -102,7 +102,7 @@ private struct MultiPackageTemplateContent: View { Spacer() - Text(self.selectedLocalization.subtitle) + Text(self.selectedLocalization.subtitle ?? "") .font(.title2) Spacer() diff --git a/RevenueCatUI/Templates/SinglePackageStandardTemplate.swift b/RevenueCatUI/Templates/SinglePackageStandardTemplate.swift index dd0a3b9709..e3eb4c1d5b 100644 --- a/RevenueCatUI/Templates/SinglePackageStandardTemplate.swift +++ b/RevenueCatUI/Templates/SinglePackageStandardTemplate.swift @@ -63,8 +63,8 @@ private struct SinglePackageTemplateContent: View { : [] ) - if self.configuration.mode.displaySubtitle { - Text(verbatim: self.localization.subtitle) + if self.configuration.mode.displaySubtitle, let subtitle = self.localization.subtitle { + Text(verbatim: subtitle) .font(self.configuration.mode.subtitleFont) } } diff --git a/Sources/Paywalls/PaywallData.swift b/Sources/Paywalls/PaywallData.swift index f7a45cb624..5f248c3dd0 100644 --- a/Sources/Paywalls/PaywallData.swift +++ b/Sources/Paywalls/PaywallData.swift @@ -39,7 +39,7 @@ public protocol PaywallLocalizedConfiguration { /// The title of the paywall screen. var title: String { get } /// The subtitle of the paywall screen. - var subtitle: String { get } + var subtitle: String? { get } /// The content of the main action button for purchasing a subscription. var callToAction: String { get } /// The content of the main action button for purchasing a subscription when an intro offer is available. @@ -66,7 +66,7 @@ extension PaywallData { // swiftlint:disable missing_docs public var title: String - public var subtitle: String + public var subtitle: String? public var callToAction: String public var offerDetails: String public var offerName: String? @@ -92,7 +92,7 @@ extension PaywallData { public init( title: String, - subtitle: String, + subtitle: String? = nil, callToAction: String, callToActionWithIntroOffer: String? = nil, offerDetails: String, diff --git a/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift b/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift index 498d24e764..fa7dc49714 100644 --- a/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift +++ b/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift @@ -52,7 +52,7 @@ func checkPaywallConfiguration(_ config: PaywallData.Configuration, func checkPaywallLocalizedConfig(_ config: PaywallData.LocalizedConfiguration) { let title: String = config.title - let subtitle: String = config.subtitle + let subtitle: String? = config.subtitle let callToAction: String = config.callToAction let callToActionWithIntroOffer: String? = config.callToActionWithIntroOffer let offerDetails: String = config.offerDetails diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json b/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json index 8873678256..e851952b0b 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json @@ -58,7 +58,6 @@ }, "es_ES": { "title": "Tienda", - "subtitle": "Descripción", "call_to_action": "Comprar", "call_to_action_with_intro_offer": "Comprar", "offer_details": "{{ price_per_month }} cada mes", diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json index 230fb6d756..6c2c52fa77 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json @@ -24,7 +24,6 @@ }, "es_ES": { "title": "Tienda", - "subtitle": "Descripción", "call_to_action": "Comprar", "offer_details": "{{ price_per_month }} cada mes", "offer_details_with_intro_offer": " ", diff --git a/Tests/UnitTests/Networking/Responses/OfferingsDecodingTests.swift b/Tests/UnitTests/Networking/Responses/OfferingsDecodingTests.swift index 10ff0a6083..6dc616ddbb 100644 --- a/Tests/UnitTests/Networking/Responses/OfferingsDecodingTests.swift +++ b/Tests/UnitTests/Networking/Responses/OfferingsDecodingTests.swift @@ -133,7 +133,7 @@ class OfferingsDecodingTests: BaseHTTPResponseTest { let esConfig = try XCTUnwrap(paywall.config(for: Locale(identifier: "es_ES"))) expect(esConfig.title) == "Tienda" - expect(esConfig.subtitle) == "Descripción" + expect(esConfig.subtitle).to(beNil()) expect(esConfig.callToAction) == "Comprar" expect(esConfig.callToActionWithIntroOffer) == "Comprar" expect(esConfig.offerDetails) == "{{ price_per_month }} cada mes" diff --git a/Tests/UnitTests/Paywalls/PaywallDataTests.swift b/Tests/UnitTests/Paywalls/PaywallDataTests.swift index 4779c2e14a..3029a3c403 100644 --- a/Tests/UnitTests/Paywalls/PaywallDataTests.swift +++ b/Tests/UnitTests/Paywalls/PaywallDataTests.swift @@ -74,7 +74,7 @@ class PaywallDataTests: BaseHTTPResponseTest { let esConfig = try XCTUnwrap(paywall.config(for: Locale(identifier: "es_ES"))) expect(esConfig.title) == "Tienda" - expect(esConfig.subtitle) == "Descripción" + expect(esConfig.subtitle).to(beNil()) expect(esConfig.callToAction) == "Comprar" expect(esConfig.callToActionWithIntroOffer).to(beNil()) expect(esConfig.offerDetails) == "{{ price_per_month }} cada mes"