Skip to content

Commit

Permalink
Conditionally fires onDismiss when receiving `ContentDialogResult::…
Browse files Browse the repository at this point in the history
…None` (#8866)

* Conditionally fires `onDismiss` when receiving `ContentDialogResult::None`

When the ContentDialog returns with a result of `None`, and there is no
close button / neutral button option presented to the user, this change
fires an `onDismiss` instead of attempting to fire the
`buttonNeutral.onPress` callback, which is very unlikely to be
registered.

It is very unlikely that RNW apps have leaned on this, but if someone is
depending on the implementation detail of the "neutral" callback being
called without presenting the button (by leaving the text for the
neutral button option null), then this is a minor breaking change.

Fixes #8865

* Change files
  • Loading branch information
rozele authored Oct 27, 2021
1 parent 4b3d6bb commit cc7095c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "prerelease",
"comment": "Conditionally fires `onDismiss` when receiving `ContentDialogResult::None`",
"packageName": "react-native-windows",
"email": "erozell@outlook.com",
"dependentChangeType": "patch"
}
7 changes: 5 additions & 2 deletions vnext/Microsoft.ReactNative/Modules/AlertModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,10 @@ void Alert::ProcessPendingAlertRequests() noexcept {
}
});

const auto hasCloseButton = dialog.CloseButtonText().size() > 0;
auto asyncOp = dialog.ShowAsync();
asyncOp.Completed(
[jsDispatcher, result, this](
[hasCloseButton, jsDispatcher, result, this](
const winrt::IAsyncOperation<xaml::Controls::ContentDialogResult> &asyncOp, winrt::AsyncStatus status) {
switch (asyncOp.GetResults()) {
case xaml::Controls::ContentDialogResult::Primary:
Expand All @@ -116,7 +117,9 @@ void Alert::ProcessPendingAlertRequests() noexcept {
jsDispatcher.Post([result, this] { result(m_constants.buttonClicked, m_constants.buttonNegative); });
break;
case xaml::Controls::ContentDialogResult::None:
jsDispatcher.Post([result, this] { result(m_constants.buttonClicked, m_constants.buttonNeutral); });
jsDispatcher.Post([hasCloseButton, result, this] {
result(hasCloseButton ? m_constants.buttonClicked : m_constants.dismissed, m_constants.buttonNeutral);
});
break;
default:
break;
Expand Down

0 comments on commit cc7095c

Please sign in to comment.