-
-
Notifications
You must be signed in to change notification settings - Fork 40
Correct OnBackPressed return value #107
Correct OnBackPressed return value #107
Conversation
Looking through the issues, I believe this fixes PrismLibrary/Prism#2815 |
@dansiegel you able to give this a look? |
Ok, been using this some - seems you can't back out of the app with it. |
Ok, hooked the source up to my app to walk through the sequence of events backing out of the app. Ultimately hit the following branch in PageNavigationService.cs:
As of my current checkout, this is lines 139-141. Latest commit here gives |
Ach, we're still not done here. Current symptom is original, but potentially for a different reason - scenario is |
@nabond251 sorry I haven't gotten to this yet. I've been focused more on some net7 stuff and will be to give this a review once I've addressed the net7 bits. |
@dansiegel you're good man, I'm still puzzling on it. Thanks for getting back. |
Ok, tentatively stating this at least seems to work... Not sure how much I like it. There are a few things that make this whole animal difficult. First, we have two events that occur when the Android back button is hit, the MAUI cross-platform back event followed by the corresponding Android back lifecycle event. These should be unified, but they are separate. Second, and dual to the first, we have the one MAUI back event for both the hardware back key and the software back button. These should be distinct, but they are confused. Third, the Android back event handler is synchronous, but the Prism logic for determining if the back navigation can occur is async. Granted, this might not be strictly the case - the main logic is still just whether the page is root, which is a synchronous determination - but even then, this determination happens in the cross-platform logic, notifying the Android handler seems to be an async operation, and again it's a sync handler. The previous attempt of duplicating the logic didn't work, since by the time the Android handler rolled around the nav had already happened so the state was different. All this being the case, this proposed solution effectively discards any use of the Android API in the case of normal back-navigation, and instead handles this more fully in the
First and third items could maybe be dealt with by having a built-in observer of the navigation result that quits the application instead of making My current test is along the simple lines of
I don't know; whole thing's a bit hairy, not much for it. I think I'm going to use this for now, but there very well might be a less-hairy more-elegant solution out there yet. |
try | ||
{ | ||
var result = await MvvmHelpers.HandleNavigationPageGoBack(this).ConfigureAwait(false); | ||
} | ||
catch (NavigationException ex) | ||
{ | ||
backingOut = ex.Message == NavigationException.CannotPopApplicationMainPage; | ||
} |
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.
this should never occur as the NavigationService is meant to catch any exception it encounters and wrap it in the INavigationResult. If we are aren't catching this for some reason it is a bug. Also this wouldn't be where we want to handle the logic to back out as the Navigation Stack may not contain a PrismNavigationPage as the root Page.
I am closing this PR as we have moved the Prism.Maui code to the Prism repo and this repo is being archived. If you would like to pick this back up and submit a PR there we would love to try to get your update into the codebase! |
Seems the MAUI docs aren't abundantly clear here, but comparing with Xamarin's Page.OnBackButtonPressed Method -
So it looks like what was actually intended in the
PrismAppBuilder
's handling of the back button is the reverse of the current implementation. Current behavior is when I am in a page on aNavigationPage
stack and hit back, Android backs out of the entire app. Tested this fix in a workaround reconfiguration ofOnBackPressed
and pressing back behaves as expected.