From cc7095ce487625a9a0a9b99b4b8df4043698eb78 Mon Sep 17 00:00:00 2001 From: Eric Rozell Date: Wed, 27 Oct 2021 10:10:23 -0400 Subject: [PATCH] Conditionally fires `onDismiss` when receiving `ContentDialogResult::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 --- ...ative-windows-c861660c-275f-4282-80bc-e84dfaeadf04.json | 7 +++++++ vnext/Microsoft.ReactNative/Modules/AlertModule.cpp | 7 +++++-- 2 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 change/react-native-windows-c861660c-275f-4282-80bc-e84dfaeadf04.json diff --git a/change/react-native-windows-c861660c-275f-4282-80bc-e84dfaeadf04.json b/change/react-native-windows-c861660c-275f-4282-80bc-e84dfaeadf04.json new file mode 100644 index 00000000000..b0423aa9043 --- /dev/null +++ b/change/react-native-windows-c861660c-275f-4282-80bc-e84dfaeadf04.json @@ -0,0 +1,7 @@ +{ + "type": "prerelease", + "comment": "Conditionally fires `onDismiss` when receiving `ContentDialogResult::None`", + "packageName": "react-native-windows", + "email": "erozell@outlook.com", + "dependentChangeType": "patch" +} diff --git a/vnext/Microsoft.ReactNative/Modules/AlertModule.cpp b/vnext/Microsoft.ReactNative/Modules/AlertModule.cpp index efab85b2073..a7074d553f0 100644 --- a/vnext/Microsoft.ReactNative/Modules/AlertModule.cpp +++ b/vnext/Microsoft.ReactNative/Modules/AlertModule.cpp @@ -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 &asyncOp, winrt::AsyncStatus status) { switch (asyncOp.GetResults()) { case xaml::Controls::ContentDialogResult::Primary: @@ -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;