From 2f8f2222dc4dd4c6e00ad9079dca82a4d4af2654 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Tue, 8 Jul 2025 08:56:27 -0700 Subject: [PATCH 1/3] Use `tapOutsideOfPopupCommand` inside `OnBackButtonPressed` --- src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index ebf1a76e75..62e6b04fe0 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -102,10 +102,9 @@ public async Task CloseAsync(PopupResult result, CancellationToken token = defau protected override bool OnBackButtonPressed() { - // Only close the Popup if CanBeDismissedByTappingOutsideOfPopup is true - if (GetCanBeDismissedByTappingOutsideOfPopup(popup, popupOptions)) + if (tapOutsideOfPopupCommand?.CanExecute(null) is true) { - CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget(); + tapOutsideOfPopupCommand.Execute(null); } // Always return true to let the Android Operating System know that we are manually handling the Navigation request from the Android Back Button From de8a9b1eed7a8fd013677378453250361baea9aa Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Tue, 8 Jul 2025 09:03:32 -0700 Subject: [PATCH 2/3] Add Comments --- src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index 62e6b04fe0..18a4fbbeb2 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -102,7 +102,9 @@ public async Task CloseAsync(PopupResult result, CancellationToken token = defau protected override bool OnBackButtonPressed() { - if (tapOutsideOfPopupCommand?.CanExecute(null) is true) + // When the Android Back Button is tapped, we only close the Popup if the tapOutsideOfPopupCommand can execute + // In other words, we'll only close the Popup when CanBeDismissedByTappingOutsideOfPopup is true + if (tapOutsideOfPopupCommand.CanExecute(null)) { tapOutsideOfPopupCommand.Execute(null); } From 6e8cf4659b2661c13202c311b4eb5891358b94b3 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Tue, 8 Jul 2025 09:07:50 -0700 Subject: [PATCH 3/3] Remove unused field --- src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index 18a4fbbeb2..3d4e263442 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -24,7 +24,6 @@ public PopupPage(View view, IPopupOptions popupOptions) partial class PopupPage : ContentPage, IQueryAttributable { readonly Popup popup; - readonly IPopupOptions popupOptions; readonly Command tapOutsideOfPopupCommand; public PopupPage(View view, IPopupOptions popupOptions) @@ -39,7 +38,6 @@ public PopupPage(Popup popup, IPopupOptions popupOptions) ArgumentNullException.ThrowIfNull(popupOptions); this.popup = popup; - this.popupOptions = popupOptions; tapOutsideOfPopupCommand = new Command(async () => {