Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Paywalls: Allow closed button color to be configured #3805

Merged
merged 3 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ extension PaywallData.Configuration.Colors {
dark: dark.callToActionSecondaryBackground),
accent1: .init(light: light.accent1, dark: dark.accent1),
accent2: .init(light: light.accent2, dark: dark.accent2),
accent3: .init(light: light.accent3, dark: dark.accent3)
accent3: .init(light: light.accent3, dark: dark.accent3),
closeButton: .init(light: light.closeButton, dark: dark.closeButton)
)
}

Expand Down Expand Up @@ -118,6 +119,7 @@ extension PaywallData.Configuration.Colors {
var accent1Color: Color { self.accent1?.underlyingColor ?? self.callToActionForegroundColor }
var accent2Color: Color { self.accent2?.underlyingColor ?? self.accent1Color }
var accent3Color: Color { self.accent3?.underlyingColor ?? self.accent2Color }
var closeButtonColor: Color? { self.closeButton?.underlyingColor }

}

Expand Down
34 changes: 27 additions & 7 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -321,14 +321,20 @@ struct LoadedOfferingPaywallView: View {

@ViewBuilder
private var content: some View {
let configuration = self.paywall.configuration(
tonidero marked this conversation as resolved.
Show resolved Hide resolved
for: self.offering,
activelySubscribedProductIdentifiers: self.activelySubscribedProductIdentifiers,
template: self.template,
mode: self.mode,
fonts: self.fonts,
locale: self.locale
)

let view = self.paywall
.createView(for: self.offering,
activelySubscribedProductIdentifiers: self.activelySubscribedProductIdentifiers,
template: self.template,
mode: self.mode,
fonts: self.fonts,
introEligibility: self.introEligibility,
locale: self.locale)
configuration: configuration,
introEligibility: self.introEligibility)
.environmentObject(self.introEligibility)
.environmentObject(self.purchaseHandler)
.disabled(self.purchaseHandler.actionInProgress)
Expand All @@ -350,7 +356,11 @@ struct LoadedOfferingPaywallView: View {
if self.displayCloseButton {
NavigationView {
view
.toolbar { self.toolbar }
.toolbar {
self.makeToolbar(
tonidero marked this conversation as resolved.
Show resolved Hide resolved
color: self.getCloseButtonColor(configuration: configuration)
)
}
}
.navigationViewStyle(.stack)
} else {
Expand All @@ -369,7 +379,16 @@ struct LoadedOfferingPaywallView: View {
)
}

private var toolbar: some ToolbarContent {
private func getCloseButtonColor(configuration: Result<TemplateViewConfiguration, Error>) -> Color? {
switch configuration {
case .success(let configuration):
return configuration.colors.closeButtonColor
case .failure:
return nil
}
}

private func makeToolbar(color: Color?) -> some ToolbarContent {
ToolbarItem(placement: .destructiveAction) {
Button {
guard let onRequestedDismissal = self.onRequestedDismissal else {
Expand All @@ -379,6 +398,7 @@ struct LoadedOfferingPaywallView: View {
onRequestedDismissal()
} label: {
Image(systemName: "xmark")
.foregroundColor(color)
}
.disabled(self.purchaseHandler.actionInProgress)
.opacity(
Expand Down
15 changes: 3 additions & 12 deletions RevenueCatUI/Templates/TemplateViewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,11 @@ private extension PaywallTemplate {
extension PaywallData {

@ViewBuilder
// swiftlint:disable:next function_parameter_count
func createView(for offering: Offering,
activelySubscribedProductIdentifiers: Set<String>,
template: PaywallTemplate,
mode: PaywallViewMode,
fonts: PaywallFontProvider,
introEligibility: IntroEligibilityViewModel,
locale: Locale) -> some View {
switch self.configuration(for: offering,
activelySubscribedProductIdentifiers: activelySubscribedProductIdentifiers,
template: template,
mode: mode,
fonts: fonts,
locale: locale) {
configuration: Result<TemplateViewConfiguration, Error>,
introEligibility: IntroEligibilityViewModel) -> some View {
switch configuration {
case let .success(configuration):
Self.createView(template: template, configuration: configuration)
.adaptTemplateView(with: configuration)
Expand Down
6 changes: 5 additions & 1 deletion Sources/Paywalls/PaywallData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ extension PaywallData.Configuration {
public var accent2: PaywallColor?
/// Tertiary accent color
public var accent3: PaywallColor?
/// Color for the close button of the paywall.
public var closeButton: PaywallColor?

// swiftlint:disable:next missing_docs
public init(
Expand All @@ -373,7 +375,8 @@ extension PaywallData.Configuration {
callToActionSecondaryBackground: PaywallColor? = nil,
accent1: PaywallColor? = nil,
accent2: PaywallColor? = nil,
accent3: PaywallColor? = nil
accent3: PaywallColor? = nil,
closeButton: PaywallColor? = nil
) {
self.background = background
self.text1 = text1
Expand All @@ -385,6 +388,7 @@ extension PaywallData.Configuration {
self.accent1 = accent1
self.accent2 = accent2
self.accent3 = accent3
self.closeButton = closeButton
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,8 @@ private extension SamplePaywallLoader {
callToActionBackground: "#222222",
callToActionForeground: "#FFFFFF",
accent1: "#F4E971",
accent2: "#121212"
accent2: "#121212",
closeButton: "#00FF00"
),
dark: .init(
background: "#272727",
Expand All @@ -292,7 +293,8 @@ private extension SamplePaywallLoader {
callToActionBackground: "#FFFFFF",
callToActionForeground: "#000000",
accent1: "#F4E971",
accent2: "#4A4A4A"
accent2: "#4A4A4A",
closeButton: "#00FF00"
)
),
termsOfServiceURL: Self.tosURL
Expand Down