Skip to content

[native] Fix textShadow parsing and dark-mode fallback for variables - #526

Open
kirawth wants to merge 2 commits into
react:mainfrom
kirawth:fix-native-textshadow-and-dark-vars
Open

kirawth wants to merge 2 commits into
react:mainfrom
kirawth:fix-native-textshadow-and-dark-vars

Conversation

@kirawth

@kirawth kirawth commented Nov 2, 2026

Copy link
Copy Markdown

Two small fixes in the native CSS layer, one commit each.

1. textShadow misparses common valid values

LENGTH_REG (/^[0-9]+[a-zA-Z%]+?$/) only accepted unsigned integers, and the color was assumed to be the last token:

input before
2px -2px color "-2px", height undefined
1px 1px 1.5px color "1.5px", radius undefined
red 1px 2px 3px width "red", height 1, radius 2

CSS allows the color before or after the lengths, and offsets can be negative. The fix:

  • accepts signed and decimal lengths (-?([0-9]*\.)?[0-9]+unit)
  • takes the first non-length token as the color, wherever it appears
  • ignores empty tokens from repeated spaces

2. Variables without a dark value resolve to nothing in dark mode

In resolveVariableReferenceValue, dark mode always read variableValue['@media (prefers-color-scheme: dark)']. Take a variable defined as { default: 'black', '@media (min-width: 400px)': 'gray' }, or any object value without a dark key. In dark mode it resolved to undefined, resolveVariableReferences returned null, and the style property was dropped.

It now uses the dark value only when it's defined (Object.hasOwn). That matches how regular style values handle mqDark in css/index.js.

Test plan

  • New __tests__/parseTextShadow-test.js: color last, color first, functional colors, negative and decimal lengths, repeated whitespace.
  • New __tests__/customProperties-test.js: dark value used when present, default used when absent.

…values

LENGTH_REG only accepted unsigned integers, and the color was assumed to
be the last token. As a result:

- "2px -2px" used "-2px" as the color
- "1px 1px 1.5px" used "1.5px" as the color
- "red 1px 2px 3px" used "red" as offsetX and shifted the other values

Accept signed and decimal lengths, take the first non-length token as the
color wherever it appears, and ignore empty tokens from repeated spaces.
In dark mode, resolveVariableReferenceValue always read the
'@media (prefers-color-scheme: dark)' key. A variable defined without it
resolved to undefined, so the whole style property was dropped.

Only use the dark value when it is defined, matching how regular style
values are resolved in css/index.js.
@meta-cla

meta-cla Bot commented Nov 2, 2026

Copy link
Copy Markdown

Hi @kirawth!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

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