Prism icon indicating copy to clipboard operation
Prism copied to clipboard

[BUG] iOS CanNavigate method from IConfirmNavigation not called when using Navbar back button

Open christian-strydom opened this issue 11 months ago • 11 comments

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: Image

Android: Image

iOS: Image

Please let me know if you require any additional information

Steps to Reproduce

  1. Clone the repository

  2. Run the app on an iPhone or iPhone simulator

  3. Tap on the "Go to child page" button

  4. Tap on the navbar back button Result: You'll be navigated back immediately

  5. Run the app on Android or Windows device

  6. Tap on the go to child page button

  7. 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


christian-strydom avatar Feb 12 '25 09:02 christian-strydom

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.

nrmiller avatar Feb 22 '25 23:02 nrmiller

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"

munkii avatar Feb 24 '25 16:02 munkii

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.

brianlagunas avatar Feb 24 '25 16:02 brianlagunas

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.

munkii avatar Feb 24 '25 16:02 munkii

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.

brianlagunas avatar Feb 24 '25 16:02 brianlagunas

Thank you for taking the time Brian, much appreciated 🙏

christian-strydom avatar Feb 26 '25 06:02 christian-strydom

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.

munkii avatar Mar 21 '25 21:03 munkii

Are there any updates on this issue? We are using the latest prerelease and it is still not working.

KonstantinKellermann avatar May 14 '25 12:05 KonstantinKellermann

There are no updates. When there is an update, it will be shared here.

brianlagunas avatar May 15 '25 23:05 brianlagunas

@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

munkii avatar May 16 '25 08:05 munkii

There is always something with MAUI that needs fixing. Is there any workaround in the meantime?

pasha-o avatar Jun 10 '25 05:06 pasha-o