Repository navigation
Add conditional style values and update them when the color scheme changes - #60124
Open
intergalacticspacehighway wants to merge 1 commit into
Open
intergalacticspacehighway wants to merge 1 commit into
intergalacticspacehighway wants to merge 1 commit into
Conversation
This was referenced Nov 18, 2026
intergalacticspacehighway
force-pushed
the
media-queries-1-core
branch
from
November 18, 2026 18:25
8f316e8 to
8709462
Compare
This was referenced Nov 18, 2026
intergalacticspacehighway
marked this pull request as ready for review
November 19, 2026 05:18
intergalacticspacehighway
force-pushed
the
media-queries-1-core
branch
from
November 19, 2026 05:22
8709462 to
27d4268
Compare
meta-codesync Bot
pushed a commit
that referenced
this pull request
Nov 19, 2026
## Summary: On Android, `TextInput` keeps `fontWeight` as a string. So `TextInput.js` changes a numeric `fontWeight` (for example `700`) to a string before it sends the props. The commit that added this ([15f27bc](15f27bc299a)) calls it "a quick and dirty replication" of the `Text.js` logic, to fix later for Fabric. This PR makes the native code accept a number too: - **C++** (`AndroidTextInputProps`): a number becomes a string, in the classic parser and in the iterator setter. - **Kotlin** (`ReactTextInputManager.setFontWeight`): the setter takes a `Dynamic`, so the raw props path also accepts a number. This changes the public signature from `String?` to `Dynamic`. The JS conversion stays, so a new JS bundle still works with an older native build. A follow-up PR removes it after this change ships. This also makes a numeric `fontWeight` work in a conditional style value ([RFC](react-native-community/discussions-and-proposals#1010), #60124), because the JS conversion cannot see inside one. ## Changelog: [ANDROID] [CHANGED] - `TextInput` accepts a numeric `fontWeight` in native code. ## Test Plan: - New Kotlin test: `ReactTextInputPropertyTest.testFontWeightAcceptsANumber`. - RNTester on the Android emulator, with the JS conversion removed locally so the number reaches native: a `TextInput` with a numeric `fontWeight` renders with no errors in each combination of the props flags (Props 1.5, Props 2.0, exclusive props updates, the C++ iterator setter). - `./gradlew :packages:react-native:ReactAndroid:testDebugUnitTest --tests ReactTextInputPropertyTest`: pass. Differential Revision: D133209822 Pull Request resolved: #60136
This branch has not been deployed
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:
This is PR 1 of 3 for native media queries (RFC). Stack: this PR → #60125 (platforms) → #60126 (types and example).
Currently, a style that depends on the color scheme needs
useColorScheme(). A scheme change then renders React again, often for large parts of the app. With this PR, a style value can carry its own conditions declaratively, and a native commit applies them without a React render:The last matching condition wins, otherwise
defaultis used. Onlyprefers-color-schemeis supported. The design leaves room forwidth/heightlater.How it works
ReactNativeAttributePayloadsends a conditional value of a core style prop as{$conditionalValue: {default, conditions}}and adds$hasConditionalValues: trueto the payload. Other props are not changed.ConcreteComponentDescriptor::clonePropscallsresolveConditionalValuesbefore it parses the props. Every parse path (classic, iterator setter, AndroidrawProps) gets plain values. The props keep a small record: the conditions, the media features they read, and the features they were resolved for (resolvedFor).UIManager::setMediaFeaturessets aMediaFeaturesStore(one per instance, in theContextContainer) and makes an empty commit on each surface. In every commit,ShadowTree::tryCommitfinds views whose record is outdated and sends their stored conditions throughclonePropsagain. This runs before the commit hooks and layout. It also fixes older nodes that React commits again after a change.ChildrenHaveConditionalValues) limits the walk to subtrees that have conditional values. A view is cloned only if a feature it reads changed.Cost (measured, Release build on a Mac):
hasPropertycheck percloneProps(about 0.05 µs), and a check in each commit. A whole commit of 1000 views without conditional values, with this check, took about 0.35 µs.Changelog:
[GENERAL] [ADDED] - Style values can depend on
@media (prefers-color-scheme).Test Plan:
gh pr checkout 60126(the PR 3 branch includes all 3 PRs), build RNTester, and open Media Queries. The screenshots are in Set the media features from the iOS and Android color scheme #60125.ConditionalValuesTest,MediaFeaturesTestandUIManagerMediaFeaturesTest; FantomConditionalValues-itest.js,ConditionalValuesReferences-itest.jsandReactNativeAttributePayload-itest.js../gradlew :private:react-native-fantom:testReactCommon,yarn fantom,yarn test,yarn flow-check, ESLint, Prettier and clang-format: pass.