Skip to content

Set the media features from the iOS and Android color scheme - #60125

Open
intergalacticspacehighway wants to merge 2 commits into
media-queries-1-corefrom
media-queries-2-platforms
Open

intergalacticspacehighway wants to merge 2 commits into
media-queries-1-corefrom
media-queries-2-platforms

Conversation

@intergalacticspacehighway

@intergalacticspacehighway intergalacticspacehighway commented Nov 18, 2026 •

Copy link
Copy Markdown
Collaborator

Summary:

This is PR 2 of 3 (RFC). Stack: #60124 (core) → this PR → #60126 (types and example).

This PR connects the platform color scheme to the media features from PR 1. On both platforms, the first value is set before the first surface starts, so the first render already uses it. Each later change calls setMediaFeatures, which commits each surface. Conditional styles use the same color scheme as useColorScheme(), including the app's overrides.

  • iOS:
    • RCTSurfacePresenter sends the color scheme to Fabric (-[RCTScheduler setMediaFeatures:]): once at start, then on each RCTUserInterfaceStyleDidChangeNotification.
    • It reads the scheme with RCTColorSchemePreference, the same function as RCTAppearance, so the app's appearance settings (such as RCTOverrideAppearancePreference) apply.
    • RCTColorSchemePreference moves unchanged from React-CoreModules to React-Core (React/Modules/RCTAppearancePreference), so Fabric needs no new pod dependency. This is the same split as RCTI18nUtil. RCTAppearance.h imports the new header, so existing imports still work.
  • Android:
    • Fabric starts with the current uiMode.
    • AppearanceModule sends each new color scheme, including the app's OverrideColorScheme, to the new FabricUIManager.setMediaFeatures (@UnstableReactNativeAPI).

Appearance.setColorScheme() works on both platforms, because it changes the window style (iOS) or the activity configuration (Android).

Changelog:

[IOS] [ADDED] - Conditional style values follow the color scheme.
[ANDROID] [ADDED] - Conditional style values follow the color scheme.

Test Plan:

  • gh pr checkout 60126 (includes all 3 PRs), build RNTester on Android and iOS, and open Media Queries.
  • The conditional styles follow system scheme changes, Appearance.setColorScheme(), and native overrides (OverrideColorScheme, RCTOverrideAppearancePreference) with no React render, and match useColorScheme().
Light Dark
Android image image
iOS image image

fabricUIManager,
eventBeatManager,
componentFactory,
UiModeUtils.isDarkMode(context.currentActivity ?: context),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think context.currentActivity is still null here when the app starts, because the activity is attached to the context a bit later. If so, this reads the app's color scheme, not the activity's one.

These can differ when the app forces a theme with AppCompatDelegate.setDefaultNightMode() (for example an in-app "dark mode" setting). useColorScheme() reads the activity first, so it could say dark while conditional styles show light, until the next configuration change.

I haven't tried it on a device. Maybe we could send the color scheme again once the activity is available (for example in FabricUIManager.onHostResume)?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, confirmed it on the emulator. Fixed in 94fbf0c. The start value now also reads the app's night mode (AppCompatDelegate.getDefaultNightMode()), and AppearanceModule sends the color scheme again on resume, so it matches useColorScheme().

// Register as a listener for color scheme changes if override is provided
overrideColorScheme?.addSchemeChangeListener(schemeChangeListener)
// The renderer starts from `uiMode`, so send the override.
overrideColorScheme?.let { updateMediaFeatures(it.getScheme()) }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AppearanceModule is only created when something uses it (lazy).

So if an app stops using Appearance / useColorScheme() (which this feature allows), this line may not run until the first configuration change, and the override would be ignored until then.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, confirmed it with an app that doesn't use Appearance. A forced theme now works without the module, since the start value reads the night mode via AppCompatDelegate.getDefaultNightMode(). Fixed in 94fbf0c.

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

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. p: Expo Partner: Expo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants