[BUG] iOS CanNavigate method from IConfirmNavigation not called when using Navbar back button
Description
When adding the IConfirmNavigation or IConfirmNavigationAsync to a ViewModel and implementing the CanNavigate / CanNavigateAsync method, the method is not called on iOS when using the NavBar back button. The method is called on Windows and Android when using NavBar back buttons or hardware back button.
Interestingly enough the CanNavigate method is called when explicitly calling navigationService.GoBackAsync() on iOS, it is just the navbar back button on iOS that doesn't call the method.
I have created a sample app that demonstrates the issue, which can be found here
I checked to make sure this isn't a duplicate bug, the only mention I could find is in the discussions here and here
Environment: I've reproduced the issue on the provided sample app on a physical iPhone 14 running iOS 18.1.1 and a simulated iPhone 14 running iOS 17.0
Please see the gifs below demonstrating the issue:
Windows:
Android:
iOS:
Please let me know if you require any additional information
Steps to Reproduce
-
Clone the repository
-
Run the app on an iPhone or iPhone simulator
-
Tap on the "Go to child page" button
-
Tap on the navbar back button Result: You'll be navigated back immediately
-
Run the app on Android or Windows device
-
Tap on the go to child page button
-
Tap on the navbar back button Result: You'll be shown an alert stating that you first need to check the checkbox before you'll be able to navigate back
Platform with bug
.NET MAUI
Affected platforms
iOS
Did you find any workaround?
You can create your own custom titleview with a custom back button that fires a command in the ViewModel, which calls navigationService.GoBackAsync() which will cause the CanNavigate method to be called on iOS as well.
Relevant log output
FWIW, I am running into the same problem. I noticed in your sample that you were using the NavigationPage. Unfortunately, changing this to PrismNavigationPage was not working for me either.
Any updates on this issue? Can anyone from the Prism team give us some suggestions, please
I am guessing it is related to the issue in this Discussion, "When and how to use PrismNavigationPage"
There are no updates to give at this time. We have not had time to look into this. As soon as we have an update it will be provided here.
There are no updates to give at this time. We have not had time to look into this. As soon as we have an update it will be provided here.
Thank you for replying. I'd do something more useful myself if I knew where to start, sorry.
First, we have to run this against our latest packages, because what is available on NuGet is not what is available to our license holders on our private feed as they have access to newer builds. It's possible this could have already been fixed just not available on public NuGet. Then if we do replicate, we have to step through the source on a Mac to find the issue.
Thank you for taking the time Brian, much appreciated 🙏
I've just ran our app against the 9.1.56-pre and the 9.0.539 builds and it still repros in the same way.
IConfirmNavigationAsync.CanNavigateAsync not called in iOS but is called on Android
The following three are called just fine on both platforms
- IDestructible.Destroy
- OnNavigatedFrom
- OnDisappearing
I also get the Debug output
[0:] NavigationPage has encountered an unhandled GoBack. Be sure to inherit from PrismNavigationPage.
Are there any updates on this issue? We are using the latest prerelease and it is still not working.
There are no updates. When there is an update, it will be shared here.
@KonstantinKellermann it is my understanding that there will be no update on this until there is a MAUI change. Currently, the Back button in iOS, on a non-Shell page, does not call the necessary page method for IConfirmNavigationAsync to hook on to.
As @Axemasta mentioned on Discord there is a MAUI PR that is awaiting review, https://github.com/dotnet/maui/pull/14137
There is always something with MAUI that needs fixing. Is there any workaround in the meantime?