Skip to content

Commit

Permalink
Paywalls: watchOS support (#3291)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto authored Nov 16, 2023
1 parent b57a1be commit 6317f09
Show file tree
Hide file tree
Showing 72 changed files with 781 additions and 165 deletions.
28 changes: 28 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,10 @@ jobs:
steps:
- checkout
- update-spm-installation-commit
- run:
name: SPM RevenueCatUI Release Build
command: swift build -c release --target RevenueCatUI
no_output_timeout: 5m
- run:
name: SPM RevenueCatUI Tests
command: bundle exec fastlane test_revenuecatui
Expand All @@ -414,6 +418,28 @@ jobs:
path: fastlane/test_output
destination: scan-test-output

spm-revenuecat-ui-watchos:
<<: *base-job
steps:
- checkout
- update-spm-installation-commit
- run:
name: SPM RevenueCatUI Tests
command: bundle exec fastlane test_revenuecatui
no_output_timeout: 15m
environment:
SCAN_PLATFORM: watchOS Simulator
SCAN_DEVICE: Apple Watch Series 8 (41mm),OS=9.4
BUILD_SDK: watchsimulator
- compress_result_bundle:
directory: fastlane/test_output
bundle_name: revenuecatui
- store_test_results:
path: fastlane/test_output/revenuecatui/tests.xml
- store_artifacts:
path: fastlane/test_output
destination: scan-test-output

run-test-ios-17:
<<: *base-job
resource_class: macos.m1.large.gen1
Expand Down Expand Up @@ -1017,6 +1043,8 @@ workflows:
xcode_version: '14.3.0'
- spm-revenuecat-ui-ios-17:
xcode_version: '15.1'
- spm-revenuecat-ui-watchos:
xcode_version: '14.3.0'
- run-test-ios-17:
xcode_version: '15.0.1'
- run-test-ios-16:
Expand Down
7 changes: 7 additions & 0 deletions RevenueCatUI/Data/TemplateViewConfiguration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ extension TemplateViewConfiguration.PackageConfiguration {
}
}

var singleIfNotMultiple: TemplateViewConfiguration.Package? {
switch self {
case let .single(package): return package
case .multiple: return nil
}
}

/// Returns all packages, useful for templates that expect multiple packages.
var all: [TemplateViewConfiguration.Package] {
switch self {
Expand Down
32 changes: 24 additions & 8 deletions RevenueCatUI/Data/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ internal enum TestData {
productType: .autoRenewableSubscription,
localizedDescription: "PRO weekly",
subscriptionGroupIdentifier: "group",
subscriptionPeriod: .init(value: 1, unit: .week)
subscriptionPeriod: .init(value: 1, unit: .week),
locale: Self.locale
)
static let monthlyProduct = TestStoreProduct(
localizedTitle: "Monthly",
Expand All @@ -35,7 +36,8 @@ internal enum TestData {
localizedDescription: "PRO monthly",
subscriptionGroupIdentifier: "group",
subscriptionPeriod: .init(value: 1, unit: .month),
introductoryDiscount: Self.intro(7, .day)
introductoryDiscount: Self.intro(7, .day),
locale: Self.locale
)
static let threeMonthProduct = TestStoreProduct(
localizedTitle: "3 months",
Expand All @@ -46,7 +48,8 @@ internal enum TestData {
localizedDescription: "PRO monthly",
subscriptionGroupIdentifier: "group",
subscriptionPeriod: .init(value: 3, unit: .month),
introductoryDiscount: Self.intro(7, .day)
introductoryDiscount: Self.intro(7, .day),
locale: Self.locale
)
static let sixMonthProduct = TestStoreProduct(
localizedTitle: "6 months",
Expand All @@ -57,7 +60,8 @@ internal enum TestData {
localizedDescription: "PRO monthly",
subscriptionGroupIdentifier: "group",
subscriptionPeriod: .init(value: 6, unit: .month),
introductoryDiscount: Self.intro(7, .day)
introductoryDiscount: Self.intro(7, .day),
locale: Self.locale
)
static let annualProduct = TestStoreProduct(
localizedTitle: "Annual",
Expand All @@ -68,7 +72,8 @@ internal enum TestData {
localizedDescription: "PRO annual",
subscriptionGroupIdentifier: "group",
subscriptionPeriod: .init(value: 1, unit: .year),
introductoryDiscount: Self.intro(14, .day, priceString: "$1.99")
introductoryDiscount: Self.intro(14, .day, priceString: "$1.99"),
locale: Self.locale
)
static let lifetimeProduct = TestStoreProduct(
localizedTitle: "Lifetime",
Expand All @@ -78,7 +83,8 @@ internal enum TestData {
productType: .nonConsumable,
localizedDescription: "Lifetime purchase",
subscriptionGroupIdentifier: "group",
subscriptionPeriod: nil
subscriptionPeriod: nil,
locale: Self.locale
)
static let productWithIntroOffer = TestStoreProduct(
localizedTitle: "PRO monthly",
Expand All @@ -98,7 +104,8 @@ internal enum TestData {
numberOfPeriods: 1,
type: .introductory
),
discounts: []
discounts: [],
locale: Self.locale
)
static let productWithNoIntroOffer = TestStoreProduct(
localizedTitle: "PRO annual",
Expand All @@ -110,7 +117,8 @@ internal enum TestData {
subscriptionGroupIdentifier: "group",
subscriptionPeriod: .init(value: 1, unit: .year),
introductoryDiscount: nil,
discounts: []
discounts: [],
locale: Self.locale
)
static let weeklyPackage = Package(
identifier: PackageType.weekly.identifier,
Expand Down Expand Up @@ -504,6 +512,13 @@ internal enum TestData {
)
static let paywallAssetBaseURL = URL(string: "https://assets.pawwalls.com")!

#if os(watchOS)
// `Locale.current` in watchOS produces `en_001` when running tests
static let locale: Locale = .init(identifier: "en_US")
#else
static let locale: Locale = .current
#endif

private static let offeringIdentifier = "offering"

private static func intro(
Expand All @@ -521,6 +536,7 @@ internal enum TestData {
type: .introductory
)
}

}

// MARK: -
Expand Down
5 changes: 4 additions & 1 deletion RevenueCatUI/Data/UserInterfaceIdiom.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@ enum UserInterfaceIdiom {
case phone
case pad
case mac
case watch
case unknown

}

extension UserInterfaceIdiom {

#if canImport(UIKit) && !os(watchOS)
#if os(watchOS)
static let `default`: Self = .watch
#elseif canImport(UIKit)
static let `default`: Self = UIDevice.interfaceIdiom
#elseif os(macOS)
static let `default`: Self = .mac
Expand Down
4 changes: 4 additions & 0 deletions RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,17 @@ extension PaywallData.Configuration.ColorInformation {
/// - Returns: `PaywallData.Configuration.Colors` combining `light` and `dark` if they're available
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
var multiScheme: PaywallData.Configuration.Colors {
#if os(watchOS)
return self.dark ?? self.light
#else
let light = self.light
guard let dark = self.dark else {
// With no dark information, simply use `light`.
return light
}

return .combine(light: light, dark: dark)
#endif
}

}
Expand Down
10 changes: 7 additions & 3 deletions RevenueCatUI/Helpers/PaywallData+Default.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import SwiftUI

#if canImport(SwiftUI)

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
extension PaywallData {

/// Default `PaywallData` to display when attempting to present a ``PaywallView`` with an offering
Expand Down Expand Up @@ -47,7 +47,8 @@ extension PaywallData {
),
localization: Self.localization(Localization.localizedBundle(locale)),
assetBaseURL: Self.defaultTemplateBaseURL,
revision: Self.revisionID
revision: Self.revisionID,
locale: locale
)
}

Expand Down Expand Up @@ -123,14 +124,17 @@ private extension PaywallData {
#if DEBUG

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
struct DefaultPaywall_Previews: PreviewProvider {

static var previews: some View {
PreviewableTemplate(offering: Self.offering) {
#if os(watchOS)
WatchTemplateView($0)
#else
Template2View($0)
#endif
}
}

Expand Down
4 changes: 1 addition & 3 deletions RevenueCatUI/Helpers/PreviewHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import SwiftUI
#if DEBUG

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@MainActor
enum PreviewHelpers {
Expand All @@ -41,7 +40,6 @@ enum PreviewHelpers {
/// }
/// ```
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
struct PreviewableTemplate<T: TemplateViewType>: View {
Expand Down Expand Up @@ -118,7 +116,7 @@ struct PreviewableTemplate<T: TemplateViewType>: View {

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
private extension PaywallViewMode {

var layout: PreviewLayout {
Expand Down
9 changes: 2 additions & 7 deletions RevenueCatUI/PaywallView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@
import RevenueCat
import SwiftUI

#if !os(macOS) && !os(tvOS) && !os(watchOS)
#if !os(macOS) && !os(tvOS)

/// A SwiftUI view for displaying a `PaywallData` for an `Offering`.
///
/// ### Related Articles
/// [Documentation](https://rev.cat/paywalls)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@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")
public struct PaywallView: View {
Expand Down Expand Up @@ -209,8 +208,7 @@ public struct PaywallView: View {

}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, *)
@available(watchOS, unavailable)
@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(macOS, unavailable)
@available(tvOS, unavailable)
private extension PaywallView {
Expand All @@ -236,7 +234,6 @@ private extension PaywallView {
// MARK: -

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
struct LoadedOfferingPaywallView: View {
Expand Down Expand Up @@ -343,7 +340,6 @@ struct LoadedOfferingPaywallView: View {
}

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
private extension LoadedOfferingPaywallView {
Expand All @@ -369,7 +365,6 @@ private extension LoadedOfferingPaywallView {
#if DEBUG

@available(iOS 15.0, macOS 12.0, tvOS 15.0, watchOS 8.0, *)
@available(watchOS, unavailable)
@available(macOS, unavailable)
@available(tvOS, unavailable)
struct PaywallView_Previews: PreviewProvider {
Expand Down
Loading

0 comments on commit 6317f09

Please sign in to comment.