Skip to content

Commit

Permalink
Paywalls: rename card to footer (#3049)
Browse files Browse the repository at this point in the history
Rename "card" to "footer" to because that is how we expect developers to
use the current implementation of the non-fullscreen modes as a footer
to their custom paywalls.

- Renamed `card` to `footer`
- Renamed `condensedCard` to `condensedFooter`

---------

Co-authored-by: NachoSoto <ignaciosoto90@gmail.com>
  • Loading branch information
joshdholtz and NachoSoto committed Aug 31, 2023
1 parent 5b92c64 commit de2e1ed
Show file tree
Hide file tree
Showing 19 changed files with 91 additions and 91 deletions.
14 changes: 7 additions & 7 deletions RevenueCatUI/Data/PaywallViewMode+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,37 @@ extension PaywallViewMode {
var displayAllPlansByDefault: Bool {
switch self {
case .fullScreen: return true
case .card: return true
case .condensedCard: return false
case .footer: return true
case .condensedFooter: return false
}
}

var displayAllPlansButton: Bool {
switch self {
case .fullScreen: return false
case .card: return false
case .condensedCard: return true
case .footer: return false
case .condensedFooter: return true
}
}

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

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

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

Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Helpers/PreviewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ private extension PaywallViewMode {
var layout: PreviewLayout {
switch self {
case .fullScreen: return .device
case .card: return .fixed(width: 400, height: 280)
case .condensedCard: return .fixed(width: 400, height: 150)
case .footer: return .fixed(width: 400, height: 280)
case .condensedFooter: return .fixed(width: 400, height: 150)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// CardHidingModifier.swift
// FooterHidingModifier.swift
//
//
// Created by Nacho Soto on 8/9/23.
Expand All @@ -11,20 +11,20 @@ import SwiftUI
@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
extension View {

func hideCardContent(
func hideFooterContent(
_ configuration: TemplateViewConfiguration,
hide: Bool,
offset: CGFloat
) -> some View {
return self.modifier(CardHidingModifier(configuration: configuration,
hide: hide,
offset: offset))
return self.modifier(FooterHidingModifier(configuration: configuration,
hide: hide,
offset: offset))
}

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
private struct CardHidingModifier: ViewModifier {
private struct FooterHidingModifier: ViewModifier {

@State
private var height: CGFloat = 10
Expand All @@ -35,12 +35,12 @@ private struct CardHidingModifier: ViewModifier {

func body(content: Content) -> some View {
switch self.configuration.mode {
case .fullScreen, .card:
case .fullScreen, .footer:
// These modes don't support hiding the content
content
.padding(.vertical)

case .condensedCard:
case .condensedFooter:
// "Hidden view" so it doesn't contribute to size calculation
Rectangle()
.frame(height: VersionDetector.iOS15 ? 1 : 0) // Note: height "0" breaks iOS 15
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ struct LoadedOfferingPaywallView: View {
case .fullScreen:
view

case .card, .condensedCard:
case .footer, .condensedFooter:
view
.fixedSize(horizontal: false, vertical: true)
.edgesIgnoringSafeArea(.bottom)
Expand Down Expand Up @@ -264,7 +264,7 @@ private extension PaywallViewMode {
var layout: PreviewLayout {
switch self {
case .fullScreen: return .device
case .card, .condensedCard: return .sizeThatFits
case .footer, .condensedFooter: return .sizeThatFits
}
}

Expand Down
10 changes: 5 additions & 5 deletions RevenueCatUI/Templates/Template2View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ struct Template2View: TemplateViewType {
} else {
self.packages
.onSizeChange(.vertical) { if $0 > 0 { self.containerHeight = $0 } }
.hideCardContent(self.configuration,
hide: !self.displayingAllPlans,
offset: self.containerHeight)
.hideFooterContent(self.configuration,
hide: !self.displayingAllPlans,
offset: self.containerHeight)
}
}
.frame(maxHeight: .infinity)
Expand Down Expand Up @@ -266,14 +266,14 @@ private extension PaywallViewMode {
var shouldDisplayPackages: Bool {
switch self {
case .fullScreen: return true
case .card, .condensedCard: return false
case .footer, .condensedFooter: return false
}
}

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

Expand Down
16 changes: 8 additions & 8 deletions RevenueCatUI/Templates/Template4View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ struct Template4View: TemplateViewType {
ZStack(alignment: .bottom) {
TemplateBackgroundImageView(configuration: self.configuration)

self.cardContent
self.footerContent
.edgesIgnoringSafeArea(.bottom)
.frame(maxWidth: .infinity, alignment: .bottom)
.background(self.configuration.colors.backgroundColor)
Expand All @@ -55,13 +55,13 @@ struct Template4View: TemplateViewType {
#endif
}

case .card, .condensedCard:
self.cardContent
case .footer, .condensedFooter:
self.footerContent
}
}

@ViewBuilder
var cardContent: some View {
var footerContent: some View {
VStack(spacing: Self.verticalPadding) {
if self.configuration.mode.shouldDisplayText {
Text(.init(self.selectedPackage.localization.title))
Expand All @@ -75,9 +75,9 @@ struct Template4View: TemplateViewType {
self.packagesScrollView
} else {
self.packagesScrollView
.hideCardContent(self.configuration,
hide: !self.displayingAllPlans,
offset: self.packageContentHeight)
.hideFooterContent(self.configuration,
hide: !self.displayingAllPlans,
offset: self.packageContentHeight)
}

IntroEligibilityStateView(
Expand Down Expand Up @@ -342,7 +342,7 @@ private extension PaywallViewMode {
var shouldDisplayPackages: Bool {
switch self {
case .fullScreen: return true
case .card, .condensedCard: return false
case .footer, .condensedFooter: return false
}
}

Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Templates/TemplateViewType.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ extension TemplateViewConfiguration {
switch self.mode {
case .fullScreen:
self.backgroundContent
case .card, .condensedCard:
case .footer, .condensedFooter:
self.backgroundContent
#if canImport(UIKit)
.roundedCorner(
Expand Down
8 changes: 4 additions & 4 deletions RevenueCatUI/Views/PurchaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,26 +99,26 @@ private extension PaywallViewMode {

var buttonFont: Font.TextStyle {
switch self {
case .fullScreen, .card, .condensedCard: return .title3
case .fullScreen, .footer, .condensedFooter: return .title3
}
}

var fullWidthButton: Bool {
switch self {
case .fullScreen, .card, .condensedCard: return true
case .fullScreen, .footer, .condensedFooter: return true
}
}

@available(tvOS, unavailable)
var buttonSize: ControlSize {
switch self {
case .fullScreen, .card, .condensedCard: return .large
case .fullScreen, .footer, .condensedFooter: return .large
}
}

var buttonBorderShape: ButtonBorderShape {
switch self {
case .fullScreen, .card, .condensedCard:
case .fullScreen, .footer, .condensedFooter:
#if os(macOS) || os(tvOS)
return .roundedRectangle
#else
Expand Down
2 changes: 1 addition & 1 deletion RevenueCatUI/Views/TemplateBackgroundImageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private extension PaywallViewMode {
var shouldDisplayBackground: Bool {
switch self {
case .fullScreen: return true
case .card, .condensedCard: return false
case .footer, .condensedFooter: return false
}
}

Expand Down
10 changes: 5 additions & 5 deletions Sources/Paywalls/PaywallViewMode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public enum PaywallViewMode {

/// Paywall can be displayed as an overlay on top of your own content.
/// Multi-package templates will display the package selection.
case card
case footer

/// Paywall can be displayed as an overlay on top of your own content.
/// Multi-package templates will include a button to make the package selection visible.
case condensedCard
case condensedFooter

/// The default ``PaywallViewMode``: ``PaywallViewMode/fullScreen``.
public static let `default`: Self = .fullScreen
Expand All @@ -38,7 +38,7 @@ extension PaywallViewMode {
public var isFullScreen: Bool {
switch self {
case .fullScreen: return true
case .card, .condensedCard: return false
case .footer, .condensedFooter: return false
}
}

Expand All @@ -49,8 +49,8 @@ extension PaywallViewMode {
var identifier: String {
switch self {
case .fullScreen: return "full_screen"
case .card: return "card"
case .condensedCard: return "condensed_card"
case .footer: return "footer"
case .condensedFooter: return "condensed_footer"
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,9 +147,9 @@ func checkPaywallViewMode(_ mode: PaywallViewMode) {
switch mode {
case .fullScreen:
break
case .card:
case .footer:
break
case .condensedCard:
case .condensedFooter:
break
@unknown default:
break
Expand Down
2 changes: 1 addition & 1 deletion Tests/RevenueCatUITests/BaseSnapshotTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ extension BaseSnapshotTest {
static let fonts: PaywallFontProvider = CustomPaywallFontProvider(fontName: "Papyrus")

static let fullScreenSize: CGSize = .init(width: 460, height: 950)
static let cardSize: CGSize = .init(width: 460, height: 460)
static let footerSize: CGSize = .init(width: 460, height: 460)

}

Expand Down
12 changes: 6 additions & 6 deletions Tests/RevenueCatUITests/Templates/OtherPaywallViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ class OtherPaywallViewTests: BaseSnapshotTest {
.snapshot(size: Self.fullScreenSize)
}

func testLoadingCardPaywallView() {
LoadingPaywallView(mode: .card)
.snapshot(size: Self.cardSize)
func testLoadingFooterPaywallView() {
LoadingPaywallView(mode: .footer)
.snapshot(size: Self.footerSize)
}

func testLoadingCondensedCardPaywallView() {
LoadingPaywallView(mode: .condensedCard)
.snapshot(size: Self.cardSize)
func testLoadingCondensedFooterPaywallView() {
LoadingPaywallView(mode: .condensedFooter)
.snapshot(size: Self.footerSize)
}

}
Expand Down
12 changes: 6 additions & 6 deletions Tests/RevenueCatUITests/Templates/Template1ViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ class Template1ViewTests: BaseSnapshotTest {
.snapshot(size: Self.fullScreenSize)
}

func testCardPaywall() {
func testFooterPaywall() {
PaywallView(offering: Self.offeringWithNoIntroOffer,
mode: .card,
mode: .footer,
introEligibility: Self.eligibleChecker,
purchaseHandler: Self.purchaseHandler)
.snapshot(size: Self.cardSize)
.snapshot(size: Self.footerSize)
}

func testCondensedCardPaywall() {
func testCondensedFooterPaywall() {
PaywallView(offering: Self.offeringWithNoIntroOffer,
mode: .condensedCard,
mode: .condensedFooter,
introEligibility: Self.eligibleChecker,
purchaseHandler: Self.purchaseHandler)
.snapshot(size: Self.cardSize)
.snapshot(size: Self.footerSize)
}

func testSamplePaywallWithIntroOffer() {
Expand Down
12 changes: 6 additions & 6 deletions Tests/RevenueCatUITests/Templates/Template2ViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@ class Template2ViewTests: BaseSnapshotTest {
.snapshot(size: Self.fullScreenSize)
}

func testCardPaywall() {
func testFooterPaywall() {
PaywallView(offering: Self.offering.withLocalImages,
mode: .card,
mode: .footer,
introEligibility: Self.eligibleChecker,
purchaseHandler: Self.purchaseHandler)
.snapshot(size: Self.cardSize)
.snapshot(size: Self.footerSize)
}

func testCondensedCardPaywall() {
func testCondensedFooterPaywall() {
PaywallView(offering: Self.offering.withLocalImages,
mode: .condensedCard,
mode: .condensedFooter,
introEligibility: Self.eligibleChecker,
purchaseHandler: Self.purchaseHandler)
.snapshot(size: Self.cardSize)
.snapshot(size: Self.footerSize)
}

func testPurchasingState() {
Expand Down
Loading

0 comments on commit de2e1ed

Please sign in to comment.