Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(android): ensure Appearance change listener does not skip events (#…
…46017) Summary: I'm able to reproduce a case when Appearance module methods are called in the following order: starting point: dark mode enabled 1. call `setColorScheme` light 2. call `getColorScheme`, which sets `colorScheme` to light [here](https://github.com/facebook/react-native/blob/7bb7a6037bd78bbfa6d9e8499973ea921e9c70e1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt#L57) 3. [onConfigurationChanged](https://github.com/facebook/react-native/blob/7bb7a6037bd78bbfa6d9e8499973ea921e9c70e1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/modules/appearance/AppearanceModule.kt#L82) is called but `if (colorScheme != newColorScheme)` does not evaluate to true, so no event is dispatched to JS. That means JS is not in sync with the native state. The issue was the `getColorScheme` had a side-effect of setting `colorScheme` private member (not sure what its use was). The fix remembers the last emitted color scheme value and emits event if new value is different. ## Changelog: [ANDROID] [FIXED] - ensure Appearance change listener does not skip events Pull Request resolved: #46017 Test Plan: tested locally with RN tester Reviewed By: NickGerleman Differential Revision: D62016949 Pulled By: cipolleschi fbshipit-source-id: b7b5755d38becda655cf376749d9a996daff7e07
- Loading branch information