Fix Appearance.setColorScheme(null) not resetting color scheme value (#47739)

Summary:
Fixes https://github.com/facebook/react-native/issues/47725

Calling Appearance.setColorScheme(null) or Appearance.setColorScheme(undefined) no longer resets the color scheme useColorScheme returns like on previous rn versions.

## Changelog:

<!-- Help reviewers and the release process by writing your own changelog entry.

Pick one each for the category and type tags:

[ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message

For more details, see:
https://reactnative.dev/contributing/changelogs-in-pull-requests
-->

[GENERAL] [FIXED] - Fix `Appearance.setColorScheme(null)` not resetting color scheme value

Pull Request resolved: https://github.com/facebook/react-native/pull/47739

Test Plan: Repo with a patch ready to test: https://github.com/sangonz193/react-native-color-scheme-patch

Reviewed By: yungsters

Differential Revision: D66230236

Pulled By: cipolleschi

fbshipit-source-id: cc668acb1fde6d30f2706fc0ab7dee5cea1c3b14
This commit is contained in:
Santiago
2025-02-05 14:16:08 +00:00
committed by Nicola Corti
parent 784c0e6734
commit d04b630daa
+3 -1
View File
@@ -105,7 +105,9 @@ export function setColorScheme(colorScheme: ?ColorSchemeName): void {
const {NativeAppearance} = state;
if (NativeAppearance != null) {
NativeAppearance.setColorScheme(colorScheme ?? 'unspecified');
state.appearance = {colorScheme};
state.appearance = {
colorScheme: toColorScheme(NativeAppearance.getColorScheme()),
};
}
}