Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fabric] Implement onDismiss for Modal and remove titlebar #14126

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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": "implement onDismiss and remove titlebar from Modal",
"packageName": "react-native-windows",
"email": "[email protected]",
"dependentChangeType": "patch"
}
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ function ModalPresentation() {
key="onDismiss"
style={styles.option}
label="onDismiss ⚫️"
disabled={Platform.OS !== 'ios'}
disabled={Platform.OS !== 'ios' && Platform.OS !== 'windows'}
onPress={() =>
setProps(prev => ({
...prev,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ WindowsModalHostComponentView::WindowsModalHostComponentView(
: Super(compContext, tag, reactContext) {}

WindowsModalHostComponentView::~WindowsModalHostComponentView() {
// dispatch onDismiss event
auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
facebook::react::ModalHostViewEventEmitter::OnDismiss onDismissArgs;
emitter->onDismiss(onDismissArgs);

// reset the topWindowID
if (m_prevWindowID) {
auto host =
Expand Down Expand Up @@ -95,7 +100,7 @@ void WindowsModalHostComponentView::EnsureModalCreated() {
m_hwnd = CreateWindow(
c_modalWindowClassName,
L"React-Native Modal",
WS_OVERLAPPEDWINDOW,
(WS_POPUP),
CW_USEDEFAULT,
CW_USEDEFAULT,
MODAL_MIN_WIDTH,
Expand Down Expand Up @@ -170,6 +175,11 @@ void WindowsModalHostComponentView::HideOnUIThread() noexcept {
SendMessage(m_hwnd, WM_CLOSE, 0, 0);
}

// dispatch onDismiss event
auto emitter = std::static_pointer_cast<const facebook::react::ModalHostViewEventEmitter>(m_eventEmitter);
facebook::react::ModalHostViewEventEmitter::OnDismiss onDismissArgs;
emitter->onDismiss(onDismissArgs);

// enable input to parent
EnableWindow(m_parentHwnd, true);

Expand Down Expand Up @@ -298,7 +308,6 @@ void WindowsModalHostComponentView::AdjustWindowSize() noexcept {
RECT rc;
GetClientRect(m_hwnd, &rc);
RECT rect = {0, 0, (int)xPos, (int)yPos};
AdjustWindowRect(&rect, WS_OVERLAPPEDWINDOW, FALSE); // Adjust for title bar and borders

// set the layoutMetrics
m_layoutMetrics.frame.size = {(float)rect.right - rect.left, (float)rect.bottom - rect.top};
Expand Down Expand Up @@ -326,6 +335,9 @@ void WindowsModalHostComponentView::updateProps(
*std::static_pointer_cast<const facebook::react::ModalHostViewProps>(oldProps ? oldProps : viewProps());
const auto &newModalProps = *std::static_pointer_cast<const facebook::react::ModalHostViewProps>(props);
newModalProps.visible ? m_isVisible = true : m_isVisible = false;
if (!m_isVisible) {
HideOnUIThread();
}
base_type::updateProps(props, oldProps);
}

Expand Down
6 changes: 6 additions & 0 deletions vnext/overrides.json
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,12 @@
"baseFile": "packages/react-native/Libraries/LogBox/UI/LogBoxInspectorStackFrame.js",
"baseHash": "663d3325298404d7c012a6aa53e833eb5fc2ec76"
},
{
"type": "derived",
"file": "src-win/Libraries/Modal/Modal.windows.js",
"baseFile": "packages/react-native/Libraries/Modal/Modal.js",
"baseHash": "6aa04ce4c8fb0c43298fa64f35be8b8b8e21e93f"
},
{
"type": "derived",
"file": "src-win/Libraries/NativeComponent/BaseViewConfig.windows.js",
Expand Down
Loading
Loading