Skip to content

Commit

Permalink
fix: Workaround XAML bug with ComboBox and dark theme (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
christophpurrer committed Mar 15, 2022
1 parent b823b7b commit 20cac25
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
15 changes: 15 additions & 0 deletions windows/ReactNativePicker/ReactPickerView.cpp
Expand Up @@ -8,6 +8,7 @@

#include <winrt/Windows.Foundation.Metadata.h>
#include <UI.Xaml.Input.h>
#include <UI.Xaml.Media.h>

namespace winrt {
using namespace Microsoft::ReactNative;
Expand Down Expand Up @@ -50,6 +51,20 @@ namespace winrt::ReactNativePicker::implementation {
winrt::FocusManager::TryFocusAsync(comboBox, winrt::FocusState::Programmatic);
}
});

// Workaround XAML bug with ComboBox and dark theme. Same as:
// https://github.com/microsoft/microsoft-ui-xaml/issues/2331
m_dropDownOpenedRevoker = this->DropDownOpened(winrt::auto_revoke,
[](auto const& sender, auto const& /*args*/) {
auto comboBox = sender.as<xaml::Controls::ComboBox>();
if (comboBox.XamlRoot()) { // XamlRoot added in 19H1
auto comboBoxAsFrameworkElement = comboBox.XamlRoot().Content().try_as<xaml::FrameworkElement>();
auto popups = xaml::Media::VisualTreeHelper::GetOpenPopupsForXamlRoot(comboBox.XamlRoot());
for (auto const& popup : popups) {
popup.Child().as<xaml::FrameworkElement>().RequestedTheme(comboBoxAsFrameworkElement.ActualTheme());
}
}
});
}

void ReactPickerView::UpdateProperties(winrt::IJSValueReader const& reader) {
Expand Down
1 change: 1 addition & 0 deletions windows/ReactNativePicker/ReactPickerView.h
Expand Up @@ -25,6 +25,7 @@ namespace winrt::ReactNativePicker::implementation {
xaml::Media::Brush m_comboBoxColor{ nullptr };
xaml::Controls::ComboBox::SelectionChanged_revoker m_selectionChangedRevoker{};
xaml::Controls::ComboBox::DropDownClosed_revoker m_dropDownClosedRevoker{};
xaml::Controls::ComboBox::DropDownOpened_revoker m_dropDownOpenedRevoker{};

void RegisterEvents();
void RepopulateItems(winrt::Microsoft::ReactNative::JSValueArray const& items);
Expand Down

0 comments on commit 20cac25

Please sign in to comment.