MvvmCross 5.2

Announcing MvvmCross 5.2!

With the release of 5.2 we focused on creating new presenters who are able to handle almost all navigation patterns for the platform. Since we already had new ones for iOS and MacOS we are now introducing new presenters for Android and WPF! For the next release (5.3) we plan to continue working on this for UWP and Xamarin.Forms. Also a lot of work was done during the .NET Summer Hackfest, where you can read all about in this page.

Updating packages in your solution

As the nuget package MvvmCross.Droid.Shared was no longer exists, please force remove it first, and then update the rest of the packages.

5.2 major changes and improvements

Please read carefully about the changes because some of them are breaking ones, but easy to fix!

A new default Android presenter #1934

The current Android presenter is very limited. Out of the box there is no support for Fragments, Dialogs, or other navigation patterns. To fix this we developed a new presenter which will replace the current one as default. The new presenter supports:

  • Fragments (Nested)
  • Activity’s
  • Dialogs
  • Tabs / ViewPager

Navigation patterns that should be easy to implement with this are:

  • NavigationDrawer
  • BottomNavigationBar
  • BottomSheetDialog
  • Master/Detail Flows
  • Nested navigation

Additionally it adds support for:

  • CustomAnimations per Attribute
  • No dependency on MvxCachingFragmentActivity. All Activities can show Fragments now
  • SharedElement transitions
  • Support for Fragments in default non AppCompat presenter
  • Closing of Dialog, Fragments, and Fragments when Activity closes
  • Override behaviour on runtime with IMvxOverridePresentationAttribute

The new presenter is very easy to customize and extend. If you have an existing custom presenter we would advice to check compatibility and possible replace it with the new default.

Please note that currently there is no caching mechanism for fragments in this ViewPresenter. Its design and scope is still under discussion. Feel free to help us getting it done!

Read more about the new Android ViewPresenter in the documentation

A new default WPF presenter #2124

The new WPF presenter enables to show modal/modal less window. It also changes the signature and some methods.

Read more in the documentation

Same as the previous 5.x releases, we continued improving and fixing our new NavigationService!

Prepare method and close bug fixes #2072

There are breaking changes in the signature to prevent problems with async code. Any navigation done with the NavigationService and a parameter or result will now be triggered in the Prepare method.

Prepare is therefore now part of the ViewModel lifecycle: It runs before the navigation is performed, But please note that all of your starter async code should still be called in Initialize.

public class MyViewModel : MvxViewModel
{
    private readonly IMvxNavigationService _navigationService;
    public MyViewModel(IMvxNavigationService navigationService)
    {
        _navigationService = navigationService ?? throw new ArgumentNullException(nameof(navigationService));
    }

    public override void Prepare()
    {
        // this method is run before the navigation is performed!
    }
    
    public override async Task Initialize()
    {
        //Do heavy work and data loading here
    }

    public async Task SomeMethod()
    {
        var result = await _navigationService.Navigate<NextViewModel, MyObject, MyReturnObject>(new MyObject());
        //Do something with the result MyReturnObject that you get back
    }
}

public class NextViewModel : MvxViewModel<MyObject, MyReturnObject>
{
    private readonly IMvxNavigationService _navigationService;
    public MyViewModel(IMvxNavigationService navigationService)
    {
        _navigationService = navigationService ?? throw new ArgumentNullException(nameof(navigationService));
    }
    
    public override void Prepare(MyObject parameter)
    {
        //Do anything before navigating to the view
        //Save the parameter to a property if you want to use it later
    }
    
    public override async Task Initialize()
    {
        //Do heavy work and data loading here
    }
    
    public async Task SomeMethodToClose()
    {
        await _navigationService.Close(this, new MyReturnObject());
    }
}

This prevents blocking the navigation before showing the view.

Read more in the documentation.

Added support for navigating to ViewModel types #2148

IMvxNavigationService now allows you to navigate to ViewModels by passing the type as a parameter:

_navigationService.Navigate(typeof(MyViewModel));

Support for all primitive types in navigation with parameters #2171

Many more primitive types can be used now as simple parameters when navigating! Read more in the documentation.

MvvmCross.Forms StarterPack #2166

You can now get started on a new Xamarin.Forms app with a set of files to get up to speed. Just install the MvvmCross.Forms.StarterPack nuget package and you are good to go!

Combiners with Fluent Bindings #2143

You can now use Expressions, pass each property individually and even pass an instance of your combiner instead of relying on a string that will retrieve a registered combiner.

Read more in the documentation.

iOS ViewPresenter changes #2093

IMvxTabBarViewController.ShowTabView has been unified. Previously existed two overloads for it:

void ShowTabView(UIViewController viewController, string tabTitle, string tabIconName, string tabSelectedIconName = null, string tabAccessibilityIdentifier = null);

void ShowTabView(UIViewController viewController, string tabTitle, string tabIconName, string tabAccessibilityIdentifier = null);

Both have been replaced by a single method that is much easier to extend:

void ShowTabView(UIViewController viewController, MvxTabPresentationAttribute attribute);

IMvxTextProvider improvements #2150

A method named TryGetText was added to IMvxTextProvider. This allows you to safely get translated values when using JsonLocalization or ResxLocalization plugins.

Ongoing work to clean the samples

During the Hackfest we had a lot of contributions to the samples. This is an ongoing process where anyone including you can help in!

Change Log

5.2 (2017-09-12)

Full Changelog

Fixed bugs:

  • Add initWithCoder: constructor for MvxView #2156
  • New navigation service doesn’t seem to be truly async as opposite to old ShowViewModel() navigation #2071
  • App crash will null reference exception after cancelling sending email #1978
  • Call Close immediately after receiving the return value by NavigationService, view(activity) cannot close itself. #1851
  • Remove unnecessary additions to AndroidViewAssemblies #2170 (Cheesebaron)

Closed issues:

  • Auto-creation of window in MvvmCross Mac now default? #2178
  • MvxAppCompatSetup.cs AndroidViewAssemblies SlidingPaneLayout is not needed #2169
  • Cleanup MvvmCross simple implementation for Droid #2153
  • Display MvxAppCompatDialogFragment as a dialog #2152
  • IMvxPictureChooserTask iOS 10.3 app crash on selecting image from Gallery #2149
  • Support NavigationService by type #2147
  • Mvx 5.x navigation and TabBarViewController #2137
  • MvxAppCompatActivity doesn’t work with IMvxNavigationService #2128
  • Renaming all classes #2123
  • Default bindings for Xamarin Forms #2119
  • Incorrect ViewModel Init() params serialization/deserialization #2116
  • Crash when using a MvxTabBarViewController + Custom Presenter not derived from MvxIosViewPresenter #2112
  • Feedback: (Semantic) Versioning #2107
  • PictureChooser Android Incorrect Rotation #2096
  • ModalViewController dismissed on click native popup #2094
  • MvxTabBarViewController not working anymore without WrapInNavigationController parameter #2084
  • ViewAppearedFirstTime: ViewAppeared() can be called multiple times on iOS #2075
  • Not being able to bind ItemClick in axml or programatically in Droid #2066
  • Navigation to tab bar models seems to be broken for MvvmCross/iOS 5.0.4 onwards #2046
  • iOS - public override async Task Initialize() throws exception on launch #2009
  • ViewModel Life cycle events not called properly when bound to an MvxActivity #2001
  • New presenter for Android #1934
  • NavigationService: Close all Fragments of parent Activity from within fragment ViewModel #1917
  • UWP back button visibility suggestion #1183

Merged pull requests:

5.1.1 (2017-07-28)

Full Changelog

Closed issues:

  • Cannot install the MvvmCross.Forms NuGet package on a fresh/clean Xamarin.Forms project. #2070
  • RaiseCanExecuteChanged on MvxCommand status is not checked again #2064
  • Tabs within fragment breaks on navigation #2055
  • Compilation issues with MvvmCross.StarterPack 5.1.0 #2063
  • new LinkerPleaseInclude.cs.pp (ios) does not compile #2054
  • MvxNavigationService and Linker All does not work #2025
  • Upgrade Analyzers VSIX project to VS2017 #1654

Merged pull requests: