Skip to content

theme: preserve CSS alpha in hex color parsing on both platforms - #352

Merged
0xSero merged 2 commits into
mainfrom
fix/css-hex-alpha
Sep 14, 2026
Merged

0xSero merged 2 commits into
mainfrom
fix/css-hex-alpha

Conversation

@0xSero

@0xSero 0xSero commented Sep 13, 2026

Copy link
Copy Markdown
Owner

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's Color(Long) is ARGB (alpha first), and the old Android parser fed the hex digits straight into Color(Long) — so #4585AA80 rendered as 0x804585AA-misread opaque color instead of translucent #4585AA at 50% alpha. iOS's Scanner-based helper silently mis-parsed or dropped the alpha byte for the same shapes.

Changes:

  • Android 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 framework Color.parseColor dependency in the hot path).
  • iOS: shared LitterHexRGBA helper (top-level in LitterPalette.swift because the Live Activity extension compiles that file but not Extensions.swift) parses alpha-last hex; Color(hex:), UIColor(hex:), ThemeDefinition.hexToRGB, and the watch's WatchThemeStore (which compiles neither shared file) all preserve alpha now.
  • QA matrix row + tests on both platforms.

Verification:

  • Android: ThemeColorTest#4585AA800x804585AA, #A8AA shorthand → 0xAAAA88AA, opaque token still matches the generated Material role, invalid input falls back without the framework parser.
  • iOS: HexColorTests on the simulator — 6 tests, 0 failures (alpha preserved, shorthand expansion, uppercase/padded input, invalid → nil, UIColor alpha, LitterPalette.Pair.colorFromHex).

@0xSero
0xSero merged commit 95d34dd into main Sep 14, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant