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: refactored IntroEligibilityStateView #3360

Merged
merged 1 commit into from
Oct 31, 2023
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: 2 additions & 2 deletions RevenueCatUI/Templates/Template1View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ struct Template1View: TemplateViewType {
Spacer()

IntroEligibilityStateView(
textWithNoIntroOffer: self.localization.offerDetails,
textWithIntroOffer: self.localization.offerDetailsWithIntroOffer,
display: .offerDetails,
localization: self.localization,
introEligibility: self.introEligibility,
foregroundColor: self.configuration.colors.text1Color
)
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Templates/Template2View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,8 @@ struct Template2View: TemplateViewType {

private func offerDetails(package: TemplateViewConfiguration.Package, selected: Bool) -> some View {
IntroEligibilityStateView(
textWithNoIntroOffer: package.localization.offerDetails,
textWithIntroOffer: package.localization.offerDetailsWithIntroOffer,
display: .offerDetails,
localization: package.localization,
introEligibility: self.introEligibility[package.content],
foregroundColor: self.textColor(selected),
alignment: Self.packageButtonAlignment
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Templates/Template3View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ struct Template3View: TemplateViewType {
Spacer()

IntroEligibilityStateView(
textWithNoIntroOffer: self.localization.offerDetails,
textWithIntroOffer: self.localization.offerDetailsWithIntroOffer,
display: .offerDetails,
localization: self.localization,
introEligibility: self.introEligibility,
foregroundColor: self.configuration.colors.text2Color
)
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Templates/Template4View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ struct Template4View: TemplateViewType {
selected: self.selectedPackage
) { package in
IntroEligibilityStateView(
textWithNoIntroOffer: package.localization.offerDetails,
textWithIntroOffer: package.localization.offerDetailsWithIntroOffer,
display: .offerDetails,
localization: package.localization,
introEligibility: self.introEligibility[package.content],
foregroundColor: self.configuration.colors.text1Color
)
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Templates/Template5View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,8 @@ struct Template5View: TemplateViewType {

private func offerDetails(package: TemplateViewConfiguration.Package, selected: Bool) -> some View {
IntroEligibilityStateView(
textWithNoIntroOffer: package.localization.offerDetails,
textWithIntroOffer: package.localization.offerDetailsWithIntroOffer,
display: .offerDetails,
localization: package.localization,
introEligibility: self.introEligibility[package.content],
foregroundColor: self.configuration.colors.text1Color,
alignment: Self.packageButtonAlignment
Expand Down
54 changes: 49 additions & 5 deletions RevenueCatUI/Views/IntroEligibilityStateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,36 @@ import SwiftUI
@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
struct IntroEligibilityStateView: View {

var textWithNoIntroOffer: String?
var textWithIntroOffer: String?
var introEligibility: IntroEligibilityStatus?
var foregroundColor: Color?
var alignment: Alignment
enum Display {

case callToAction
case offerDetails

}

private var textWithNoIntroOffer: String?
private var textWithIntroOffer: String?
private var introEligibility: IntroEligibilityStatus?
private var foregroundColor: Color?
private var alignment: Alignment

init(
display: Display,
localization: ProcessedLocalizedConfiguration,
introEligibility: IntroEligibilityStatus?,
foregroundColor: Color? = nil,
alignment: Alignment = .center
) {
self.init(
textWithNoIntroOffer: display.textWithNoIntroOffer(localization),
textWithIntroOffer: display.textWithIntroOffer(localization),
introEligibility: introEligibility,
foregroundColor: foregroundColor,
alignment: alignment
)
}

fileprivate init(
textWithNoIntroOffer: String?,
textWithIntroOffer: String?,
introEligibility: IntroEligibilityStatus?,
Expand Down Expand Up @@ -61,6 +84,27 @@ struct IntroEligibilityStateView: View {

}

// MARK: - Private

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
private extension IntroEligibilityStateView.Display {

func textWithNoIntroOffer(_ localization: ProcessedLocalizedConfiguration) -> String? {
switch self {
case .callToAction: return localization.callToAction
case .offerDetails: return localization.offerDetails
}
}

func textWithIntroOffer(_ localization: ProcessedLocalizedConfiguration) -> String? {
switch self {
case .callToAction: return localization.callToActionWithIntroOffer
case .offerDetails: return localization.offerDetailsWithIntroOffer
}
}

}

// MARK: - Extensions

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
Expand Down
4 changes: 2 additions & 2 deletions RevenueCatUI/Views/PurchaseButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ private struct PurchaseButtonLabel: View {

var body: some View {
IntroEligibilityStateView(
textWithNoIntroOffer: self.package.localization.callToAction,
textWithIntroOffer: self.package.localization.callToActionWithIntroOffer,
display: .callToAction,
localization: self.package.localization,
introEligibility: self.introEligibility,
foregroundColor: self.colors.callToActionForegroundColor
)
Expand Down