-
Notifications
You must be signed in to change notification settings - Fork 338
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 V2] Update color spec #4468
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,18 +43,80 @@ public extension PaywallComponent { | |
public let heicLowRes: URL | ||
} | ||
|
||
struct ColorInfo: Codable, Sendable, Hashable, Equatable { | ||
struct ColorScheme: Codable, Sendable, Hashable, Equatable { | ||
|
||
public init(light: ColorHex, dark: ColorHex? = nil) { | ||
public init(light: ColorInfo, dark: ColorInfo? = nil) { | ||
self.light = light | ||
self.dark = dark | ||
} | ||
|
||
public let light: ColorHex | ||
public let dark: ColorHex? | ||
public let light: ColorInfo | ||
public let dark: ColorInfo? | ||
|
||
} | ||
|
||
enum ColorInfo: Codable, Sendable, Hashable { | ||
|
||
case hex(ColorHex) | ||
case alias(String) | ||
|
||
public func encode(to encoder: any Encoder) throws { | ||
var container = encoder.container(keyedBy: CodingKeys.self) | ||
|
||
switch self { | ||
case .hex(let hex): | ||
try container.encode(ColorInfoTypes.hex.rawValue, forKey: .type) | ||
try container.encode(hex, forKey: .value) | ||
case .alias(let alias): | ||
try container.encode(ColorInfoTypes.alias.rawValue, forKey: .type) | ||
try container.encode(alias, forKey: .value) | ||
} | ||
} | ||
|
||
public init(from decoder: Decoder) throws { | ||
let container = try decoder.container(keyedBy: CodingKeys.self) | ||
let type = try container.decode(ColorInfoTypes.self, forKey: .type) | ||
|
||
switch type { | ||
case .hex: | ||
let value = try container.decode(ColorHex.self, forKey: .value) | ||
self = .hex(value) | ||
case .alias: | ||
let value = try container.decode(String.self, forKey: .value) | ||
self = .alias(value) | ||
} | ||
} | ||
|
||
// swiftlint:disable:next nesting | ||
private enum CodingKeys: String, CodingKey { | ||
|
||
case type | ||
case value | ||
|
||
} | ||
|
||
// swiftlint:disable:next nesting | ||
private enum ColorInfoTypes: String, Decodable { | ||
|
||
case hex | ||
case alias | ||
|
||
} | ||
|
||
} | ||
|
||
// struct ColorInfo: Codable, Sendable, Hashable, Equatable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: remove commented code There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ha! I did notice this and it gets removed like 2 PRs in 😛 |
||
// | ||
// public init(light: ColorHex, dark: ColorHex? = nil) { | ||
// self.light = light | ||
// self.dark = dark | ||
// } | ||
// | ||
// public let light: ColorHex | ||
// public let dark: ColorHex? | ||
// | ||
// } | ||
|
||
enum Shape: Codable, Sendable, Hashable, Equatable { | ||
|
||
case rectangle | ||
|
@@ -209,15 +271,15 @@ public extension PaywallComponent { | |
|
||
struct Shadow: Codable, Sendable, Hashable, Equatable { | ||
|
||
public let color: ColorInfo | ||
public let color: ColorScheme | ||
public let radius: CGFloat | ||
// swiftlint:disable:next identifier_name | ||
public let x: CGFloat | ||
// swiftlint:disable:next identifier_name | ||
public let y: CGFloat | ||
|
||
// swiftlint:disable:next identifier_name | ||
public init(color: ColorInfo, radius: CGFloat, x: CGFloat, y: CGFloat) { | ||
public init(color: ColorScheme, radius: CGFloat, x: CGFloat, y: CGFloat) { | ||
self.color = color | ||
self.radius = radius | ||
self.x = x | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I might think about adding in some tests to validate the custom encoding/decoding of the ColorInfo enum. I know from recent experience in Pines that it's easy to make mistakes in these custom enum codable implementations and it's easy to miss until much later in testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes yes, for sure! Tests coming soon™️