Skip to content

Commit

Permalink
Paywalls: new text1 and text2 colors (#2903)
Browse files Browse the repository at this point in the history
`foreground` becomes `text1`, allowing us to keep growing that list just
like accents.
`accent1` is now also optional.
  • Loading branch information
NachoSoto committed Jul 31, 2023
1 parent 9bda484 commit 6192315
Show file tree
Hide file tree
Showing 18 changed files with 54 additions and 41 deletions.
12 changes: 7 additions & 5 deletions RevenueCatUI/Data/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -204,7 +204,7 @@ internal enum TestData {
colors: .init(
light: .init(
background: "#272727",
foreground: "#FFFFFF",
text1: "#FFFFFF",
callToActionBackground: "#FFFFFF",
callToActionForeground: "#000000",
accent1: "#F4E971",
Expand Down Expand Up @@ -240,15 +240,17 @@ internal enum TestData {

static let lightColors: PaywallData.Configuration.Colors = .init(
background: "#FFFFFF",
foreground: "#000000",
text1: "#000000",
text2: "#B2B2B2",
callToActionBackground: "#5CD27A",
callToActionForeground: "#FFFFFF",
accent1: "#BC66FF",
accent2: "#00FF00"
)
static let darkColors: PaywallData.Configuration.Colors = .init(
background: "#000000",
foreground: "#FFFFFF",
text1: "#FFFFFF",
text2: "#B2B2B2",
callToActionBackground: "#ACD27A",
callToActionForeground: "#000000",
accent1: "#B022BB",
Expand Down
8 changes: 5 additions & 3 deletions RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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 }

}
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Helpers/PaywallData+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 3 additions & 3 deletions RevenueCatUI/Templates/MultiPackageBoldTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Templates/OnePackageStandardTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Templates/OnePackageWithFeaturesTemplate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Views/FooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ struct Footer_Previews: PreviewProvider {
termsOfServiceURL: termsOfServiceURL,
privacyURL: privacyURL
),
color: TestData.colors.foregroundColor,
color: TestData.colors.text1Color,
purchaseHandler: Self.handler
)
}
Expand Down
16 changes: 10 additions & 6 deletions Sources/Paywalls/PaywallData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions Tests/TestingApps/SimpleApp/SimpleApp/SamplePaywalls.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -135,7 +135,7 @@ private extension SamplePaywallLoader {
colors: .init(
light: .init(
background: "#272727",
foreground: "#FFFFFF",
text1: "#FFFFFF",
callToActionBackground: "#FFFFFF",
callToActionForeground: "#000000",
accent1: "#F4E971",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@
"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",
"accent_2": "#00FF00"
},
"dark": {
"background": "#FF0000",
"foreground": "#1100FFAA",
"text_1": "#FF0011",
"call_to_action_background": "#112233AA",
"call_to_action_foreground": "#AABBCC",
"accent_1": "#00FFFF",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 6 additions & 4 deletions Tests/UnitTests/Paywalls/PaywallDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")))
Expand Down

0 comments on commit 6192315

Please sign in to comment.