Skip to content

Commit

Permalink
Make appearanceChanged event consistent with Android/iOS (#13499)
Browse files Browse the repository at this point in the history
* Make appearanceChanged event consistent with Android/iOS

On Android and iOS, the `appearanceChanged` global event has an object
payload where the updated dark/light string value is nested as a property.

This makes Windows consistent with iOS and Android.

* Change files

* yarn format
  • Loading branch information
rozele authored Jul 26, 2024
1 parent 42da4ff commit 2466bb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Make appearanceChanged event consistent with Android/iOS",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
2 changes: 1 addition & 1 deletion vnext/Microsoft.ReactNative/Modules/AppearanceModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void Appearance::RequeryTheme() noexcept {
auto oldTheme = winrt::unbox_value_or<ApplicationTheme>(oldThemeBoxed, ApplicationTheme::Light);

if (oldTheme != theme) {
appearanceChanged(ToString(theme));
appearanceChanged({ToString(theme)});
}
}

Expand Down
8 changes: 7 additions & 1 deletion vnext/Microsoft.ReactNative/Modules/AppearanceModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<Appearance> {
using ApplicationTheme = xaml::ApplicationTheme;
Expand All @@ -31,7 +37,7 @@ struct Appearance : std::enable_shared_from_this<Appearance> {
void removeListeners(double count) noexcept;

REACT_EVENT(appearanceChanged);
std::function<void(std::string const &)> appearanceChanged;
std::function<void(AppearanceChangeArgs const &)> 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;
Expand Down

0 comments on commit 2466bb9

Please sign in to comment.