Skip to content

Commit 4fe2d65

Browse files
committed
fix(windows): close modals on light dismiss
The modal Popup's Closed handler was attached with AddHandler(Popup.ClosedEvent, ...), but Popup.Closed is a plain event, not a routed one: Popup.ClosedEvent is undefined, the call threw and the empty catch hid it. Clicking outside a cancelable modal closed the Popup without running the modal's close logic, so the view kept its modal state and the close callback never fired. The handler is now assigned to popup.Closed and cleared with null on close. Also corrects the TextField comment: AddHandler(KeyDownEvent, handler, true) works with a runtime that boxes JS delegates for Object parameters (NativeScript/windows#41); the KeyDown event stays as the fallback for runtimes that can't.
1 parent 298c76d commit 4fe2d65

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

‎packages/core/ui/core/view/index.windows.ts‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1994,8 +1994,8 @@ export class View extends ViewCommon {
19941994
this._closeModalCallback();
19951995
}
19961996
};
1997-
//@ts-ignore
1998-
popup.AddHandler(Microsoft.UI.Xaml.Controls.Primitives.Popup.ClosedEvent, this._modalPopupClosedHandler, true);
1997+
// Popup.Closed is a plain event, not a routed one, so it can't go through AddHandler.
1998+
popup.Closed = this._modalPopupClosedHandler as never;
19991999

20002000
} catch (_e) { }
20012001

@@ -2040,8 +2040,8 @@ export class View extends ViewCommon {
20402040
this._isModalClosing = true;
20412041
try {
20422042
try {
2043-
if (this._modalPopup && this._modalPopupClosedHandler && typeof this._modalPopup.removeEventListener === 'function') {
2044-
try { this._modalPopup.removeEventListener('Closed', this._modalPopupClosedHandler); } catch (_e) { }
2043+
if (this._modalPopup && this._modalPopupClosedHandler) {
2044+
this._modalPopup.Closed = null;
20452045
}
20462046
} catch (_e) { }
20472047

‎packages/core/ui/text-field/index.windows.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ export class TextField extends TextFieldBase {
8383
if (owner) owner.notify({ eventName: TextFieldBase.returnPressEvent, object: owner });
8484
}
8585
});
86-
// AddHandler(KeyDownEvent) throws E_INVALIDARG (0x80070057) in the runtime's RoutedEvent
87-
// projection: an uncaught throw jams frame navigation. Fall back to instance KeyDown.
86+
// handledEventsToo: Enter still arrives when the TextBox handles it. A runtime that can't
87+
// box the handler for AddHandler throws; the KeyDown event is the fallback.
8888
try {
8989
nv.AddHandler(Microsoft.UI.Xaml.UIElement.KeyDownEvent, this._keyDownDelegate, true);
9090
} catch (_e) {

0 commit comments

Comments
 (0)