fix(native): seed a concrete scheme-aware Android __rn-css-color - #392
Open
YevheniiKotyrlo wants to merge 2 commits into
Open
fix(native): seed a concrete scheme-aware Android __rn-css-color#392YevheniiKotyrlo wants to merge 2 commits into
YevheniiKotyrlo wants to merge 2 commits into
Conversation
On Android the root `__rn-css-color` fallback was
PlatformColor('?attr/textColorPrimary'), which resolves to a ColorStateList;
RN's ColorPropConverter returns the resource *reference* rather than an ARGB
int, so it silently never paints. Every color resolving through the root
fallback -- default ring-* / inset-ring-* (Tailwind's default ring color is
currentcolor), text-current, bg-current -- was invisible on Android. iOS's
PlatformColor('label') is fine.
Seed a concrete color on Android instead, made scheme-aware through the root
observable's existing prefers-color-scheme evaluation (no extra Appearance
listener). The root variable is only the ultimate fallback -- any
ancestor-published or themed --__rn-css-color overrides it -- so a binary
black/white default is spec-faithful.
Splitting the platforms also drops the file's `as any` and two eslint
suppressions: the Android media-query seed types cleanly, and the iOS
PlatformColor uses an isolated `as unknown as StyleDescriptor` bridge.
Adds android + ios tests (currentcolor, live scheme reactivity, a default ring,
ancestor override) that resolve the ColorStateList reference before the fix and
concrete colors after.
YevheniiKotyrlo
marked this pull request as ready for review
July 26, 2026 14:52
…he platform-suffix convention
The seed hardcodes black and white, and the only thing that makes that defensible
is that an app which themes its own text colour wins. The suite proved that for an
ancestor element and never for a stylesheet `:root` rule, which is how an app
actually does it.
The two new cases live in their own file deliberately: `inject` replaces a root
variable outright and nothing puts it back, so a `:root { color }` in the existing
file leaks into every test after it.
`root-color-seed-ios.test.tsx` becomes `root-color-seed.test.ios.tsx`, matching
env / styled / text-shadow.
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.
Summary
On Android, every color that resolves through the root
__rn-css-colorfallback renders nothing — defaultring-*/inset-ring-*(Tailwind v4's default ring color iscurrentcolor),text-current, andbg-currentare all invisible. iOS is fine.The root seed in
src/native-internal/root.ts:On Android
PlatformColor('?attr/textColorPrimary')resolves through React Native'sColorPropConverter.resolveThemeAttribute, which returnsoutValue.datawithout inspectingoutValue.type:?attr/textColorPrimaryis a ColorStateList on AppCompat / Material themes, soTheme.resolveAttributefillsoutValuewith a resource reference (TYPE_REFERENCE), not a packed color — andoutValue.datais then that reference id, used as if it were an ARGB int. The paint is a garbage, effectively-invisible color. The fallback'SystemBaseHighColor'has no@/?prefix, so it isn't a valid resource path and is silently skipped. Net effect on device: no exception, no paint — verified on an Android emulator, where re-seeding__rn-css-colorwith#FF00FFmade the rings andtext-currentrender magenta, proving the resolution machinery is correct and only the seed value was wrong.Fix
Seed a concrete color on Android, made scheme-aware through the root observable's existing
prefers-color-schemeevaluation — no newAppearancelistener, and it drops theas any+ two eslint suppressions:The root variable is only the ultimate fallback (any ancestor-published or themed
--__rn-css-coloroverrides it), so a binary black/white default is spec-faithful — CSS's initialcoloris effectivelycanvastext. iOS keepsPlatformColor('label'), a first-class dynamic color that already tracks the system appearance.Why the media-query form: the root observable already evaluates each seeded value's media query against the reactive
colorSchemeobservable (native/conditions/media-query.ts), so[["#FFFFFF", darkMQ], ["#000000"]]is scheme-reactive for free — the same mechanismlight-dark()andprefers-color-schemerules use — rather than a second imperativeAppearancesubscription.Test plan
src/__tests__/native/root-color-seed-android.test.tsx(Platform.OS mocked to android — the seed is a module-load side effect and jest-expo defaults to ios):currentcolorwith no ancestor →#000000(light) /#FFFFFF(dark).act(() => colorScheme.set("dark"))re-resolves the same element.box-shadowcurrentcolor) paint with the seed color — the reported symptom.null) falls back to the light default.src/__tests__/native/root-color-seed.test.ios.tsx:PlatformColor('label'); ancestor override still works.src/__tests__/native/root-color-seed-override.test.tsx::root { color }replaces the seed outright, and a scheme-conditioned one overrides it per scheme. This is what makes a hardcoded black/white defensible, and the other files only ever tested an ancestor element. Its own file becauseinjectreplaces a root variable outright and nothing puts it back between tests, so a:root { color }leaks into every later test in the same file.src/__tests__/vendor/tailwind/ring-color-seed.test.tsx(real Tailwind → the runtime, android):ring-2/ring— whose default color iscurrentcolor— paint the concrete seed (#000000light,#FFFFFFdark); an explicitring-red-500still wins. This exercises the reported symptom through actual Tailwind output, not a hand-writtenbox-shadow.Verified red→green: pre-fix, the Android tests resolve to
{ semantic: ["?attr/textColorPrimary", "SystemBaseHighColor"] }; post-fix, concrete colors.To be precise about what that proves and what it does not:
jest-expo's hastedefaultPlatformisios, soPlatformColorValueTypesalways resolves its.ios.jsvariant even withPlatform.OSmocked toandroid. The tests therefore observe the unresolved descriptor rather than Android's{resource_paths: […]}shape, and they are guards on the seed value rather than on the native resolution. The native side is what the emulator run above covers.Why black and white, rather than another theme attribute
The failure is specific to the
?attr/path returningoutValue.dataunchecked.@-prefixed resources go throughResourcesCompat.getColor, which flattens a ColorStateList correctly, and a theme attribute whose value is a plain<color>resolves toTYPE_INT_COLOR_*wheredatareally is ARGB. So?attr/colorForeground— which points atforeground_material_light|darkin AppCompat and Material — would plausibly work and would keep the platform's real foreground across DayNight and custom brand themes, instead of collapsing every theme to pure black or white.I chose the concrete pair because it is what CSS Color 4 specifies for the initial
color(CanvasText), becauseprefers-color-schemeis the only signal the runtime has, and because it matches howlight-dark()already compiles in this repo. But if you would rather keep a platform attribute here,colorForegroundis the candidate and I am happy to switch — it needs a device check I have not run.yarn test,yarn typecheck,yarn eslint, andprettier --checkall pass. (Twobabel/import-plugin suites fail only on Windows — a pre-existing path-separator bug in the plugin, unrelated to this change; they are green on CI.)Follow-up (separate, facebook/react-native)
The deeper RN-layer bug —
ColorPropConverter.resolveThemeAttributereturningoutValue.dataunchecked for ColorStateList attributes (a reference, not a color) — affects anyPlatformColor('?attr/<ColorStateList>')usage and is worth a separate issue in react-native itself.References
ColorPropConverter.resolveThemeAttributereturnsoutValue.datawithout checkingoutValue.type(Kotlin source, commit-pinned) ·PlatformColor?attr/textColorPrimaryis a themed ColorStateList in AppCompat / Material components, which is why the returnedoutValue.datais a reference, not a color.colorSchemeobservable (native/conditions/media-query.ts—prefers-color-scheme→get(colorScheme)), so a media-query-conditioned seed is scheme-reactive with no extra listener.Overlaps with #410
Both edit the same twelve lines of
src/native-internal/root.ts— this one changes the seed, #410 puts the registries behind oneglobalThiskey. They are independent defects with different blast radii, so I have kept them apart; whichever lands first, I will rebase the other onto the composed body.One thing worth knowing before both land, because neither branch's tests can see it.
observable.set()evaluates its read function immediately, so a media-conditioned seed callstestMediaQuery→get(colorScheme)duringroot.ts's module body. Onmainthat never happens, because the seed carries no media query. Under #410 the registry becomes process-global whilecolorSchemeinsrc/native/reactivity.tsdoes not, so the shared seed binds to whichever module copy evaluated first. Measured withjest.resetModules(): the composed pair answers#000000after a second copy sets dark, where this branch alone answers#FFFFFF.That is #410's class of bug rather than this one's — any
@media (prefers-color-scheme: dark) { :root { --x } }in user CSS already hits it under #410 — but this change makes it reachable in every Android app rather than only in stylesheets that happen to use a conditioned root variable. The real fix is to guardreactivity.ts's process-global observables the waystyle-collection.tsandvariables.tsxalready are. Happy to send that first if you would prefer it ahead of either.