Skip to content

Commit

Permalink
Paywalls: don't apply dark appearance with no dark mode colors (#3184)
Browse files Browse the repository at this point in the history
Reported by @joshdholtz. If the developer doesn't configure dark colors,
we don't want things like materials from inheriting the automatic dark
mode configuration.
  • Loading branch information
NachoSoto authored Sep 11, 2023
1 parent 9c35ee7 commit 9933264
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,16 @@ extension PaywallData.Configuration.ColorInformation {

#endif

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
extension TemplateViewConfiguration {

/// Whether dark mode colors have been configured in this paywall.
var hasDarkMode: Bool {
return self.configuration.colors.dark != nil
}

}

#if canImport(SwiftUI)

import SwiftUI
Expand Down
10 changes: 9 additions & 1 deletion RevenueCatUI/Templates/TemplateViewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,20 @@ extension PaywallData {
fonts: fonts,
locale: locale) {
case let .success(configuration):
Self.createView(template: template, configuration: configuration)
let view = Self.createView(template: template, configuration: configuration)
.task(id: offering) {
await introEligibility.computeEligibility(for: configuration.packages)
}
.background(configuration.backgroundView)

if configuration.hasDarkMode {
view
} else {
// If paywall has no dark mode configured, prevent materials
// and other SwiftUI elements from automatically taking a dark appearance.
view.environment(\.colorScheme, .light)
}

case let .failure(error):
DebugErrorView(error, releaseBehavior: .emptyView)
}
Expand Down

0 comments on commit 9933264

Please sign in to comment.