Skip to content

Commit d7b4b48

Browse files
authored
[Fabric] Implement onDismiss for Modal and remove titlebar (#14126)
* add onDismiss event * remove title bar * Change files * fix lint and snapshots * add option for titlebar * upgrade override
1 parent 253fcf8 commit d7b4b48

File tree

7 files changed

+388
-11
lines changed

7 files changed

+388
-11
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": "implement onDismiss and remove titlebar from Modal",
4+
"packageName": "react-native-windows",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

packages/@react-native-windows/tester/src/js/examples/Modal/ModalPresentation.windows.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ function ModalPresentation() {
214214
key="onDismiss"
215215
style={styles.option}
216216
label="onDismiss ⚫️"
217-
disabled={Platform.OS !== 'ios'}
217+
disabled={Platform.OS !== 'ios' && Platform.OS !== 'windows'}
218218
onPress={() =>
219219
setProps(prev => ({
220220
...prev,

packages/e2e-test-app-fabric/test/__snapshots__/snapshotPages.test.js.snap

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30019,14 +30019,7 @@ exports[`snapshotAllPages Modal 1`] = `
3001930019
},
3002030020
null,
3002130021
null,
30022-
[
30023-
{
30024-
"borderWidth": 0,
30025-
},
30026-
{
30027-
"backgroundColor": "#7676801e",
30028-
},
30029-
],
30022+
null,
3003030023
{
3003130024
"marginRight": 8,
3003230025
"marginTop": 6,

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

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ WindowsModalHostComponentView::WindowsModalHostComponentView(
3434
: Super(compContext, tag, reactContext) {}
3535

3636
WindowsModalHostComponentView::~WindowsModalHostComponentView() {
37+
// dispatch onDismiss event
38+
auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
39+
facebook::react::ModalHostViewEventEmitter::OnDismiss onDismissArgs;
40+
emitter->onDismiss(onDismissArgs);
41+
3742
// reset the topWindowID
3843
if (m_prevWindowID) {
3944
auto host =
@@ -92,10 +97,12 @@ void WindowsModalHostComponentView::EnsureModalCreated() {
9297

9398
m_parentHwnd = GetHwndForParenting();
9499

100+
auto windowsStyle = m_showTitleBar ? WS_OVERLAPPEDWINDOW : WS_POPUP;
101+
95102
m_hwnd = CreateWindow(
96103
c_modalWindowClassName,
97104
L"React-Native Modal",
98-
WS_OVERLAPPEDWINDOW,
105+
windowsStyle,
99106
CW_USEDEFAULT,
100107
CW_USEDEFAULT,
101108
MODAL_MIN_WIDTH,
@@ -170,6 +177,11 @@ void WindowsModalHostComponentView::HideOnUIThread() noexcept {
170177
SendMessage(m_hwnd, WM_CLOSE, 0, 0);
171178
}
172179

180+
// dispatch onDismiss event
181+
auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
182+
facebook::react::ModalHostViewEventEmitter::OnDismiss onDismissArgs;
183+
emitter->onDismiss(onDismissArgs);
184+
173185
// enable input to parent
174186
EnableWindow(m_parentHwnd, true);
175187

@@ -298,7 +310,10 @@ void WindowsModalHostComponentView::AdjustWindowSize() noexcept {
298310
RECT rc;
299311
GetClientRect(m_hwnd, &rc);
300312
RECT rect = {0, 0, (int)xPos, (int)yPos};
301-
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); // Adjust for title bar and borders
313+
314+
if (m_showTitleBar) {
315+
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); // Adjust for title bar and borders
316+
}
302317

303318
// set the layoutMetrics
304319
m_layoutMetrics.frame.size = {(float)rect.right - rect.left, (float)rect.bottom - rect.top};
@@ -326,6 +341,9 @@ void WindowsModalHostComponentView::updateProps(
326341
*std::static_pointer_cast<const facebook::react::ModalHostViewProps>(oldProps ? oldProps : viewProps());
327342
const auto &newModalProps = *std::static_pointer_cast<const facebook::react::ModalHostViewProps>(props);
328343
newModalProps.visible ? m_isVisible = true : m_isVisible = false;
344+
if (!m_isVisible) {
345+
HideOnUIThread();
346+
}
329347
base_type::updateProps(props, oldProps);
330348
}
331349

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ struct WindowsModalHostComponentView
6464
HWND m_hwnd{nullptr};
6565
uint64_t m_prevWindowID;
6666
bool m_isVisible{false};
67+
bool m_showTitleBar{false};
6768
winrt::Microsoft::ReactNative::ReactNativeIsland m_reactNativeIsland;
6869
};
6970

vnext/overrides.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,12 @@
482482
"baseFile": "packages/react-native/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js",
483483
"baseHash": "663d3325298404d7c012a6aa53e833eb5fc2ec76"
484484
},
485+
{
486+
"type": "derived",
487+
"file": "src-win/Libraries/Modal/Modal.windows.js",
488+
"baseFile": "packages/react-native/Libraries/Modal/Modal.js",
489+
"baseHash": "ab5b48312e287809327d494e7a9542f2f178d94b"
490+
},
485491
{
486492
"type": "derived",
487493
"file": "src-win/Libraries/NativeComponent/BaseViewConfig.windows.js",

0 commit comments

Comments
 (0)