Files
Alex Hunt a4581ecd8b Fix/simplify invariant for ColorSchemeName, align manual typedef (#53397)
Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/53397

This is a runtime behaviour fix and an API change to `Appearance.setColorScheme`, motivated by a user report where providing `'unspecified'` (valid) to this function would trigger an incorrect invariant throw. Furthermore, there is already a [first party use](https://github.com/facebook/react-native/blob/aec35b896053d9372ccdaf67c939b2eb216d3455/packages/react-native/Libraries/Utilities/Appearance.js#L101) where we call `Appearance.setColorScheme('unspecified')`.

**Changes**

- `Appearance.d.ts` (current public API, manual types): Fix `ColorSchemeName` type to include `'unspecified'` value, and narrow to remove nullability — aligning with existing Flow source for this type in `NativeAppearance`.
- `Appearance.js` (implementation): Fix the invariant throw by **removing it**, and instead narrowing the input type to non-nullable. Redundant work in `getState` and `getColorScheme` is removed.

Changelog: [General][Breaking] `Appearance.setColorScheme` no longer accepts a nullable value

Reviewed By: andrewdacenko

Differential Revision: D80705652

fbshipit-source-id: cf221a33447606653050d471ca2d0347ab30db81
2025-08-29 11:42:14 -07:00
..