Skip to content

fix(native): seed a concrete scheme-aware __rn-css-color on every platform - #392

Open
YevheniiKotyrlo wants to merge 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:fix/root-color-seed
Open

YevheniiKotyrlo wants to merge 1 commit into
nativewind:mainfrom
YevheniiKotyrlo:fix/root-color-seed

Conversation

@YevheniiKotyrlo

@YevheniiKotyrlo YevheniiKotyrlo commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

Problem

A color that falls back to the root __rn-css-color comes out wrong on a device. On Android it is invisible or black wherever it is read; on iOS, border, outline and shadow take the system appearance's variant of label rather than the app's scheme, so an app that forces a scheme the system does not have draws them in the other scheme's color. Tailwind v4's default ring color is currentcolor, so ring, inset-ring, text-current and border-current are the everyday triggers.

Root cause

  • Android. ?attr/textColorPrimary is a ColorStateList, and ColorPropConverter.resolveThemeAttribute returns outValue.data without checking outValue.type, so for a ColorStateList the paint receives a value that is not a color. react/react-native#59606 fixes it from 0.89; 0.88 and earlier carry it.
  • iOS. A semantic UIColor has to be resolved against the view's trait collection. RCTViewComponentView.mm does that for the background alone; its border and outline, and RCTBoxShadow.mm's shadow, read .CGColor, which resolves against the system appearance (react/react-native#57836).

Solution

The seed is color's initial value, CanvasText (CSS Color 4 §3.2), made concrete: black, or white under prefers-color-scheme: dark. The root observable already evaluates a seeded value's media query against colorScheme, so the seed stays reactive with no Platform.OS branch, no as any and no eslint suppression. It sits in seedRootRegistry, so the registries' reset seeds it too. An ancestor's color or a :root color still overrides it.

Tests

  • src/__tests__/native/root-color-seed.test.tsx — each of 13 currentcolor consumers compiles to the root color reference and paints #000000 in a light scheme and #FFFFFF in a dark one, and so does a currentcolor held in a custom property the compiler keeps; no preference, a live scheme change, an ancestor color, a :root color and a scheme-conditioned :root color are pinned as well.
  • src/__tests__/vendor/tailwind/current-color.test.tsx — Tailwind's own currentcolor utilities (text-current, bg-current, border-current, outline-current, decoration-current, caret-current, fill-current, stroke-current, ring, inset-ring, shadow-current, placeholder:text-current) in both schemes, and an explicit ring color over the default.
  • src/__tests__/native/box-shadow.test.tsx — currentcolor resolves to the concrete root seed, and a platformColor() shadow still reaches the shadow as the platform's object.
  • Four suites that pinned the unresolved PlatformColor descriptor for a currentcolor reader now assert the painted color.

On main, 59 cases fail with the PlatformColor seed and all of them pass with this one.

Two expectations follow what main does: it maps border-inline-start-color to borderStartColor, and writes a color-mix() shadow color as rgba().

Verification

A local replica of CI passes every job on this head merged into main, on Node 26.12.1, where .nvmrc pins 24.22.3: lint and typecheck, yarn test --maxWorkers=2 --coverage (2308 passed), the library build with node --test, the web export and commitlint, and the iOS dev build on macOS with Xcode 27.2, where ci.yml pins 26.6.

Device evidence, Android only, from an earlier revision of this fix: #392 (comment)

Open questions

?attr/colorForeground points at a plain <color> in AppCompat and Material, so it would resolve correctly and keep a custom brand theme's foreground instead of pure black or white. I chose the concrete pair because it is what CSS specifies and what light-dark() compiles to here; switching needs a device check I have not run.

Known limits

Merge order

#459, #494 and #498 also change src/native-internal/root.ts, and #489 and #495 src/native/styles/shorthands/box-shadow.ts. #391, #489, #495, #501 and #503 add cases that expect main's PlatformColor seed. Whichever of this PR and each of them lands second resolves the conflict.

@YevheniiKotyrlo

YevheniiKotyrlo commented Aug 18, 2026 •

Copy link
Copy Markdown
Contributor Author

Device evidence — before / after

UNFIXED — The swatch is invisible or black — the seed is a PlatformColor Android cannot resolve to a value.

FIXED — The currentColor swatch is outlined exactly like the control, in the scheme’s foreground.

before — 3.1.0-rc.0 after — with this PR

Android 16 emulator (API 36, GLES on the host GPU), 1140×2400 @ 480dpi, both frames from one run. before is the published 3.1.0-rc.0 plus what my test app needs from my other patches to run: the native and native-internal subpath exports, PR 459, cascade-layer ranking, and a shim that compiles a class-qualified :root inert. after adds the rest of my open PRs, this one included. One of them shows on every screen: PR 417 narrows a var()-valued font-family to one family, so the after sets its text in the theme's face where the before falls back to the platform's.

…tform

The root seed is `color`'s initial value, `CanvasText`: black, or white in
a dark scheme. A semantic `PlatformColor` fallback paints no color from
Android's `?attr/textColorPrimary`, and on iOS a border, outline or shadow
resolves it against the system appearance instead of the app's scheme, so
the seed is a concrete color chosen by the root's own
`prefers-color-scheme` evaluation. The tests pin 13 currentcolor consumers
and Tailwind's own currentcolor utilities on the compile-time and runtime
paths.

This branch has not been deployed

No deployments
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