From 0f137ae229375cc7325ea87510e81cb079f604a2 Mon Sep 17 00:00:00 2001 From: NachoSoto Date: Fri, 28 Jul 2023 00:40:13 +0200 Subject: [PATCH] `Paywalls`: new `text1` and `text2` colors (#2903) `foreground` becomes `text1`, allowing us to keep growing that list just like accents. `accent1` is now also optional. --- RevenueCatUI/Data/TestData.swift | 12 +++++++----- .../Helpers/ColorInformation+MultiScheme.swift | 8 +++++--- RevenueCatUI/Helpers/PaywallData+Default.swift | 4 ++-- .../Templates/MultiPackageBoldTemplate.swift | 6 +++--- .../Templates/OnePackageStandardTemplate.swift | 4 ++-- .../OnePackageWithFeaturesTemplate.swift | 4 ++-- RevenueCatUI/Views/FooterView.swift | 2 +- Sources/Paywalls/PaywallData.swift | 16 ++++++++++------ .../SwiftAPITester/PaywallAPI.swift | 8 +++++--- .../SimpleApp/SimpleApp/SamplePaywalls.swift | 10 +++++----- .../Networking/Responses/Fixtures/Offerings.json | 2 +- .../Responses/Fixtures/PaywallData-Sample1.json | 5 +++-- ...lData-missing_current_and_default_locale.json | 2 +- .../PaywallData-missing_current_locale.json | 2 +- Tests/UnitTests/Paywalls/PaywallDataTests.swift | 10 ++++++---- 15 files changed, 54 insertions(+), 41 deletions(-) diff --git a/RevenueCatUI/Data/TestData.swift b/RevenueCatUI/Data/TestData.swift index 7c8c643a1f..f97fc67fee 100644 --- a/RevenueCatUI/Data/TestData.swift +++ b/RevenueCatUI/Data/TestData.swift @@ -167,14 +167,14 @@ internal enum TestData { colors: .init( light: .init( background: "#FFFFFF", - foreground: "#000000", + text1: "#000000", callToActionBackground: "#EC807C", callToActionForeground: "#FFFFFF", accent1: "#BC66FF" ), dark: .init( background: "#000000", - foreground: "#FFFFFF", + text1: "#FFFFFF", callToActionBackground: "#ACD27A", callToActionForeground: "#000000", accent1: "#B022BB" @@ -204,7 +204,7 @@ internal enum TestData { colors: .init( light: .init( background: "#272727", - foreground: "#FFFFFF", + text1: "#FFFFFF", callToActionBackground: "#FFFFFF", callToActionForeground: "#000000", accent1: "#F4E971", @@ -240,7 +240,8 @@ internal enum TestData { static let lightColors: PaywallData.Configuration.Colors = .init( background: "#FFFFFF", - foreground: "#000000", + text1: "#000000", + text2: "#B2B2B2", callToActionBackground: "#5CD27A", callToActionForeground: "#FFFFFF", accent1: "#BC66FF", @@ -248,7 +249,8 @@ internal enum TestData { ) static let darkColors: PaywallData.Configuration.Colors = .init( background: "#000000", - foreground: "#FFFFFF", + text1: "#FFFFFF", + text2: "#B2B2B2", callToActionBackground: "#ACD27A", callToActionForeground: "#000000", accent1: "#B022BB", diff --git a/RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift b/RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift index fb7b43d11c..6dd2415806 100644 --- a/RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift +++ b/RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift @@ -32,7 +32,8 @@ extension PaywallData.Configuration.Colors { static func combine(light: Self, dark: Self) -> Self { return .init( background: .init(light: light.background, dark: dark.background), - foreground: .init(light: light.foreground, dark: dark.foreground), + text1: .init(light: light.text1, dark: dark.text1), + text2: .init(light: light.text2, dark: dark.text2), callToActionBackground: .init(light: light.callToActionBackground, dark: dark.callToActionBackground), callToActionForeground: .init(light: light.callToActionForeground, dark: dark.callToActionForeground), accent1: .init(light: light.accent1, dark: dark.accent1), @@ -77,10 +78,11 @@ import SwiftUI extension PaywallData.Configuration.Colors { var backgroundColor: Color { self.background.underlyingColor } - var foregroundColor: Color { self.foreground.underlyingColor } + var text1Color: Color { self.text1.underlyingColor } + var text2Color: Color { self.text2?.underlyingColor ?? self.text1.underlyingColor } var callToActionBackgroundColor: Color { self.callToActionBackground.underlyingColor } var callToActionForegroundColor: Color { self.callToActionForeground.underlyingColor } - var accent1Color: Color { self.accent1.underlyingColor } + var accent1Color: Color { self.accent1?.underlyingColor ?? self.callToActionForegroundColor } var accent2Color: Color { self.accent2?.underlyingColor ?? self.accent1Color } } diff --git a/RevenueCatUI/Helpers/PaywallData+Default.swift b/RevenueCatUI/Helpers/PaywallData+Default.swift index 9b160f0e29..c1a985128d 100644 --- a/RevenueCatUI/Helpers/PaywallData+Default.swift +++ b/RevenueCatUI/Helpers/PaywallData+Default.swift @@ -35,14 +35,14 @@ private extension PaywallData { static let colors: PaywallData.Configuration.ColorInformation = .init( light: .init( background: try! .init(stringRepresentation: "#FFFFFF"), - foreground: try! .init(stringRepresentation: "#000000"), + text1: try! .init(stringRepresentation: "#000000"), callToActionBackground: try! .init(stringRepresentation: "#EC807C"), callToActionForeground: try! .init(stringRepresentation: "#FFFFFF"), accent1: try! .init(stringRepresentation: "#EC807C") ), dark: .init( background: try! .init(stringRepresentation: "#000000"), - foreground: try! .init(stringRepresentation: "#FFFFFF"), + text1: try! .init(stringRepresentation: "#FFFFFF"), callToActionBackground: try! .init(stringRepresentation: "#ACD27A"), callToActionForeground: try! .init(stringRepresentation: "#000000"), accent1: try! .init(stringRepresentation: "#ACD27A") diff --git a/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift b/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift index 7cd1712030..3460cb19f9 100644 --- a/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift +++ b/RevenueCatUI/Templates/MultiPackageBoldTemplate.swift @@ -68,7 +68,7 @@ private struct MultiPackageTemplateContent: View { if case .fullScreen = self.configuration.mode { FooterView(configuration: self.configuration.configuration, - color: self.configuration.colors.foregroundColor, + color: self.configuration.colors.text1Color, purchaseHandler: self.purchaseHandler) } } @@ -149,13 +149,13 @@ private struct MultiPackageTemplateContent: View { .padding() .multilineTextAlignment(.leading) .frame(maxWidth: .infinity, alignment: alignment) - .foregroundColor(self.configuration.colors.foregroundColor) + .foregroundColor(self.configuration.colors.text1Color) .overlay { if selected { EmptyView() } else { RoundedRectangle(cornerRadius: Self.cornerRadius) - .stroke(self.configuration.colors.foregroundColor, lineWidth: 2) + .stroke(self.configuration.colors.text1Color, lineWidth: 2) } } .background { diff --git a/RevenueCatUI/Templates/OnePackageStandardTemplate.swift b/RevenueCatUI/Templates/OnePackageStandardTemplate.swift index 326eabbe78..41dea2d681 100644 --- a/RevenueCatUI/Templates/OnePackageStandardTemplate.swift +++ b/RevenueCatUI/Templates/OnePackageStandardTemplate.swift @@ -57,7 +57,7 @@ private struct OnePackageTemplateContent: View { } .padding(.horizontal) } - .foregroundColor(self.configuration.colors.foregroundColor) + .foregroundColor(self.configuration.colors.text1Color) .multilineTextAlignment(.center) .scrollable(if: self.configuration.mode.isFullScreen) .scrollContentBackground(.hidden) @@ -82,7 +82,7 @@ private struct OnePackageTemplateContent: View { if case .fullScreen = self.configuration.mode { FooterView(configuration: self.configuration.configuration, - color: self.configuration.colors.foregroundColor, + color: self.configuration.colors.text1Color, purchaseHandler: self.purchaseHandler) } } diff --git a/RevenueCatUI/Templates/OnePackageWithFeaturesTemplate.swift b/RevenueCatUI/Templates/OnePackageWithFeaturesTemplate.swift index d28de883cf..f3522bcf6a 100644 --- a/RevenueCatUI/Templates/OnePackageWithFeaturesTemplate.swift +++ b/RevenueCatUI/Templates/OnePackageWithFeaturesTemplate.swift @@ -62,7 +62,7 @@ private struct OnePackageWithFeaturesTemplateContent: View { Text(self.localization.title) .font(.title) - .foregroundStyle(self.configuration.colors.foregroundColor) + .foregroundStyle(self.configuration.colors.text1Color) .multilineTextAlignment(.center) Spacer() @@ -161,7 +161,7 @@ private struct FeatureView: View { } Text(self.feature.title) - .foregroundStyle(self.colors.foregroundColor) + .foregroundStyle(self.colors.text1Color) .font(.headline) .frame(maxWidth: .infinity, alignment: .leading) } diff --git a/RevenueCatUI/Views/FooterView.swift b/RevenueCatUI/Views/FooterView.swift index df769e031a..ad2a528963 100644 --- a/RevenueCatUI/Views/FooterView.swift +++ b/RevenueCatUI/Views/FooterView.swift @@ -168,7 +168,7 @@ struct Footer_Previews: PreviewProvider { termsOfServiceURL: termsOfServiceURL, privacyURL: privacyURL ), - color: TestData.colors.foregroundColor, + color: TestData.colors.text1Color, purchaseHandler: Self.handler ) } diff --git a/Sources/Paywalls/PaywallData.swift b/Sources/Paywalls/PaywallData.swift index 5f248c3dd0..90103cfbaf 100644 --- a/Sources/Paywalls/PaywallData.swift +++ b/Sources/Paywalls/PaywallData.swift @@ -303,28 +303,32 @@ extension PaywallData.Configuration { /// Color for the background of the paywall. public var background: PaywallColor - /// Color for foreground elements. - public var foreground: PaywallColor + /// Color for primary text element. + public var text1: PaywallColor + /// Color for secondary text element. + public var text2: PaywallColor? /// Background color of the main call to action button. public var callToActionBackground: PaywallColor /// Foreground color of the main call to action button. public var callToActionForeground: PaywallColor /// Primary accent color. - public var accent1: PaywallColor + public var accent1: PaywallColor? /// Secondary accent color public var accent2: PaywallColor? // swiftlint:disable:next missing_docs public init( background: PaywallColor, - foreground: PaywallColor, + text1: PaywallColor, + text2: PaywallColor? = nil, callToActionBackground: PaywallColor, callToActionForeground: PaywallColor, - accent1: PaywallColor, + accent1: PaywallColor? = nil, accent2: PaywallColor? = nil ) { self.background = background - self.foreground = foreground + self.text1 = text1 + self.text2 = text2 self.callToActionBackground = callToActionBackground self.callToActionForeground = callToActionForeground self.accent1 = accent1 diff --git a/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift b/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift index 69300749cc..775308d8e5 100644 --- a/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift +++ b/Tests/APITesters/SwiftAPITester/SwiftAPITester/PaywallAPI.swift @@ -98,15 +98,17 @@ func checkPaywallImages(_ images: PaywallData.Configuration.Images) { func checkPaywallColors(_ config: PaywallData.Configuration.Colors) { let background: PaywallColor = config.background - let foreground: PaywallColor = config.foreground + let text1: PaywallColor = config.text1 + let text2: PaywallColor? = config.text2 let callToActionBackground: PaywallColor = config.callToActionBackground let callToActionForeground: PaywallColor = config.callToActionForeground - let accent1: PaywallColor = config.accent1 + let accent1: PaywallColor? = config.accent1 let accent2: PaywallColor? = config.accent2 _ = PaywallData.Configuration.Colors( background: background, - foreground: foreground, + text1: text1, + text2: text2, callToActionBackground: callToActionBackground, callToActionForeground: callToActionForeground, accent1: accent1, diff --git a/Tests/TestingApps/SimpleApp/SimpleApp/SamplePaywalls.swift b/Tests/TestingApps/SimpleApp/SimpleApp/SamplePaywalls.swift index 6594d8d1be..2565010638 100644 --- a/Tests/TestingApps/SimpleApp/SimpleApp/SamplePaywalls.swift +++ b/Tests/TestingApps/SimpleApp/SimpleApp/SamplePaywalls.swift @@ -62,14 +62,14 @@ private extension SamplePaywallLoader { colors: .init( light: .init( background: "#FFFFFF", - foreground: "#000000", + text1: "#000000", callToActionBackground: "#5CD27A", callToActionForeground: "#FFFFFF", accent1: "#BC66FF" ), dark: .init( background: "#000000", - foreground: "#FFFFFF", + text1: "#FFFFFF", callToActionBackground: "#ACD27A", callToActionForeground: "#000000", accent1: "#B022BB" @@ -98,14 +98,14 @@ private extension SamplePaywallLoader { colors: .init( light: .init( background: "#FFFFFF", - foreground: "#000000", + text1: "#000000", callToActionBackground: "#EC807C", callToActionForeground: "#FFFFFF", accent1: "#BC66FF" ), dark: .init( background: "#000000", - foreground: "#FFFFFF", + text1: "#FFFFFF", callToActionBackground: "#ACD27A", callToActionForeground: "#000000", accent1: "#B022BB" @@ -135,7 +135,7 @@ private extension SamplePaywallLoader { colors: .init( light: .init( background: "#272727", - foreground: "#FFFFFF", + text1: "#FFFFFF", callToActionBackground: "#FFFFFF", callToActionForeground: "#000000", accent1: "#F4E971", diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json b/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json index e851952b0b..941bafd691 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/Offerings.json @@ -73,7 +73,7 @@ "colors": { "light": { "background": "#FF00AA", - "foreground": "#FF00AA22", + "text_1": "#FF00AA22", "call_to_action_background": "#FF00AACC", "call_to_action_foreground": "#FF00AA", "accent_1": "#FF0000" diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json index 6c2c52fa77..faeea1ee8e 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-Sample1.json @@ -53,7 +53,8 @@ "colors": { "light": { "background": "#FF00AA", - "foreground": "#FF00AA22", + "text_1": "#FF00AA22", + "text_2": "#FF00AA11", "call_to_action_background": "#FF00AACC", "call_to_action_foreground": "#FF00AA", "accent_1": "#FF0000", @@ -61,7 +62,7 @@ }, "dark": { "background": "#FF0000", - "foreground": "#1100FFAA", + "text_1": "#FF0011", "call_to_action_background": "#112233AA", "call_to_action_foreground": "#AABBCC", "accent_1": "#00FFFF", diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_and_default_locale.json b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_and_default_locale.json index c2d4cc815b..74946fc5bf 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_and_default_locale.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_and_default_locale.json @@ -17,7 +17,7 @@ "colors": { "light": { "background": "#FFFFFF", - "foreground": "#FFFFFF", + "text_1": "#FFFFFF", "call_to_action_background": "#FFFFFF", "call_to_action_foreground": "#FFFFFF", "accent_1": "#FFFFFF" diff --git a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json index cf33db9ff2..142863a554 100644 --- a/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json +++ b/Tests/UnitTests/Networking/Responses/Fixtures/PaywallData-missing_current_locale.json @@ -17,7 +17,7 @@ "colors": { "light": { "background": "#FFFFFF", - "foreground": "#FFFFFF", + "text_1": "#FFFFFF", "call_to_action_background": "#FFFFFF", "call_to_action_foreground": "#FFFFFF", "accent_1": "#FFFFFF" diff --git a/Tests/UnitTests/Paywalls/PaywallDataTests.swift b/Tests/UnitTests/Paywalls/PaywallDataTests.swift index 3029a3c403..ca8fec10ce 100644 --- a/Tests/UnitTests/Paywalls/PaywallDataTests.swift +++ b/Tests/UnitTests/Paywalls/PaywallDataTests.swift @@ -45,17 +45,19 @@ class PaywallDataTests: BaseHTTPResponseTest { expect(paywall.config.privacyURL) == URL(string: "https://revenuecat.com/privacy")! expect(paywall.config.colors.light.background.stringRepresentation) == "#FF00AA" - expect(paywall.config.colors.light.foreground.stringRepresentation) == "#FF00AA22" + expect(paywall.config.colors.light.text1.stringRepresentation) == "#FF00AA22" + expect(paywall.config.colors.light.text2?.stringRepresentation) == "#FF00AA11" expect(paywall.config.colors.light.callToActionBackground.stringRepresentation) == "#FF00AACC" expect(paywall.config.colors.light.callToActionForeground.stringRepresentation) == "#FF00AA" - expect(paywall.config.colors.light.accent1.stringRepresentation) == "#FF0000" + expect(paywall.config.colors.light.accent1?.stringRepresentation) == "#FF0000" expect(paywall.config.colors.light.accent2?.stringRepresentation) == "#00FF00" expect(paywall.config.colors.dark?.background.stringRepresentation) == "#FF0000" - expect(paywall.config.colors.dark?.foreground.stringRepresentation) == "#1100FFAA" + expect(paywall.config.colors.dark?.text1.stringRepresentation) == "#FF0011" + expect(paywall.config.colors.dark?.text2).to(beNil()) expect(paywall.config.colors.dark?.callToActionBackground.stringRepresentation) == "#112233AA" expect(paywall.config.colors.dark?.callToActionForeground.stringRepresentation) == "#AABBCC" - expect(paywall.config.colors.dark?.accent1.stringRepresentation) == "#00FFFF" + expect(paywall.config.colors.dark?.accent1?.stringRepresentation) == "#00FFFF" expect(paywall.config.colors.dark?.accent2?.stringRepresentation) == "#FF00FF" let enConfig = try XCTUnwrap(paywall.config(for: Locale(identifier: "en_US")))