-
Notifications
You must be signed in to change notification settings - Fork 464
[Popup] Properly handle Android Back Button pressed #2716
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
TheCodeTraveler
merged 8 commits into
main
from
Close-Popup-When-Android-Back-Button-Pressed
Jun 13, 2025
Merged
[Popup] Properly handle Android Back Button pressed #2716
TheCodeTraveler
merged 8 commits into
main
from
Close-Popup-When-Android-Back-Button-Pressed
Jun 13, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR ensures that tapping the Android Back button properly closes the popup by calling CloseAsync() and uses SafeFireAndForget(), so the ShowPopupAsync() task completes as expected.
- Removed the unused
Shell.SetPresentationModeblock in the constructor. - Added
CommunityToolkit.Maui.ExtensionsforSafeFireAndForget. - Updated
OnBackButtonPressedto always callCloseAsync(...)and returntrueinstead of delegating tobase.
Comments suppressed due to low confidence (1)
src/CommunityToolkit.Maui/Views/Popup/PopupPage.shared.cs:113
- Consider adding unit or integration tests for
OnBackButtonPressedto verify thatCloseAsyncis invoked and thatShowPopupAsync()completes when the Android Back button is pressed.
CloseAsync(new PopupResult(true), CancellationToken.None).SafeFireAndForget();
Closed
2 tasks
bijington
reviewed
Jun 13, 2025
bijington
previously approved these changes
Jun 13, 2025
bijington
approved these changes
Jun 13, 2025
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of Change
This PR updates
protected override bool PopupPage.OnBackButtonPressed()to ensure we properly close the Popup usingCloseAsync()when the Android Back Button is tapped by the user.This ensures that the
Taskreturned byShowPopupAsync()completes when the Android Back Button is tapped.Linked Issues
Fixes #2717
Fixes #2700
This fixes the Issue highlighted by @crwsolutions in their comment here: #2703 (comment).
Note: This does not close resolve the issue #2703. We currently unable to reproduce that Issue and are awaiting a sample reproduction to help us solve that Issue.
PR Checklist
approved(bug) orChampioned(feature/proposal)mainat time of PRAdditional information
SafeFireAndForget
Because
protected override bool OnBackButtonPressed()does not return aTask, we are unable to use theawaitkeyword. SincePopupPage.Closereturns aTask, we use.SafeFireAndForget()to ensure we follow best practices and await itsTaskunder the hood.PopupResult
For the
PopupResult, I am settingWasDismissedByTappingOutsideOfPopuptotruefor two reasons:WasDismissedByTappingOutsideOfPopup = falserequiresPopupResult<T>.Resultto be a value provided by the developer when programmatically closing the popup