Skip to content

Commit

Permalink
Fix Alerts and Flyouts crashing on Windows 10 1809 (RS5) (#13505)
Browse files Browse the repository at this point in the history
* Change files

* add version checks for xamlroot

---------

Co-authored-by: Marlene Cota <1422161+marlenecota@users.noreply.github.com>
  • Loading branch information
juliesaia-vendora and marlenecota authored Jul 31, 2024
1 parent 5c2007f commit 8de5648
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "add version checks for uses of XamlRoot",
"packageName": "react-native-windows",
"email": "julie@vendora.io",
"dependentChangeType": "patch"
}
4 changes: 3 additions & 1 deletion vnext/Microsoft.ReactNative/Modules/AlertModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ void Alert::ProcessPendingAlertRequestsXaml() noexcept {
// https://github.com/microsoft/microsoft-ui-xaml/issues/2331
dialog.Opened([useXamlRootForThemeBugWorkaround](winrt::IInspectable const &sender, auto &&) {
auto contentDialog = sender.as<xaml::Controls::ContentDialog>();
auto popups = xaml::Media::VisualTreeHelper::GetOpenPopupsForXamlRoot(contentDialog.XamlRoot());
auto popups = useXamlRootForThemeBugWorkaround
? xaml::Media::VisualTreeHelper::GetOpenPopupsForXamlRoot(contentDialog.XamlRoot())
: xaml::Media::VisualTreeHelper::GetOpenPopups(xaml::Window::Current());

auto contentAsFrameworkElement = useXamlRootForThemeBugWorkaround
? contentDialog.XamlRoot().Content().try_as<xaml::FrameworkElement>()
Expand Down
41 changes: 25 additions & 16 deletions vnext/Microsoft.ReactNative/Views/FlyoutViewManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,10 @@ void FlyoutShadowNode::createView(const winrt::Microsoft::ReactNative::JSValueOb
}

OnFlyoutClosed(GetViewManager()->GetReactContext(), m_tag, false);
m_xamlRootChangedRevoker.revoke();

if (Is19H1OrHigher()) {
m_xamlRootChangedRevoker.revoke();
}
}
});

Expand Down Expand Up @@ -262,15 +265,17 @@ void FlyoutShadowNode::createView(const winrt::Microsoft::ReactNative::JSValueOb
});

// Set XamlRoot on the Flyout to handle XamlIsland/AppWindow scenarios.
if (auto flyoutBase6 = m_flyout.try_as<winrt::IFlyoutBase6>()) {
if (auto uiManager = GetNativeUIManager(GetViewManager()->GetReactContext()).lock()) {
if (auto xamlRoot = uiManager->tryGetXamlRoot(m_rootTag)) {
flyoutBase6.XamlRoot(xamlRoot);
m_xamlRootChangedRevoker = xamlRoot.Changed(winrt::auto_revoke, [this](auto &&, auto &&) {
if (m_isLightDismissEnabled) {
onDropViewInstance();
}
});
if (Is19H1OrHigher()) {
if (auto flyoutBase6 = m_flyout.try_as<winrt::IFlyoutBase6>()) {
if (auto uiManager = GetNativeUIManager(GetViewManager()->GetReactContext()).lock()) {
if (auto xamlRoot = uiManager->tryGetXamlRoot(m_rootTag)) {
flyoutBase6.XamlRoot(xamlRoot);
m_xamlRootChangedRevoker = xamlRoot.Changed(winrt::auto_revoke, [this](auto &&, auto &&) {
if (m_isLightDismissEnabled) {
onDropViewInstance();
}
});
}
}
}
}
Expand Down Expand Up @@ -403,12 +408,16 @@ winrt::Flyout FlyoutShadowNode::GetFlyout() {
void FlyoutShadowNode::OnShowFlyout() {
AdjustDefaultFlyoutStyle(50000, 50000);
if (m_isFlyoutShowOptionsSupported) {
if (!m_flyout.XamlRoot()) {
LogErrorAndClose("The target view window was closed before flyout could be shown.");
} else if (!m_targetElement && m_targetTag > 0) {
LogErrorAndClose("The target view unmounted before flyout could be shown.");
} else if (m_targetElement && m_flyout.XamlRoot() != m_targetElement.XamlRoot()) {
LogErrorAndClose("The target view window lost focus before flyout could be shown.");
if (Is19H1OrHigher()) {
if (!m_flyout.XamlRoot()) {
LogErrorAndClose("The target view window was closed before flyout could be shown.");
} else if (!m_targetElement && m_targetTag > 0) {
LogErrorAndClose("The target view unmounted before flyout could be shown.");
} else if (m_targetElement && m_flyout.XamlRoot() != m_targetElement.XamlRoot()) {
LogErrorAndClose("The target view window lost focus before flyout could be shown.");
} else {
m_flyout.ShowAt(m_targetElement, m_showOptions);
}
} else {
m_flyout.ShowAt(m_targetElement, m_showOptions);
}
Expand Down

0 comments on commit 8de5648

Please sign in to comment.