Skip to content

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

@christian-strydom

Description

@christian-strydom

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


Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions