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: convert empty images into nil #3195

Merged
merged 3 commits into from
Sep 12, 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
33 changes: 29 additions & 4 deletions Sources/Paywalls/PaywallData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,29 @@ extension PaywallData.Configuration {
public struct Images {

/// Image displayed as a header in a template.
public var header: String?
public var header: String? {
get { self._header }
set { self._header = newValue }
}

/// Image displayed as a background in a template.
public var background: String?
public var background: String? {
get { self._background }
set { self._background = newValue }
}

/// Image displayed as an app icon in a template.
public var icon: String?
public var icon: String? {
get { self._icon }
set { self._icon = newValue }
}

@NonEmptyStringDecodable
var _header: String?
@NonEmptyStringDecodable
var _background: String?
@NonEmptyStringDecodable
var _icon: String?
Comment on lines +283 to +287
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cc @vegaro we'll need to do the same in Android

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


// swiftlint:disable:next missing_docs
public init(header: String? = nil, background: String? = nil, icon: String? = nil) {
Expand Down Expand Up @@ -418,7 +434,16 @@ extension PaywallData.LocalizedConfiguration: Codable {

extension PaywallData.Configuration.ColorInformation: Codable {}
extension PaywallData.Configuration.Colors: Codable {}
extension PaywallData.Configuration.Images: Codable {}

extension PaywallData.Configuration.Images: Codable {

private enum CodingKeys: String, CodingKey {
case _header = "header"
case _background = "background"
case _icon = "icon"
}

}

extension PaywallData.Configuration: Codable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
},
"display_restore_purchases" : true,
"images" : {
"header" : "903907_1693958145.jpg"
"background" : null,
"header" : "903907_1693958145.jpg",
"icon" : null
},
"packages" : [
"$rc_monthly"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"display_restore_purchases" : true,
"images" : {
"background" : "300883_1691437592.jpg",
"header" : null,
"icon" : "300883_1691437591.jpg"
},
"packages" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"display_restore_purchases" : true,
"images" : {
"background" : "background.jpg",
"header" : null,
"icon" : "revenuecatui_default_paywall_app_icon"
},
"packages" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"display_restore_purchases" : true,
"images" : {
"background" : "background.jpg",
"header" : null,
"icon" : "revenuecatui_default_paywall_app_icon"
},
"packages" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"display_restore_purchases" : true,
"images" : {
"background" : "background.jpg",
"header" : null,
"icon" : "revenuecatui_default_paywall_app_icon"
},
"packages" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"display_restore_purchases" : true,
"images" : {
"background" : "background.jpg",
"header" : null,
"icon" : "revenuecatui_default_paywall_app_icon"
},
"packages" : [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"display_restore_purchases" : true,
"images" : {
"background" : "background.jpg",
"header" : null,
"icon" : "revenuecatui_default_paywall_app_icon"
},
"packages" : [
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"template_name": "1",
"localized_strings": {
"en_US": {
"title": "Paywall",
"subtitle": "Description",
"call_to_action": "Purchase now",
"call_to_action_with_intro_offer": "Purchase now",
"offer_details": "{{ sub_price_per_month }} per month",
"offer_details_with_intro_offer": "Start your {{ sub_offer_duration }} trial, then {{ sub_price_per_month }} per month"
}
},
"config": {
"packages": ["$rc_monthly", "$rc_annual"],
"images": {
"header": "",
"background": "",
"icon": ""
},
"colors": {
"light": {
"background": "#FFFFFF",
"text_1": "#FFFFFF",
"call_to_action_background": "#FFFFFF",
"call_to_action_foreground": "#FFFFFF",
"accent_1": "#FFFFFF"
},
"dark": null
}
},
"asset_base_url": "https://rc-paywalls.s3.amazonaws.com"
}
9 changes: 9 additions & 0 deletions Tests/UnitTests/Paywalls/PaywallDataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,15 @@ class PaywallDataTests: BaseHTTPResponseTest {
expect(localization.title) == "Tienda"
}

func testEmptyImageNamesAreParsedAsNil() throws {
let paywall: PaywallData = try self.decodeFixture("PaywallData-empty_images")

let images = paywall.config.images
expect(images.header).to(beNil())
expect(images.background).to(beNil())
expect(images.icon).to(beNil())
}

func testEncodePaywallViewMode() throws {
// iOS 12 does not allow decoding fragments (top-level objects)
try AvailabilityChecks.iOS13APIAvailableOrSkipTest()
Expand Down