-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
[XF] IConfirmNavigation and IConfirmNavigationAsync don't work with back button on NavigationPage #900
Comments
While this may be possible when dealing with Modal navigation, I don't know how to do it with non-modal navigation (navigation within a NavigationPage). With modal navigation I could handle the ModalPopping event on the application class, check the interface and then call e.Cancel if false. The NavigationPage does not provide such a capability. I do not want to add a feature have it work in one scenario and not another, so I decided not to implement it at all. Unless someone else has another way, but remember that it must work the same on all supported platforms. |
Thanks, I will do some experimenting myself. BTW, thanks for all your hard work! I just watched your Channel9 on this yesterday, dropped it in to my solution, and threw out tons of my own code. Yours is much better! 👍 |
I think one thing I can do to make your life easier in this scenario is make the method that checks this interface public so that you can easily call it from within your own custom code where it is needed. This would eliminate some headache on your side by using the code in Prism. Right now it is protected, but I can make it public for this scenario: Then you can call it only in the cases where you need it. Would that work? |
I just realized though that when using a NavigationPage the OnBackButtonPressed doesn't get invoked when hitting the software backbutton, so it would only work when users hit the hardware back button. I wonder if there is a way to do this. |
Yeah, looking through the Xamarin.Forms code it looks like we'll need a change to OnBackButtonPressed. I think that would benefit everyone, Prism or no. |
I requested an API change, we will see if it gets accepted. |
Do you think you would find value in making the CanNavigateAsync method I linked to earlier public so that you can at least handle this in your own application code? |
Yes, I think that would be useful, especially if/when Xamarin.Forms ads that API. Thanks! |
You can now use `PageUtilities.CanNavigateAsync' in your custom back button logic. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Package info
Repro steps
When the user clicks the back button on a navigation page, and there are unsaved changes on the current page, I want to prompt the user to save or cancel. I was hoping to use IConfirmNavigationAsync, but it looks like it only works with GoBackAsync() and doesn't get called when the user clicks back (or, I assume, the hardware back button on Android). Any possibility this could be added, and/or any suggested alternative? I suppose I could navigate modally, create my own back button, and override the page's OnBackButtonPressed() but that feels a bit clunkier than what i'm envisoning.
The text was updated successfully, but these errors were encountered: