diff --git a/change/react-native-windows-bdd93326-988c-4313-b50d-26ae62117088.json b/change/react-native-windows-bdd93326-988c-4313-b50d-26ae62117088.json new file mode 100644 index 00000000000..5ad6a860adf --- /dev/null +++ b/change/react-native-windows-bdd93326-988c-4313-b50d-26ae62117088.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Make appearanceChanged event consistent with Android/iOS", + "packageName": "react-native-windows", + "email": "erozell@outlook.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Modules/AppearanceModule.cpp b/vnext/Microsoft.ReactNative/Modules/AppearanceModule.cpp index 00a5eb5a643..fd16f26a606 100644 --- a/vnext/Microsoft.ReactNative/Modules/AppearanceModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/AppearanceModule.cpp @@ -68,7 +68,7 @@ void Appearance::RequeryTheme() noexcept { auto oldTheme = winrt::unbox_value_or(oldThemeBoxed, ApplicationTheme::Light); if (oldTheme != theme) { - appearanceChanged(ToString(theme)); + appearanceChanged({ToString(theme)}); } } diff --git a/vnext/Microsoft.ReactNative/Modules/AppearanceModule.h b/vnext/Microsoft.ReactNative/Modules/AppearanceModule.h index e2c547f9f14..61e09bce701 100644 --- a/vnext/Microsoft.ReactNative/Modules/AppearanceModule.h +++ b/vnext/Microsoft.ReactNative/Modules/AppearanceModule.h @@ -9,6 +9,12 @@ namespace Microsoft::ReactNative { +REACT_STRUCT(AppearanceChangeArgs) +struct AppearanceChangeArgs { + REACT_FIELD(colorScheme) + std::string colorScheme; +}; + REACT_MODULE(Appearance) struct Appearance : std::enable_shared_from_this { using ApplicationTheme = xaml::ApplicationTheme; @@ -31,7 +37,7 @@ struct Appearance : std::enable_shared_from_this { void removeListeners(double count) noexcept; REACT_EVENT(appearanceChanged); - std::function appearanceChanged; + std::function appearanceChanged; // This function allows the module to get the current theme on the UI thread before it is requested by any JS thread static void InitOnUIThread(const Mso::React::IReactContext &context) noexcept;