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.Platform
is nowMvvmCross.Forms.Core
.MvvmCross.Forms.{Platform}
is nowMvvmCross.Forms.Platforms.{Platform}
.
Core and all platforms
MvvmCross.Platform
namespace is nowMvvmCross
.- Most framework core classes are now under the namespace
MvvmCross.Base
. MvvmCross.Platform.{Platform}.Platform
is nowMvvmCross.Platforms.{Platform}.Base
.MvvmCross.Binding.{Platform}
namespace is nowMvvmCross.Platforms.{Platform}.Binding
.MvvmCross.Core.Platform.Converters
namespace is nowMvvmCross.Converters
MvvmCross.Core.Platform
namespace is nowMvvmCross.Core
.- Platform initialization code (Setup classes, ..) was moved from
MvvmCross.{Platform}.Platform
to the namespaceMvvmCross.Platforms.{Platform}.Core
. MvvmCross.Platform.{Platform}.Views
is now under the namespace namespaceMvvmCross.Platforms.{Platform}.Views.Base
.MvvmCross.Platform.UI
namespace is nowMvvmCross.UI
.MvvmCross.Platform.Exceptions
namespace is nowMvvmCross.Exceptions
- All PresentationHints are now at
MvvmCross.Presenters.Hints
. MvvmCross.Core.ViewModels
namespace is nowMvvmCross.ViewModels
.MvvmCross.{Platform}.Platform
namespace is nowMvvmCross.Platforms.{Platform}.Core
.MvvmCross.{Platform}.ViewModels
namespace is nowMvvmCross.Platforms.{Platform}.ViewModels
.MvvmCross.{Platform}.Views
namespace is nowMvvmCross.Platforms.{Platform}.Views
.MvvmCross.Core.Views
namespace is nowMvvmCross.Views
.MvvmCross.Platform.ExtensionMethods.MvxCrossCoreExtensions
class is nowMvvmCross.Base.MvxCoreExtensions
.MvvmCross.Platform.WeakSubscription
namespace is nowMvvmCross.WeakSubscription
.MvvmCross.Test.Core
namespace is nowMvvmCross.Tests
.JetBrains.Annotations
namespace is nowMvvmCross.Annotations
.
IoC
- All IoC related code was moved from
MvvmCross.Platform.IoC
toMvvmCross.IoC
. MvxSimpleIoCContainer
is 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.Logging
is nowMvvmCross.Logging
.MvvmCross.Core.Platform.LogProviders
namespace is nowMvvmCross.Platforms.Logging.LogProviders
.
Navigation
MvvmCross.Core.Navigation
is nowMvvmCross.Navigation
.ShowViewModel
andMvxNavigatingObject
were removed.MvxNavigationService
should be used instead. Please take a look at the official documentation to learn about it.MvxNavigationServiceAppStart
was removed andMvxAppStart
uses 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}.Views
is now atMvvmCross.Platforms.{Platform}.Presenters
MvvmCross.{Platform}.Views.Attributes
toMvvmCross.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
Plugins
keyword is nowPlugin
. MvvmCross.Plugins.{PluginName}.{Platform}
is nowMvvmCross.Plugin.{PluginName}.Platforms.{Platform}
MvvmCross.Platform.Plugins
namespace 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
GetAppStartHint
on 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
. IMvxAppStart
has 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
Start
is now reserved and managed by the framework. If you are using a custom AppStart you should use the protected methodStartup
from now on.
Plugins
Color
- On Android, the method
ToAndroidColor
was renamed toToNativeColor
in 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.PresentationAttribute
now takes aMvxViewModelRequest
as parameter. If you’re using a custom ViewPresenter that extends the default provided by MvvmCross, be aware thatGetPresentationAttribute
andGetOverridePresentationAttribute
methods signatures have changed.MvxFormsPagePresenter
constructor 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
CreatePresenter
was renamed toCreateViewPresenter
. - On iOS and tvOS, the method
CleanupModalViewControllers
was renamed toCloseModalViewControllers
. - The method
NativeModalViewControllerDisappearedOnItsOwn
is now calledCloseTopModalViewController
. IMvxTvosModalHost
andIMvxIosModalHost
were deprecated and removed.- On iOS, the method
PresentModalViewController
was renamed toShowModalViewController
.
Navigation
IMvxNavigationService.ChangePresentation
is 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
IMvxNavigationService
interface:Task<bool> CanNavigate<TViewModel>
andTask<bool> CanNavigate(Type viewModelType)
.
IMvxCommand
- The method
RaiseCanExecuteChanged
was added to theIMvxCommand
interface.
Logging
IMvxLog
has a new method: bool IsLogLevelEnabled(MvxLogLevel logLevel)
.
Android
IMvxAndroidSplashScreenActivity
was removed. It was replaced byIMvxSetupMonitor
, which is located on theMvvmCross.Core
namespace.- On both SplashScreen activities (traditional and AppCompat), the method
TriggerFirstNavigate
was removed.RunAppStart
is 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 incomingBundle
as a parameter. MvxRelativeLayout
,MvxFrameLayout
andMvxTableLayout
were 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.
IMvxRecyclerViewHolder
now has a new property:int Id { get; set; }
, which contains the LayoutId being used.MvxWakefulBroadcastReceiver
was removed, as it was deprecated by the platform.- The interface
IMvxTemplateSelector
has 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
,ShowIntent
has a new parameter. - On
MvxAppCompatViewPresenter
,CreateActivityTransitionOptions
changed its return type. - As part of the shared elements evolution,
MvxActivityPresentationAttribute
andMvxFragmentPresentationAttribute
have lost some properties - they were deprecated. - On both presenters, callback methods like
OnBeforeFragmentChanging
andOnFragmentChanged
now forward theMvxViewModelRequest
object as a parameter.
WPF
MvxBaseWpfViewPresenter
andMvxSimpleWpfViewPresenter
were 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)