Skip to content

Commit

Permalink
Paywalls: enabled Catalyst support (#3087)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Aug 28, 2023
1 parent 1025cd2 commit 97c0656
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 58 deletions.
1 change: 0 additions & 1 deletion RevenueCatUI/Helpers/PaywallData+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ private extension PaywallData {
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
struct DefaultPaywall_Previews: PreviewProvider {

static var previews: some View {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Helpers/PreviewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import SwiftUI
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
@MainActor
enum PreviewHelpers {

Expand Down
2 changes: 0 additions & 2 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import SwiftUI
@available(watchOS, unavailable, message: "RevenueCatUI does not support watchOS yet")
@available(macOS, unavailable, message: "RevenueCatUI does not support macOS yet")
@available(tvOS, unavailable, message: "RevenueCatUI does not support tvOS yet")
@available(macCatalyst, unavailable, message: "RevenueCatUI does not support Catalyst yet")
public struct PaywallView: View {

private let mode: PaywallViewMode
Expand Down Expand Up @@ -250,7 +249,6 @@ struct LoadedOfferingPaywallView: View {
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
struct PaywallView_Previews: PreviewProvider {

static var previews: some View {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Templates/Template1View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ private struct CircleMaskModifier: ViewModifier {
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
struct Template1View_Previews: PreviewProvider {

static var previews: some View {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Templates/Template2View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,6 @@ private extension Bundle {
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
struct Template2View_Previews: PreviewProvider {

static var previews: some View {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Templates/Template3View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ private struct FeatureView: View {
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
struct Template3View_Previews: PreviewProvider {

static var previews: some View {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Templates/Template4View.swift
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ private extension PaywallViewMode {
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
struct Template4View_Previews: PreviewProvider {

static var previews: some View {
Expand Down
4 changes: 3 additions & 1 deletion RevenueCatUI/Views/FooterView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ struct FooterView: View {
.padding(.horizontal)
.padding(.bottom, 5)
.dynamicTypeSize(...Constants.maximumDynamicTypeSize)
#if targetEnvironment(macCatalyst)
.buttonStyle(.plain)
#endif
}

private static func allPlansButton(_ binding: Binding<Bool>) -> some View {
Expand Down Expand Up @@ -229,7 +232,6 @@ private struct LinkButton: View {
@available(iOS 16.0, macOS 13.0, tvOS 16.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(macCatalyst, unavailable)
struct Footer_Previews: PreviewProvider {

static var previews: some View {
Expand Down
1 change: 0 additions & 1 deletion RevenueCatUI/Views/LoadingPaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ private extension LoadingPaywallView {
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
@available(macCatalyst, unavailable)
struct LoadingPaywallView_Previews: PreviewProvider {

static var previews: some View {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,13 @@
PRODUCT_BUNDLE_IDENTIFIER = com.revenuecat.PaywallsTester;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TARGETED_DEVICE_FAMILY = "1,2,6,7";
};
name = Debug;
};
Expand Down Expand Up @@ -434,13 +434,13 @@
PRODUCT_BUNDLE_IDENTIFIER = com.revenuecat.PaywallsTester;
PRODUCT_NAME = "$(TARGET_NAME)";
SDKROOT = auto;
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator macosx xros xrsimulator";
SUPPORTED_PLATFORMS = "iphoneos iphonesimulator xros xrsimulator";
SUPPORTS_MACCATALYST = YES;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SUPPORTS_XR_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_EMIT_LOC_STRINGS = YES;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2,7";
TARGETED_DEVICE_FAMILY = "1,2,6,7";
};
name = Release;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ struct CustomPaywall: View {
var purchaseHandler: PurchaseHandler?

var body: some View {
NavigationView {
self.content
.navigationTitle("Custom paywall")
}
self.content
.navigationTitle("Custom paywall")
}

private var content: some View {
Expand Down
15 changes: 14 additions & 1 deletion Tests/TestingApps/SimpleApp/SimpleApp/Views/OfferingsList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,20 @@ struct OfferingsList: View {
case let .success(offerings):
self.list(with: offerings)
.sheet(item: self.$selectedOffering) { offering in
PaywallView(offering: offering)
NavigationView {
PaywallView(offering: offering)
#if targetEnvironment(macCatalyst)
.toolbar {
ToolbarItem(placement: .destructiveAction) {
Button {
self.selectedOffering = nil
} label: {
Image(systemName: "xmark")
}
}
}
#endif
}
}

case let .failure(error):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,45 +22,19 @@ struct SamplePaywallsList: View {
.navigationTitle("Test Paywalls")
}
.sheet(item: self.$display) { display in
switch display {
case let .template(template, mode):
switch mode {
case .fullScreen:
PaywallView(offering: Self.loader.offering(for: template),
customerInfo: Self.loader.customerInfo,
introEligibility: Self.introEligibility,
purchaseHandler: .default())

case .footer, .condensedFooter:
CustomPaywall(offering: Self.loader.offering(for: template),
customerInfo: Self.loader.customerInfo,
condensed: mode == .condensedFooter,
introEligibility: Self.introEligibility,
purchaseHandler: .default())
}

case let .customFont(template):
PaywallView(offering: Self.loader.offering(for: template),
customerInfo: Self.loader.customerInfo,
fonts: Self.customFontProvider,
introEligibility: Self.introEligibility,
purchaseHandler: .default())

case let .customPaywall(mode):
CustomPaywall(customerInfo: Self.loader.customerInfo,
condensed: mode == .condensedFooter)

case .missingPaywall:
PaywallView(offering: Self.loader.offeringWithDefaultPaywall(),
customerInfo: Self.loader.customerInfo,
introEligibility: Self.introEligibility,
purchaseHandler: .default())

case .unrecognizedPaywall:
PaywallView(offering: Self.loader.offeringWithUnrecognizedPaywall(),
customerInfo: Self.loader.customerInfo,
introEligibility: Self.introEligibility,
purchaseHandler: .default())
NavigationView {
self.view(for: display)
#if targetEnvironment(macCatalyst)
.toolbar {
ToolbarItem(placement: .destructiveAction) {
Button {
self.display = nil
} label: {
Image(systemName: "xmark")
}
}
}
#endif
}
}
.onPurchaseCompleted { _ in
Expand All @@ -69,6 +43,50 @@ struct SamplePaywallsList: View {
.navigationTitle("Paywalls")
}

@ViewBuilder
private func view(for display: Display) -> some View {
switch display {
case let .template(template, mode):
switch mode {
case .fullScreen:
PaywallView(offering: Self.loader.offering(for: template),
customerInfo: Self.loader.customerInfo,
introEligibility: Self.introEligibility,
purchaseHandler: .default())

case .footer, .condensedFooter:
CustomPaywall(offering: Self.loader.offering(for: template),
customerInfo: Self.loader.customerInfo,
condensed: mode == .condensedFooter,
introEligibility: Self.introEligibility,
purchaseHandler: .default())
}

case let .customFont(template):
PaywallView(offering: Self.loader.offering(for: template),
customerInfo: Self.loader.customerInfo,
fonts: Self.customFontProvider,
introEligibility: Self.introEligibility,
purchaseHandler: .default())

case let .customPaywall(mode):
CustomPaywall(customerInfo: Self.loader.customerInfo,
condensed: mode == .condensedFooter)

case .missingPaywall:
PaywallView(offering: Self.loader.offeringWithDefaultPaywall(),
customerInfo: Self.loader.customerInfo,
introEligibility: Self.introEligibility,
purchaseHandler: .default())

case .unrecognizedPaywall:
PaywallView(offering: Self.loader.offeringWithUnrecognizedPaywall(),
customerInfo: Self.loader.customerInfo,
introEligibility: Self.introEligibility,
purchaseHandler: .default())
}
}

private func list(with loader: SamplePaywallLoader) -> some View {
List {
ForEach(PaywallTemplate.allCases, id: \.rawValue) { template in
Expand Down

0 comments on commit 97c0656

Please sign in to comment.