Fix muddy custom-theme surfaces on vivid backgrounds#85
Merged
Conversation
buildCustomColorScheme derived every neutral/surface role from the background's own HSL, using saturation up to 0.20 and lightness offsets that assumed a near-white light-mode background. It decided light vs dark by luminance but did the offset math on HSL lightness, so a vivid mid-lightness background like yellow (#F3FF00: luminance 0.93, HSL lightness 0.5) produced a dark olive surfaceVariant on every card with dim, low-contrast text. The Material 3 surfaceContainer* / surfaceDim / surfaceBright roles were never set, so menus, bottom sheets, and the nav bar fell back to a clashing default neutral. Derive all neutral surface roles from the background hue only at a near-zero fixed saturation (0.04) and an absolute per-mode lightness ramp, choose onBackground/onSurface by contrast, and set the full surfaceContainer palette in both light and dark schemes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0154oNEvwJNtprknEQfFAyND
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.
Problem
A custom theme with a vivid background (e.g. the "cray" theme: pink
#FA098E, green#00FF27, blue#001CE7, yellow background#F3FF00) rendered every card and surface as a dark muddy olive with dim, low-contrast text, while menus, bottom sheets, and the navigation bar fell back to a clashing default neutral. The theme read as "not applied" even though the seed colours were stored correctly.Root cause
The defect was entirely in
buildCustomColorScheme()(ui/theme/Color.kt). It derived every neutral/surface role from the background's own HSL, using saturation up to0.20and lightness offsets (bg[2] - 0.10, etc.) that assumed a near-white light-mode background. It decided light vs dark by luminance but did the offset math on HSL lightness — those two diverge badly for a vivid mid-lightness hue. For yellow#F3FF00(luminance 0.93, HSL lightness 0.5) that producedsurfaceVariant = hsl(63°, 0.20, 0.40), the olive seen on every card. The whole Material 3surfaceContainer*/surfaceDim/surfaceBrightfamily was never set, so those roles used the library default that clashes with the custom background.Fix
Reworked only the neutral/surface derivation in
buildCustomColorScheme(); seed colours (primary/secondary/tertiary) and the background override are unchanged.0.04), so a saturated background can never tint surfaces muddy.onBackground/onSurfaceby contrast, reusing the existingcontrastingOn()helper, so text stays legible on any pick.surfaceContainer*palette plussurfaceDim/surfaceBrightin both the light and dark scheme constructors.Result for "cray": yellow page background, clean near-neutral legible cards, and vivid pink/green/blue on buttons, chips, and the nav indicator.
Verification
python3 a11y_check.py→ all clean (no.clickablechanges).#F3FF00→bgIsLighttrue,surfaceVariant = hsl(63°, 0.04, 0.90)(light neutral tint, not olive),onBackgroundnear-black.#000000→ near-black neutral surfaces with white on-text.Includes a
patchchangelog fragment and a LESSONS.md entry (#28).Generated by Claude Code