Skip to content

Commit 24d1752

Browse files
TatianaKaposYajur-Grover
authored andcommitted
[Fabric] Use PopupWindowSiteBridge for Modal when USE_EXPERIMENTAL_WINUI3 is true (microsoft#14284)
* add modal implementation with PopupWindowSiteBridge * Change files * add conditional * feedback
1 parent 8487656 commit 24d1752

File tree

3 files changed

+62
-15
lines changed

3 files changed

+62
-15
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "prerelease",
3+
"comment": "add modal implementation with PopupWindowSiteBridge",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

vnext/Microsoft.ReactNative/Fabric/Composition/Modal/WindowsModalHostViewComponentView.cpp

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
5555
m_window.Destroy();
5656
m_window = nullptr;
5757
}
58+
59+
#ifdef USE_EXPERIMENTAL_WINUI3
60+
if (m_popUp) {
61+
m_popUp.Close();
62+
m_popUp = nullptr;
63+
}
64+
#endif
5865
}
5966

6067
void InitializePortalViewComponent(
@@ -122,7 +129,6 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
122129
private:
123130
void OnMounted(const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
124131
m_mounted = true;
125-
126132
if (m_showQueued) {
127133
ShowOnUIThread(view);
128134
}
@@ -179,6 +185,24 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
179185
m_showQueued = false;
180186
EnsureModalCreated(view);
181187

188+
#ifdef USE_EXPERIMENTAL_WINUI3
189+
if (m_popUp) {
190+
m_bridge.Enable();
191+
m_popUp.Show();
192+
193+
auto navHost = winrt::Microsoft::UI::Input::InputFocusNavigationHost::GetForSiteBridge(
194+
m_popUp.as<winrt::Microsoft::UI::Content::IContentSiteBridge>());
195+
auto result = navHost.NavigateFocus(winrt::Microsoft::UI::Input::FocusNavigationRequest::Create(
196+
winrt::Microsoft::UI::Input::FocusNavigationReason::First));
197+
198+
// dispatch onShow event
199+
if (auto eventEmitter = EventEmitter()) {
200+
::Microsoft::ReactNativeSpecs::ModalHostViewEventEmitter::OnShow eventArgs;
201+
eventEmitter->onShow(eventArgs);
202+
}
203+
}
204+
#endif
205+
182206
if (m_window && !m_window.IsVisible()) {
183207
m_bridge.Enable();
184208
m_window.Show(true);
@@ -203,6 +227,12 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
203227
m_window.Hide();
204228
}
205229

230+
#ifdef USE_EXPERIMENTAL_WINUI3
231+
if (m_popUp) {
232+
m_popUp.Hide();
233+
}
234+
#endif
235+
206236
// dispatch onDismiss event
207237
if (auto eventEmitter = EventEmitter()) {
208238
::Microsoft::ReactNativeSpecs::ModalHostViewEventEmitter::OnDismiss eventArgs;
@@ -225,6 +255,11 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
225255
return;
226256
}
227257

258+
#ifdef USE_EXPERIMENTAL_WINUI3
259+
if (m_popUp) {
260+
return;
261+
}
262+
#endif
228263
// get the root hwnd
229264
m_prevWindowID =
230265
winrt::Microsoft::ReactNative::ReactCoreInjection::GetTopLevelWindowId(view.ReactContext().Properties());
@@ -356,6 +391,9 @@ struct ModalHostView : public winrt::implements<ModalHostView, winrt::Windows::F
356391
winrt::Microsoft::ReactNative::IComponentState m_state{nullptr};
357392
winrt::Microsoft::UI::Content::DesktopChildSiteBridge m_bridge{nullptr};
358393
winrt::Microsoft::ReactNative::ReactNativeIsland m_reactNativeIsland{nullptr};
394+
#ifdef USE_EXPERIMENTAL_WINUI3
395+
winrt::Microsoft::UI::Content::PopupWindowSiteBridge m_popUp{nullptr};
396+
#endif
359397
};
360398

361399
void RegisterWindowsModalHostNativeComponent(

vnext/Microsoft.ReactNative/Fabric/Composition/ReactNativeIsland.cpp

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -913,21 +913,23 @@ winrt::Microsoft::UI::Content::ContentIsland ReactNativeIsland::Island() {
913913
}
914914
});
915915
#ifdef USE_EXPERIMENTAL_WINUI3
916-
m_islandConnectedToken = m_island.Connected(
917-
[weakThis = get_weak()](
918-
winrt::IInspectable const &, winrt::Microsoft::UI::Content::ContentIsland const &island) {
919-
if (auto pThis = weakThis.get()) {
920-
pThis->OnMounted();
921-
}
922-
});
916+
if (!m_isFragment) {
917+
m_islandConnectedToken = m_island.Connected(
918+
[weakThis = get_weak()](
919+
winrt::IInspectable const &, winrt::Microsoft::UI::Content::ContentIsland const &island) {
920+
if (auto pThis = weakThis.get()) {
921+
pThis->OnMounted();
922+
}
923+
});
923924

924-
m_islandDisconnectedToken = m_island.Disconnected(
925-
[weakThis = get_weak()](
926-
winrt::IInspectable const &, winrt::Microsoft::UI::Content::ContentIsland const &island) {
927-
if (auto pThis = weakThis.get()) {
928-
pThis->OnUnmounted();
929-
}
930-
});
925+
m_islandDisconnectedToken = m_island.Disconnected(
926+
[weakThis = get_weak()](
927+
winrt::IInspectable const &, winrt::Microsoft::UI::Content::ContentIsland const &island) {
928+
if (auto pThis = weakThis.get()) {
929+
pThis->OnUnmounted();
930+
}
931+
});
932+
}
931933
#endif
932934
}
933935
return m_island;

0 commit comments

Comments
 (0)