Skip to content

Commit

Permalink
Paywalls: improved unselected package background color (#3079)
Browse files Browse the repository at this point in the history
From the design feedback.
  • Loading branch information
NachoSoto committed Sep 15, 2023
1 parent 8598910 commit e830d32
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 19 deletions.
7 changes: 7 additions & 0 deletions RevenueCatUI/Data/PaywallViewMode+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,11 @@ extension PaywallViewMode {
}
}

var shouldDisplayBackground: Bool {
switch self {
case .fullScreen: return true
case .footer, .condensedFooter: return false
}
}

}
11 changes: 11 additions & 0 deletions RevenueCatUI/Data/TemplateViewConfiguration+Images.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ extension TemplateViewConfiguration {

}

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

var backgroundImageURLToDisplay: URL? {
guard self.mode.shouldDisplayBackground else { return nil }

return self.backgroundImageURL
}

}

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

Expand Down
20 changes: 14 additions & 6 deletions RevenueCatUI/Templates/Template2View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,31 @@ struct Template2View: TemplateViewType {
if selected {
EmptyView()
} else {
RoundedRectangle(cornerRadius: Self.cornerRadius)
self.roundedRectangle
.stroke(self.configuration.colors.text1Color.opacity(Self.fadedColorOpacity), lineWidth: 2)
}
}
.background {
let view = RoundedRectangle(cornerRadius: Self.cornerRadius, style: .continuous)

if selected {
view
self.roundedRectangle
.foregroundColor(self.selectedBackgroundColor)
} else {
view
.foregroundStyle(.thinMaterial)
if self.configuration.backgroundImageURLToDisplay != nil {
// Blur background if there is a background image.
self.roundedRectangle
.foregroundStyle(.thinMaterial)
} else {
// Otherwise the text should have enough contrast with the selected background color.
EmptyView()
}
}
}
}

private var roundedRectangle: some Shape {
RoundedRectangle(cornerRadius: Self.cornerRadius, style: .continuous)
}

private func packageButtonTitle(
_ package: TemplateViewConfiguration.Package,
selected: Bool
Expand Down
14 changes: 1 addition & 13 deletions RevenueCatUI/Views/TemplateBackgroundImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ struct TemplateBackgroundImageView: View {
var configuration: TemplateViewConfiguration

var body: some View {
if self.configuration.mode.shouldDisplayBackground,
let url = self.configuration.backgroundImageURL {
if let url = self.configuration.backgroundImageURLToDisplay {
self.image(url)
.unredacted()
.frame(maxWidth: .infinity, maxHeight: .infinity)
Expand All @@ -35,14 +34,3 @@ struct TemplateBackgroundImageView: View {
}

}

private extension PaywallViewMode {

var shouldDisplayBackground: Bool {
switch self {
case .fullScreen: return true
case .footer, .condensedFooter: return false
}
}

}

0 comments on commit e830d32

Please sign in to comment.