Repository navigation
Return a hex string for dynamic and grayscale colors in toHex - #15
Merged
Merged
Conversation
toHex read the components from cgColor, which is nil for dynamic colors like .primary or .systemBlue and has only two components for colors in a gray color space, so it returned nil for all of them. It now reads sRGB components through UIColor/NSColor, which resolves dynamic colors against the current appearance, and clamps wide-gamut components to the sRGB range hex can represent.
toHex resolves dynamic colors against the traits current at the time of the call, which usually differ from a view's environment; the doc comment now says so and points to rgbo(in:). A new test pins that an in-gamut Display P3 color is converted to sRGB instead of reporting its raw P3 components.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Overview
Color.toHex(alpha:)readcgColor, which isnilfor dynamic colors (.primary,.blue,.systemBlue, …), so it returnednilfor them. For colors in a gray color space it also returnednil(two components), and Display P3 colors were reported with their raw P3 numbers. It now reads sRGB components throughUIColor/NSColor, which resolve dynamic colors, and clamps wide-gamut values to sRGB.main.bluenil0091FF.red/.gray/.primarynilFF4245/98989D/FFFFFFCGColor(gray: 0.5)nil92929280CC4D(raw P3)64CE2F(sRGB)Dynamic colors resolve against the traits current at the time of the call. The doc comment says so and points to
rgbo(in:)for the color a view actually displays.Split out of #7.
How this was verified
Red, with
main'sColorExt.swift:Green, this branch: