Skip to content

Commit

Permalink
Paywalls: added support for decoding colors (#2822)
Browse files Browse the repository at this point in the history
  • Loading branch information
NachoSoto committed Aug 24, 2023
1 parent 3a252ef commit fb22271
Show file tree
Hide file tree
Showing 12 changed files with 625 additions and 10 deletions.
18 changes: 17 additions & 1 deletion RevenueCat.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,8 @@
4FB3FE132A38CB1F004789C6 /* SignatureVerificationIntegrationTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FB3FE122A38CB1F004789C6 /* SignatureVerificationIntegrationTests.swift */; };
4FB9069F2A69550500BE2735 /* AvailabilityChecks.swift in Sources */ = {isa = PBXBuildFile; fileRef = B3BE0263275942D500915B4C /* AvailabilityChecks.swift */; };
4FBBC5682A61E42F0077281F /* NonEmptyStringDecodable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FBBC5672A61E42F0077281F /* NonEmptyStringDecodable.swift */; };
4FBBD4E42A620539001CBA21 /* PaywallColorTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FBBD4E32A620539001CBA21 /* PaywallColorTests.swift */; };
4FBBD4E62A620573001CBA21 /* PaywallColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FBBD4E52A620573001CBA21 /* PaywallColor.swift */; };
4FC083292A4A35FB00A97089 /* Integer+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FC083282A4A35FB00A97089 /* Integer+Extensions.swift */; };
4FC0832B2A4A361700A97089 /* IntegerExtensionsTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FC0832A2A4A361700A97089 /* IntegerExtensionsTests.swift */; };
4FC972172A712DCC008593DE /* CachingProductsManagerTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4FC972162A712DCC008593DE /* CachingProductsManagerTests.swift */; };
Expand Down Expand Up @@ -1003,6 +1005,8 @@
4FA696BC2A0020A000D228B1 /* MainThreadMonitor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MainThreadMonitor.swift; sourceTree = "<group>"; };
4FB3FE122A38CB1F004789C6 /* SignatureVerificationIntegrationTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SignatureVerificationIntegrationTests.swift; sourceTree = "<group>"; };
4FBBC5672A61E42F0077281F /* NonEmptyStringDecodable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NonEmptyStringDecodable.swift; sourceTree = "<group>"; };
4FBBD4E32A620539001CBA21 /* PaywallColorTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PaywallColorTests.swift; sourceTree = "<group>"; };
4FBBD4E52A620573001CBA21 /* PaywallColor.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PaywallColor.swift; sourceTree = "<group>"; };
4FC083282A4A35FB00A97089 /* Integer+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Integer+Extensions.swift"; sourceTree = "<group>"; };
4FC0832A2A4A361700A97089 /* IntegerExtensionsTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IntegerExtensionsTests.swift; sourceTree = "<group>"; };
4FC972162A712DCC008593DE /* CachingProductsManagerTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CachingProductsManagerTests.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1667,6 +1671,7 @@
2DDF41DD24F6F4F9005BC22D /* Mocks */,
35D832FE262FAD6900E60AC5 /* Networking */,
57488B8929CB75520000EE7E /* OfflineEntitlements */,
4FBBD4E22A620516001CBA21 /* Paywalls */,
354235D624C11160008C84EE /* Purchasing */,
5759B403296DF68D002472D5 /* ReceiptParserTests */,
2DDE559824C8B5D100DCB087 /* Resources */,
Expand Down Expand Up @@ -2240,6 +2245,7 @@
4F87610D2A5C9E330006FA14 /* Paywalls */ = {
isa = PBXGroup;
children = (
4FBBD4E52A620573001CBA21 /* PaywallColor.swift */,
4F87610E2A5C9E490006FA14 /* PaywallData.swift */,
4F87612B2A5CAB980006FA14 /* PaywallTemplate.swift */,
);
Expand All @@ -2258,6 +2264,15 @@
path = Helpers;
sourceTree = "<group>";
};
4FBBD4E22A620516001CBA21 /* Paywalls */ = {
isa = PBXGroup;
children = (
4F05876E2A5DE03F00E9A834 /* PaywallDataTests.swift */,
4FBBD4E32A620539001CBA21 /* PaywallColorTests.swift */,
);
path = Paywalls;
sourceTree = "<group>";
};
4FCEEA5F2A379CD6002C2112 /* Support */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -2393,7 +2408,6 @@
574A2F3E282D75E300150D40 /* OfferingsDecodingTests.swift */,
574A2F4E282D7B9E00150D40 /* PostOfferDecodingTests.swift */,
5766C61F282DA3D50067D886 /* GetIntroEligibilityDecodingTests.swift */,
4F05876E2A5DE03F00E9A834 /* PaywallDataTests.swift */,
57045B3729C514A8001A5417 /* ProductEntitlementMappingDecodingTests.swift */,
);
path = Responses;
Expand Down Expand Up @@ -3454,6 +3468,7 @@
9A65DFDE258AD60A00DE00B0 /* LogIntent.swift in Sources */,
B37815492857F1E7000A7B93 /* BackendConfiguration.swift in Sources */,
57045B3C29C51AF7001A5417 /* ProductEntitlementMappingCallback.swift in Sources */,
4FBBD4E62A620573001CBA21 /* PaywallColor.swift in Sources */,
B35042C626CDD3B100905B95 /* PurchasesDelegate.swift in Sources */,
0313FD41268A506400168386 /* DateProvider.swift in Sources */,
57FDAABA284937A0009A48F1 /* SandboxEnvironmentDetector.swift in Sources */,
Expand Down Expand Up @@ -3535,6 +3550,7 @@
57E415EB2846962500EA5460 /* PurchasesSyncPurchasesTests.swift in Sources */,
5766AAC5283E843300FA6091 /* PurchasesConfiguringTests.swift in Sources */,
351B514D26D44A8600BD2BD7 /* MockHTTPClient.swift in Sources */,
4FBBD4E42A620539001CBA21 /* PaywallColorTests.swift in Sources */,
5733B1AA27FFBCF900EC2045 /* BaseErrorTests.swift in Sources */,
578FB10E27ADDA8000F70709 /* AvailabilityChecks.swift in Sources */,
57E415EF284697A300EA5460 /* PurchasesDeferredPurchasesTests.swift in Sources */,
Expand Down
46 changes: 46 additions & 0 deletions RevenueCatUI/Helpers/ColorInformation+MultiScheme.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
//
// ColorInformation+MultiScheme.swift
//
//
// Created by Nacho Soto on 7/14/23.
//

import Foundation
import RevenueCat

#if canImport(SwiftUI) && canImport(UIKit)

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 {
let light = self.light
guard let dark = self.dark else {
// With no dark information, simply use `light`.
return light
}

return .init(
background: .init(light: light.background, dark: dark.background),
foreground: .init(light: light.foreground, dark: dark.foreground),
callToActionBackground: .init(light: light.callToActionBackground, dark: dark.callToActionBackground),
callToActionForeground: .init(light: light.callToActionForeground, dark: dark.callToActionForeground)
)
}

}

#else

extension PaywallData.Configuration.ColorInformation {

/// - Returns: `light` colors for platforms that don't support dark mode.
@available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *)
var multiScheme: PaywallData.Configuration.Colors {
return self.light
}

}

#endif
24 changes: 22 additions & 2 deletions RevenueCatUI/TestData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ internal enum TestData {
template: .example1,
config: .init(
packages: [.monthly],
headerImageName: Self.paywallHeaderImageName
headerImageName: Self.paywallHeaderImageName,
colors: .init(light: Self.lightColors)
),
localization: Self.localization,
assetBaseURL: Self.paywallAssetBaseURL
Expand All @@ -75,7 +76,8 @@ internal enum TestData {
template: .example1,
config: .init(
packages: [.annual],
headerImageName: Self.paywallHeaderImageName
headerImageName: Self.paywallHeaderImageName,
colors: .init(light: Self.lightColors)
),
localization: Self.localization,
assetBaseURL: Self.paywallAssetBaseURL
Expand All @@ -97,6 +99,13 @@ internal enum TestData {
availablePackages: Self.packages
)

static let lightColors: PaywallData.Configuration.Colors = .init(
background: "#000000",
foreground: "#FF0000",
callToActionBackground: "#FF0AB1",
callToActionForeground: "#FF0000"
)

static let customerInfo: CustomerInfo = {
let json = """
{
Expand Down Expand Up @@ -191,4 +200,15 @@ extension PurchaseHandler {
}
}

extension PaywallColor: ExpressibleByStringLiteral {

/// Creates a `PaywallColor` with a string literal
/// - Warning: This will crash at runtime if the string is invalid. Only for debugging purposes.
public init(stringLiteral value: StringLiteralType) {
// swiftlint:disable:next force_try
try! self.init(stringRepresentation: value)
}

}

#endif
Loading

0 comments on commit fb22271

Please sign in to comment.