fix(commons): base ColorScheme.isLight on background, not primary luminance

commons ColorScheme.isLight tested `primary.luminance() < 0.5f`. With the
default purple accent the primary is a deep purple in the light theme (lum
0.09) AND a light purple in the dark theme (lum 0.35) — both < 0.5 — so it
reported "light" in BOTH modes. The Android app decides the same thing from
the background (`background != Color.Black`); `background.luminance() > 0.5f`
is the multiplatform-safe equivalent (light bg ≈ 0.98, dark bg = 0.0).

Surfaced while reviewing the note-ui extraction: the new commons theme helpers
that branch on isLight — subtleBorder / replyModifier (card hairline borders)
and allGoodColor / warningColor (RelayDiscovery latency chips) — were rendering
their light-theme variant in dark mode, a regression vs the Android originals
which use the app's background-based isLight. This restores parity.

Also corrects two pre-existing consumers that had the same latent bug and now
behave correctly in dark mode (worth a dark-mode glance in review):
- UserAvatar → CachedRobohash light/dark variant selection;
- ChatTheme.chatBubbleBackground alpha.

Verified: :commons:compileKotlinJvm passes.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Gmrt3jwYPDJ38MJGJ6GaNr
This commit is contained in:
Claude
2026-07-17 22:50:09 +00:00
parent c18256a175
commit c4957ee8c0
@@ -26,11 +26,17 @@ import androidx.compose.ui.graphics.ColorFilter
import androidx.compose.ui.graphics.luminance
/**
* Determines if the color scheme is light mode.
* Based on primary color luminance.
* Determines if the color scheme is light mode, from the background's luminance
* (near-white in light themes, black in dark themes).
*
* NOTE: this used to test `primary.luminance() < 0.5f`, which was wrong — the
* default purple accent is a deep purple in the light theme AND a light purple
* in the dark theme, both below 0.5, so it reported "light" in *both* modes.
* The Android app keys the same decision off the background (`background !=
* Color.Black`); background luminance is the multiplatform-safe equivalent.
*/
val ColorScheme.isLight: Boolean
get() = primary.luminance() < 0.5f
get() = background.luminance() > 0.5f
/**
* Color filter for onBackground color (for tinting icons/images).