Mvvmcross: Cannot await properly when navigate deep on three view models

Created on 29 Oct 2018  路  12Comments  路  Source: MvvmCross/MvvmCross

馃悰 Bug Report

It is not possible to await the navigation result in viewmodel A when navigating on viewmodel B, if the viewmodel B navigate again to viewmodel C.

If I navigate from the viewmodel A to the viewmodel B and I await the result of the viewmodel B, when the viewmodel B navigates to another viewmodel C, the navigation to the viewmodel C starts, buti the await from the viewmodel B in the viewmodel A returns with unexpected null TResult.

Expected behavior

The await in the viewmodel A must await the viewmodel B to Close explicitly.

Reproduction steps

Create an application with 3 viewmodels.

  • Navigate from viewmodel A to viewmodel B with await the result.
  • Navigate again from viewmodel B to viewmodel C and await the result.

Configuration

Version: 6.2.1

Platform:

  • [X] :iphone: iOS
  • [X] :robot: Android
  • [ ] :checkered_flag: WPF
  • [X] :earth_americas: UWP
  • [ ] :apple: MacOS
  • [ ] :tv: tvOS
  • [X] :monkey: Xamarin.Forms
needs-investigation up-for-grabs

Most helpful comment

@symibsoft
I found one more workaround:)
you can override your 2nd view model ViewDestroy like

public override void ViewDestroy(bool viewFinishing = true)
        {
            base.ViewDestroy(false);
        }

All 12 comments

I noticed same bug in my app, as soon as you navigate from ViewModel B to C, B returns the result to A, in this case null.

Configuration
Version: 6.2.1

@symibsoft , @agarciasempere , I've found a workaround. You can just use MvxNavigationViewModel instead of MvxViewModel and it will work. But be aware, it returns null in case of back button press.

@xyashapyx, thank you for the response. I tried your solution but it does not work for me. The issue is the same.

@symibsoft have you changed just one viewModel base class or base class of all view models in your tree?

@xyashapyx, I changed all my viewmodels in order to inherit from MvxNavigationViewModel.

I have a base viewmodel class like this:

public abstract partial class BaseScreenNotify : MvxNavigationViewModel

//with this constructor
public BaseScreenNotify(IMvxLogProvider logProvider, IMvxNavigationService navigationService) : base(logProvider, navigationService)

All my viewmodels are inheriting from that base class.

@xyashapyx, Didn't work for me either, just tried same case as @symibsoft did. Same problem persist. I even noticed on Android that if you put the app on background viewmodel returns null too and you are not able to return result anymore.

@symibsoft , @agarciasempere, I don't know if it is a case but all my commands that are invoking navigation declared like:
public IMvxAsyncCommand NavigateCommand => new MvxAsyncCommand(NavigateMethod, allowConcurrentExecutions: true);
Can you try this also?

Hi!
Thank you @xyashapyx but your solution did not solve the issue.

I found a solution but only on android platform.
Before I had the MainApplication class inheriting from MvxAppCompatApplication.
I changed that in order to inherit from MvxAndroidApplication and on android I solved the issue.

I can't find a solution for the UWP implementation. Now I'm inheriting my UWP app class from MvxApplication.

@symibsoft
I found one more workaround:)
you can override your 2nd view model ViewDestroy like

public override void ViewDestroy(bool viewFinishing = true)
        {
            base.ViewDestroy(false);
        }

@symibsoft
I found one more workaround:)
you can override your 2nd view model ViewDestroy like

public override void ViewDestroy(bool viewFinishing = true)
        {
            base.ViewDestroy(false);
        }

Save me day, works perfectly for me.

Thanks.

@symibsoft
I found one more workaround:)
you can override your 2nd view model ViewDestroy like

public override void ViewDestroy(bool viewFinishing = true)
{
base.ViewDestroy(false);
}

Also works for me. Thanks!

Thank you guys, I solved with your suggestion.

The viewdestroy override solved the problem in windows platform. I leave the android platform without this override.

Was this page helpful?
0 / 5 - 0 ratings