Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Fix Crash after closing DesktopPopupSiteBridge",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,26 +35,38 @@ struct ModalHostState
struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::Foundation::IInspectable>,
::Microsoft::ReactNativeSpecs::BaseModalHostView<ModalHostView> {
~ModalHostView() {
if (m_reactNativeIsland) {
m_reactNativeIsland.Island().Close();
}
if (m_popUp) {
// Unregister closing event handler
if (m_appWindow && m_appWindowClosingToken) {
m_appWindow.Closing(m_appWindowClosingToken);
m_appWindowClosingToken.value = 0;
}

// Add AppWindow closing token cleanup
if (m_appWindow && m_appWindowClosingToken) {
m_appWindow.Closing(m_appWindowClosingToken);
m_appWindowClosingToken.value = 0;
}
// Reset topWindowID before destroying
if (m_prevWindowID) {
winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
m_reactContext.Properties().Handle(), m_prevWindowID);
m_prevWindowID = 0;
}

if (m_popUp) {
if (m_departFocusToken && !m_popUp.IsClosed()) {
// WASDK BUG: InputFocusNavigationHost::GetForSiteBridge fails on a DesktopPopupSiteBridge
// https://github.com/microsoft/react-native-windows/issues/14604
/*
auto navHost =
winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteBridge(m_popUp.as<winrt::Microsoft::UI::Content::IContentSiteBridge>());
navHost.DepartFocusRequested(m_departFocusToken);
*/
// Close island
if (m_reactNativeIsland) {
m_reactNativeIsland.Island().Close();
m_reactNativeIsland = nullptr;
}

// Hide popup
if (m_popUp.IsVisible()) {
m_popUp.Hide();
}

// Destroy AppWindow this automatically resumes parent window to receive inputs
if (m_appWindow) {
m_appWindow.Destroy();
m_appWindow = nullptr;
}

// Close bridge
m_popUp.Close();
m_popUp = nullptr;
}
Expand Down Expand Up @@ -88,7 +100,7 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
QueueShow(view);
} else {
m_visible = false;
CloseWindow();
HideWindow();
}
}

Expand Down Expand Up @@ -219,31 +231,27 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
}
}

void CloseWindow() noexcept {
// enable input to parent before closing the modal window, so focus can return back to the parent window
EnableWindow(m_parentHwnd, true);
/*
HideWindow called on visible=false
unmounts the modal window using onDismiss event
*/
void HideWindow() noexcept {
// Hide popup
if (m_popUp) {
m_popUp.Hide();
}

// Unregister closing event handler
if (m_appWindow && m_appWindowClosingToken) {
m_appWindow.Closing(m_appWindowClosingToken);
m_appWindowClosingToken.value = 0;
// Restore message routing to parent
if (m_prevWindowID) {
winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
m_reactContext.Properties().Handle(), m_prevWindowID);
}

// dispatch onDismiss event
// Dispatch onDismiss event
if (auto eventEmitter = EventEmitter()) {
::Microsoft::ReactNativeSpecs::ModalHostViewEventEmitter::OnDismiss eventArgs;
eventEmitter->onDismiss(eventArgs);
}

// reset the topWindowID
if (m_prevWindowID) {
winrt::Microsoft::ReactNative::ReactCoreInjection::SetTopLevelWindowId(
m_reactContext.Properties().Handle(), m_prevWindowID);
m_prevWindowID = 0;
}
}

// creates a new modal window
Expand Down
Loading