From 279bda2470ede9e5f114c7bf72a84f74d6fed4f5 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:55:48 -0700 Subject: [PATCH 1/3] Called `Closed` in `override OnBackButtonPressed()` --- src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index fb1c03a075..93949c7135 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -43,11 +43,6 @@ public PopupPage(Popup popup, IPopupOptions popupOptions) // Only set the content if the parent constructor hasn't set the content already; don't override content if it already exists base.Content ??= new PopupPageLayout(popup, popupOptions); - if (Shell.Current is Shell shell) - { - Shell.SetPresentationMode(shell, PresentationMode.ModalNotAnimated); - } - tapOutsideOfPopupCommand = new Command(async () => { popupOptions.OnTappingOutsideOfPopup?.Invoke(); @@ -114,9 +109,10 @@ protected override bool OnBackButtonPressed() { if (popupOptions.CanBeDismissedByTappingOutsideOfPopup) { + popupClosedEventManager.HandleEvent(this, new PopupResult(true), nameof(PopupClosed)); return base.OnBackButtonPressed(); } - + return true; } From 49472e7bfdc3f4facf7fa8f5f19aa97f8289ed7f Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 13 Jun 2025 10:59:32 -0700 Subject: [PATCH 2/3] Use `Close()` --- src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index 93949c7135..e80bdfd39f 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -2,6 +2,7 @@ using System.Globalization; using CommunityToolkit.Maui.Converters; using CommunityToolkit.Maui.Core; +using CommunityToolkit.Maui.Extensions; using Microsoft.Maui.Controls.PlatformConfiguration; using Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific; using Microsoft.Maui.Controls.Shapes; @@ -109,8 +110,7 @@ protected override bool OnBackButtonPressed() { if (popupOptions.CanBeDismissedByTappingOutsideOfPopup) { - popupClosedEventManager.HandleEvent(this, new PopupResult(true), nameof(PopupClosed)); - return base.OnBackButtonPressed(); + CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget(); } return true; From f3484fed8c18539c8256d4971f83d6e4173bf495 Mon Sep 17 00:00:00 2001 From: Brandon Minnick <13558917+TheCodeTraveler@users.noreply.github.com> Date: Fri, 13 Jun 2025 11:45:31 -0700 Subject: [PATCH 3/3] Update PopupPage.shared.cs --- src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs index e80bdfd39f..8cd851161c 100644 --- a/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs +++ b/src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs @@ -104,15 +104,16 @@ public async Task CloseAsync(PopupResult result, CancellationToken token = defau popupClosedEventManager.HandleEvent(this, result, nameof(PopupClosed)); } - - // Prevent the Android Back Button from dismissing the Popup if CanBeDismissedByTappingOutsideOfPopup is true + protected override bool OnBackButtonPressed() { + // Only close the Popup if PopupOptions.CanBeDismissedByTappingOutsideOfPopup is true if (popupOptions.CanBeDismissedByTappingOutsideOfPopup) { CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget(); } + // Always return true to let the Android Operating System know that we are manually handling the Navigation request from the Android Back Button return true; }