Upgrade from 5 to 6
EditThis guide assumes you are using MvvmCross 5.6.x. If you are updating your app from a previous version, please look at the appropiate blog posts.
The very first thing you will notice when upgrading / installing v6 nugets, is that a readme file will open automatically. Please read the readme instructions carefully, and don’t hesitate to jump in and make a PR to improve it if you think anything is missing!
.NET Standard
MvvmCross 6 requires your app to use .NET Standard 2.0 as its base library now. Please make sure you make that upgrade before proceeding!
Names and namespaces changes
As part of the netstandard migration we took the chance to align some names and namespaces. We have massively simplified the solution structure to make it easier to get started with, and also changed some names in order to improve consistency across all platforms.
We know this (sadly) means breaking changes, so here you have a small summary which should help in the process of upgrading:
Extensions vs ExtensionMethods
In the past we had a mix for extension methods between Extensions and ExtensionMethods. All extension classes are now called Extensions.
iOS
Previously we had a mix between iOS and Ios namespaces. We have unified them all to Ios.
Android
As we now don’t have separate projects for each platform’s implementations, we got rid of the Xamarin limitation for naming android projects as “Android” (that’s why the convention of Droid exists!). In summary, we have changed most namespaces that included Droid to Android.
tvOS
Previously we had a mix between tvOS and Tvos namespaces. We have unified them all to Tvos.
UWP
Previously we had a mix between Uwp and Uap namespaces. We have unified them all to Uap.
Xamarin.Forms
MvvmCross.Forms.Platformis nowMvvmCross.Forms.Core.MvvmCross.Forms.{Platform}is nowMvvmCross.Forms.Platforms.{Platform}.
Core and all platforms
MvvmCross.Platformnamespace is nowMvvmCross.- Most framework core classes are now under the namespace
MvvmCross.Base. MvvmCross.Platform.{Platform}.Platformis nowMvvmCross.Platforms.{Platform}.Base.MvvmCross.Binding.{Platform}namespace is nowMvvmCross.Platforms.{Platform}.Binding.MvvmCross.Core.Platform.Convertersnamespace is nowMvvmCross.ConvertersMvvmCross.Core.Platformnamespace is nowMvvmCross.Core.- Platform initialization code (Setup classes, ..) was moved from
MvvmCross.{Platform}.Platformto the namespaceMvvmCross.Platforms.{Platform}.Core. MvvmCross.Platform.{Platform}.Viewsis now under the namespace namespaceMvvmCross.Platforms.{Platform}.Views.Base.MvvmCross.Platform.UInamespace is nowMvvmCross.UI.MvvmCross.Platform.Exceptionsnamespace is nowMvvmCross.Exceptions- All PresentationHints are now at
MvvmCross.Presenters.Hints. MvvmCross.Core.ViewModelsnamespace is nowMvvmCross.ViewModels.MvvmCross.{Platform}.Platformnamespace is nowMvvmCross.Platforms.{Platform}.Core.MvvmCross.{Platform}.ViewModelsnamespace is nowMvvmCross.Platforms.{Platform}.ViewModels.MvvmCross.{Platform}.Viewsnamespace is nowMvvmCross.Platforms.{Platform}.Views.MvvmCross.Core.Viewsnamespace is nowMvvmCross.Views.MvvmCross.Platform.ExtensionMethods.MvxCrossCoreExtensionsclass is nowMvvmCross.Base.MvxCoreExtensions.MvvmCross.Platform.WeakSubscriptionnamespace is nowMvvmCross.WeakSubscription.MvvmCross.Test.Corenamespace is nowMvvmCross.Tests.JetBrains.Annotationsnamespace is nowMvvmCross.Annotations.
IoC
- All IoC related code was moved from
MvvmCross.Platform.IoCtoMvvmCross.IoC. MvxSimpleIoCContaineris nowMvxIoCContainer.
Logging
MvxTrace and everything related was removed in v6. Please take a look at the official documentation to learn about the new logging system.
MvvmCross.Platform.Loggingis nowMvvmCross.Logging.MvvmCross.Core.Platform.LogProvidersnamespace is nowMvvmCross.Platforms.Logging.LogProviders.
Navigation
MvvmCross.Core.Navigationis nowMvvmCross.Navigation.ShowViewModelandMvxNavigatingObjectwere removed.MvxNavigationServiceshould be used instead. Please take a look at the official documentation to learn about it.MvxNavigationServiceAppStartwas removed andMvxAppStartuses the navigation service internally.
Binding
MvvmCross.Binding.{Platform}is now available atMvvmCross.Platforms.{Platform}.Binding.
Commands
All Commands related code was moved from MvvmCross.Core.ViewModels to MvvmCross.Commands.
ViewPresenters
ViewPresenters are now under their own folder. Therefore we had to modify namespaces:
- Presenters code under
MvvmCross.{Platform}.Viewsis now atMvvmCross.Platforms.{Platform}.Presenters MvvmCross.{Platform}.Views.AttributestoMvvmCross.Platforms.{Platform}.Presenters.Attributes
Plugins
All plugin namespaces have changed, but you shouldn’t worry about it unless you are diving deep into their implementations.
- The
Pluginskeyword is nowPlugin. MvvmCross.Plugins.{PluginName}.{Platform}is nowMvvmCross.Plugin.{PluginName}.Platforms.{Platform}MvvmCross.Platform.Pluginsnamespace is nowMvvmCross.Plugin.
Breaking changes
Setup
As part of the Setup improvements, we have removed all parameters from constructors and moved them to a new method: PlatformInitialize.
The SetupSingleton that existed previously only on Android has been extended and it now exists for all platforms.
AppStart
- It is no longer necessary that you call AppStart by yourself. All visual initialization code can now be done by MvvmCross automatically. If you need to provide a hint to it (if you are for example using push notifications), then you just need to override the method
GetAppStartHinton the class where you used to call the code to run the AppStart. In case you need further control over what happens, you can overrideRunAppStart. IMvxAppStarthas a new method:ResetStart()and a new property:bool IsStarted { get; }. If you are using a custom AppStart, then it is recommended that you make it inherit from the brand new base classMvxAppStart, which implements everything by default.- The method
Startis now reserved and managed by the framework. If you are using a custom AppStart you should use the protected methodStartupfrom now on.
Plugins
Color
- On Android, the method
ToAndroidColorwas renamed toToNativeColorin order to match all other platforms.
DownloadCache
DownloadCache was removed in v6.0, as well as MvxImageView and all the related code. Reason being is that there were multiple ancient issues around it and its implementation wasn’t as clean as we would have liked. There are also multiple more efficient alternatives, like FFImageLoading.
ViewPresenters
IMvxOverridePresentationAttribute.PresentationAttributenow takes aMvxViewModelRequestas parameter. If you’re using a custom ViewPresenter that extends the default provided by MvvmCross, be aware thatGetPresentationAttributeandGetOverridePresentationAttributemethods signatures have changed.MvxFormsPagePresenterconstructor now takes a single parameter. You will be affected by this change only if you are using Xamarin Forms and you are providing a custom pages presenter for a platform ViewPresenter.- On iOS, macOS and tvOS the Setup method
CreatePresenterwas renamed toCreateViewPresenter. - On iOS and tvOS, the method
CleanupModalViewControllerswas renamed toCloseModalViewControllers. - The method
NativeModalViewControllerDisappearedOnItsOwnis now calledCloseTopModalViewController. IMvxTvosModalHostandIMvxIosModalHostwere deprecated and removed.- On iOS, the method
PresentModalViewControllerwas renamed toShowModalViewController.
Navigation
IMvxNavigationService.ChangePresentationis now an async method (the method now returns aTask<bool>). It was the only “sync” method on IMvxNavigationService, which was odd.- Two methods were added to the
IMvxNavigationServiceinterface:Task<bool> CanNavigate<TViewModel>andTask<bool> CanNavigate(Type viewModelType).
IMvxCommand
- The method
RaiseCanExecuteChangedwas added to theIMvxCommandinterface.
Logging
IMvxLog has a new method: bool IsLogLevelEnabled(MvxLogLevel logLevel).
Android
IMvxAndroidSplashScreenActivitywas removed. It was replaced byIMvxSetupMonitor, which is located on theMvvmCross.Corenamespace.- On both SplashScreen activities (traditional and AppCompat), the method
TriggerFirstNavigatewas removed.RunAppStartis it’s replacement. But in case you need to pass a hint to your custom AppStart, the method you should override isGetAppStartHint, which will receive the incomingBundleas a parameter. MvxRelativeLayout,MvxFrameLayoutandMvxTableLayoutwere removed as they were memory inefficient (nothing we can do to improve that).- If you were declaring any view on your .axml files which prefix is “Mvx…” using the entire namespace, then you might see your app breaking. This is because namespaces have changed for many views. Just remove the namespace and leave the widget name.
IMvxRecyclerViewHoldernow has a new property:int Id { get; set; }, which contains the LayoutId being used.MvxWakefulBroadcastReceiverwas removed, as it was deprecated by the platform.- The interface
IMvxTemplateSelectorhas a new property:int ItemTemplateId { get; set; }which will be filled with the default LayoutId or the one you set by .axml using the item template attr. - On
MvxAndroidViewPresenter,ShowIntenthas a new parameter. - On
MvxAppCompatViewPresenter,CreateActivityTransitionOptionschanged its return type. - As part of the shared elements evolution,
MvxActivityPresentationAttributeandMvxFragmentPresentationAttributehave lost some properties - they were deprecated. - On both presenters, callback methods like
OnBeforeFragmentChangingandOnFragmentChangednow forward theMvxViewModelRequestobject as a parameter.
WPF
MvxBaseWpfViewPresenterandMvxSimpleWpfViewPresenterwere removed. It is highly recommended that you migrate toMvxWpfViewPresenter.
iOS Support package
The package iOS-Support has been removed in v6. But this doesn’t mean we have deleted it! Most reusable bits are now part of the main lib, and the sidebar support is now a plugin that you can install on your iOS project.
Others
Some methods and classes that were marked as [Obsolete] previously, have been finally removed on MvvmCross 6. This includes:
MvxBaseFluentBindingDescription.Overwrite(...)MvxFluentBindingDescription.Described(...)IMvxConsumer(IoC)IMvxProducer(IoC)MvxIoCExtensions(all methods)MvxEventSourceTabActivity(Android)MvxTabActivity(Android)- Some constructos for
MvxCollectionViewCell(iOS)