Prism: [Bug] 7.2.0.1367 breaks call to OnNavigatingTo from INavigationAware.

Created on 29 Jul 2019  路  10Comments  路  Source: PrismLibrary/Prism

Description

I've just upgraded from 7.1.0.431 to 7.2.0.1367. And _I think_ it has broken OnNavigatingTo (but not navigated or from) in our BaseViewModel which implements INavigationAware. I have tested all of these with breakpoints. So our OnNavigatingTo is no longer called to get a parameter when it is needed.

Steps to Reproduce

  1. Run an app with 2 ViewModels, A and B. Make sure B implements INavigationAware
  2. Set a breakpoint in your OnNavigatingTo and OnNavigatedTo methods in ViewModel B
  3. Navigate to a ViewModelB using INavigatiousenService.NavigateAsync
  4. The debugger only breaks in OnNavigatedTo.

Expected Behavior

The debugger should first break in OnNavigatingTo and then OnNavigatedTo.

Actual Behavior

The debugger only breaks in OnNavigatedTo.

Basic Information

  • Version with issue: Prism 7.2.0.1367.
  • Last known good version: Prism 7.1.0.431.
  • Xamarin.Forms version: 4.0.0.540366 and also 4.1.0.618606.
  • IDE: Visual Studio for Mac

Most helpful comment

Prism.Navigation. You can also use IInitialize async if you want to make asynchronous calls inside it.

e.g.

public class ViewModelBase : Prism.Navigation.IInitialize, Prism.Navigation.IInitializeAsync
    {
        public void Initialize(INavigationParameters parameters)
        {
            //Do whatever used to be inside OnNavigatingTo
        }

        public async Task InitializeAsync(INavigationParameters parameters)
        {
            //Do whatever used to be inside OnNavigatingTo inside an async method 
        }
    }

All 10 comments

I believe this is an expected behaviour for this version forward.

I see. Yes it is detailed here: https://github.com/PrismLibrary/Prism/releases/tag/v7.2.0.1367. I will close this now.

Okay I'm trying to understand the release notes above:

After numerous user survey's and interviews it became apparent that the intent of INavigatingAware had been become unclear and that users were actually overwhelmingly asking for a breaking change. INavigatingAware is no longer supported. For those who may be using OnNavigatingTo with INavigationAware this will be most impactful as a behavior change as INavigatingAware has been removed from INavigationAware meaning that it will no longer be called. For those who have implemented INavigatingAware directly you will see a build error. The impact should be minimal by simply renaming all instances of INavigatingAware to Initialize.

I was using INavigationAware (not INavigatingAware - I see the confusion). If this means I am to remove OnNavigatingTo, what do I replace it with? I thought the solution might be IAutoInitialize parameters but that does not seem to work.

I am essentially passing a parameter with GoBackAsync(INavigationParameter param) and without OnNavigatingTo on the ViewModel it goes to, I have no way of grabbing that INavigationParameter. What is the fix here?

Use OnNavigatedTo when calling GoBack

@UnreachableCode keep in mind that INavigationAware was just an aggregate interface. Unfortunately this meant there was no perfect way to make the change we kept having Prism users asking for. While we could mark OnNavigatingTo as Obsolete that means you're forced to implement obsolete code in every new class moving forward when adding INavigationAware.

Thanks for getting back to me guys. @brianlagunas - what if I need a parameter before OnAppearing() in this scenario?

@UnreachableCode hopefuly you've found this by now but for anyone else who comes across this.

Implement the interface IInitialize. The method Initialize(INavigationParameters parameters) takes in the same parameters as OnNavigatingTo() and will be called at the same time when passing a parameter to a ViewModel.

What namespace do I find this interface in? IIitialize?

@UnreachableCode hopefuly you've found this by now but for anyone else who comes across this.

Implement the interface IInitialize. The method Initialize(INavigationParameters parameters) takes in the same parameters as OnNavigatingTo() and will be called at the same time when passing a parameter to a ViewModel.

Prism.Navigation. You can also use IInitialize async if you want to make asynchronous calls inside it.

e.g.

public class ViewModelBase : Prism.Navigation.IInitialize, Prism.Navigation.IInitializeAsync
    {
        public void Initialize(INavigationParameters parameters)
        {
            //Do whatever used to be inside OnNavigatingTo
        }

        public async Task InitializeAsync(INavigationParameters parameters)
        {
            //Do whatever used to be inside OnNavigatingTo inside an async method 
        }
    }

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

brianlagunas picture brianlagunas  路  3Comments

znakeeye picture znakeeye  路  7Comments

tibitoth picture tibitoth  路  5Comments

HartlD picture HartlD  路  3Comments

weitzhandler picture weitzhandler  路  6Comments