theme: preserve CSS alpha in hex color parsing on both platforms - #352
Merged
Merged
Conversation
0xSero
force-pushed
the
fix/css-hex-alpha
branch
from
September 14, 2026 13:40
a15d850 to
c0ccbbd
Compare
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.
Follow-up to #312: theme colors written as CSS hex with an alpha channel lost their translucency.
Problem: CSS/VS Code hex is alpha-last (
#RGB,#RGBA,#RRGGBB,#RRGGBBAA). Android'sColor(Long)is ARGB (alpha first), and the old Android parser fed the hex digits straight intoColor(Long)— so#4585AA80rendered as0x804585AA-misread opaque color instead of translucent#4585AAat 50% alpha. iOS'sScanner-based helper silently mis-parsed or dropped the alpha byte for the same shapes.Changes:
colorFromHex: expand 3/4-digit shorthands, parse 6/8-digit forms, and move the alpha byte to the ARGB front for 8-digit input; invalid input falls back cleanly (no Android frameworkColor.parseColordependency in the hot path).LitterHexRGBAhelper (top-level inLitterPalette.swiftbecause the Live Activity extension compiles that file but notExtensions.swift) parses alpha-last hex;Color(hex:),UIColor(hex:),ThemeDefinition.hexToRGB, and the watch'sWatchThemeStore(which compiles neither shared file) all preserve alpha now.Verification:
ThemeColorTest—#4585AA80→0x804585AA,#A8AAshorthand →0xAAAA88AA, opaque token still matches the generated Material role, invalid input falls back without the framework parser.HexColorTestson the simulator — 6 tests, 0 failures (alpha preserved, shorthand expansion, uppercase/padded input, invalid → nil,UIColoralpha,LitterPalette.Pair.colorFromHex).