Skip to content

[Paywalls V2] Updating UIConfig aliased colors to contain both light and dark#4650

Merged
joshdholtz merged 6 commits into
mainfrom
paywalls-v2/ui-config-colors-light-and-dark
Jan 13, 2025
Merged

[Paywalls V2] Updating UIConfig aliased colors to contain both light and dark#4650
joshdholtz merged 6 commits into
mainfrom
paywalls-v2/ui-config-colors-light-and-dark

Conversation

@joshdholtz

@joshdholtz joshdholtz commented Jan 11, 2025

Copy link
Copy Markdown
Member

Motivation

Aliased color will be both light and dark

Description

This ended up being a whole thing...

TL;DR - Added a new DisplayableColorScheme object that has types of hex, linear, and radial...

PaywallComponent.ColorScheme -> DisplayableColorScheme->Color/Gradient`

Issue

We have .alias as a value on ColorInfo but we need to alias an entire set of light/dark colors (aka ColorScheme).

Our logic right now directly converts ColorInfo into a SwiftUI/UI color (for foreground, background, etc). This works fine for hex, linear, and radial but will not work well for alias. We need to perform the alias lookup at the ColorScheme level (near the view model layer instead of at the render layer)

Solution

Create a new DisplayableColorScheme and DisplayableColorInfo struct. These new data structures only have values for hex, linear, and radial.

ColorScheme (and ColorInfo) get mapped to DisplayableColorScheme (and DisplayableColorInfo) and in this mapping is where the alias look up happens. This makes it safer/cleaner at the render level because everything has a specific color now.

The converting to DisplayableColorScheme currently will fallback to a clear color if there is an error and log an error. We will EVENTUALLY AND SOON (in a follow up PR) add this validation that the alias exists in the creation of the view models so that we can error out early if needed.

NOTE: We will also add big backend validation that the alias colors exist so the SDKs will never (🤞) have to encounter an alias color not existing.

@joshdholtz joshdholtz marked this pull request as ready for review January 12, 2025 00:10
@joshdholtz joshdholtz requested review from a team January 12, 2025 00:10

@JayShortway JayShortway left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This makes a lot of sense! :shipit:

Comment on lines +121 to +126
// Throwing error if alias has an alias
// This should NEVER happen though
case .alias(let name):
Logger.error("Aliased color '\(name)' has an aliased value which is not allowed.")
throw PaywallColorError.aliasedColorIsAliased(name)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Famous last words 😅
This will move to the ViewModel validation/initialization too, right?

@joshdholtz joshdholtz force-pushed the paywalls-v2/ui-config-colors-light-and-dark branch from cb94a09 to 5c70b03 Compare January 13, 2025 11:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants