MvvmCross 5.3
Announcing MvvmCross 5.3!
A new MvvmCross version is available on NuGet! Most of our focus went out to creating new ViewPresenters for Xamarin.Forms and improving the code around that. With that said we are proud to announce these new ViewPresenters! If you have been using the default presenters we provide, you will find them very familiar. They work using the same view attributes system and are super flexible. But that is not everything. With MvvmCross 5.3, you will now be able to mix and match Native Xamarin views with Xamarin.Forms pages using ViewModel navigation!
Lets look at a sample view:
[MvxModalPresentation(WrapInNavigationPage = true, Title = "My Modal Page")]
public partial class MyModalViewPage : MvxContentPage<MyModalViewModel>
{
public MyModalViewPage()
{
InitializeComponent();
}
// your code
}
Supported attributes
- MvxContentPagePresentation
- MvxMasterDetailPagePresentation
- MvxModalPresentation
- MvxNavigationPagePresentation
- MvxTabbedPagePresentation
- MvxCarouselPagePresentation
There are also new MvvmCross base classes for all Xamarin.Forms Page types supporting DataBinding, ViewModels and more from code and layout files!
To take advantage of all those new features make sure to use the Xamarin.Forms base classes for Setup, Appdelegate and others.
Extended MvvmCross bindings support
Already possible
<Label mvx:La.ng="Text ThisIsLocalized" />
New bindings
<Label Text="{mvx:MvxLang ThisIsLocalizedToo}" />
<Label Text="{mvx:MvxBind TextSource, Mode=OneTime, Converter=Language, ConverterParameter=ThisIsLocalizedThroughMvxBind}" />
Presenters improvements
To make the mixing for Xamarin.Forms and Native Xamarin views possible we had to align all the presenters. We’ve now done that and they use the same structure with View Attributes. At the same time we improved those presenters and fixed issues with Dialogs and the MvxNavigationService.
Breaking changes for presenters using view attributes
Now iOS, Android, macOS and WPF ViewPresenters implement an interface called IMvxAttributeViewPresenter
, which is a common contract for all presenters using the view attributes system.
As part of this refactoring, the dictionary that hosts the attribute types / show delegates has become a dictionary with two delegates: one for show, one for close.
None of the behavior has changed, but since a few signatures have changed, if you are subclassing a presenter you will need to adjust your code. Please go straight to the presenter code if something doesn’t make sense, or ask us for help :).
Hooks for Fragments in Android
To get more control over your Fragment lifecycle - or Activity - and transitions, you can now override the folling methods (you can also modify your fragment transitions):
void OnFragmentChanged(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute);
void OnFragmentChanging(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute)
void OnFragmentPopped(FragmentTransaction ft, Fragment fragment, MvxFragmentPresentationAttribute attribute)
Android Activity transitions
In case you want to override the transition options between 2 activities you can override the folling method:
ActivityOptionsCompat CreateActivityTransitionOptions(Android.Content.Intent intent,MvxActivityPresentationAttribute attribute);
Open-Generic registration on IoC
There are situations where you have an interface with a generic type parameter IFoo<T>
and you have to register it in the IoC Container with different T types. One way to do this is to register it as many times as T types you have:
Mvx.RegisterType<IFoo<Bar1>, Foo<Bar1>>();
Mvx.RegisterType<IFoo<Bar2>, Foo<Bar2>>();
Mvx.RegisterType<IFoo<Bar3>, Foo<Bar3>>();
Mvx.RegisterType<IFoo<Bar4>, Foo<Bar4>>();
But this creates boilerplate code and in case you need another instance with a different T type, you have to register it as well, which is error prone. To solve this situation, you can now register this interface as open-generic, i.e. you don’t specify the generic type parameter in neither the interface nor the implementation:
Mvx.RegisterType<IFoo<>, Foo<>>();
Then at the moment of resolving the interface the implementation takes the same generic type parameter that the interface, e.g. if you resolve var foo = Mvx.Resolve<IFoo<Bar1>>();
then foo
will be of type Foo<Bar1>
.
As you can see this give us more flexibility and scalability because we can effortlessly change the generic type parameters at the moment of resolving the interface and we don’t need to add anything to register the interface with a new generic type parameter.
Change Log
5.3.0 (2017-10-13)
Fixed bugs:
- Pass MvxViewModelRequest.PresentationValues when navigating to Fragment on to it’s parent’s Activity when navigating #2237
- Wrong host activity gets shown #2222
- Close(this) is not working for Theme.Dialog on configuration change #1411
- MvxWindowsViewPresenter swallowing exceptions thrown in Init #1309
Closed issues:
- Make ViewAppeared and ViewAppearing return Task, for async purposes #2265
- Unable to update nuget packages from version 5.1.1 to version 5.2.1 (ANDROID) #2253
- [Android] Dialog doesn’t survive screen orientation change #2246
- [Android] Dismissing dialog via back button doesn’t cancel Task #2245
- Can’t install MvvmCross 5.2.1 in Xamarin Forms PCL Project #2240
- OnStop needs a null check #2238
- IMvxOverridePresentationAttribute not working of any Android view #2225
- 2 Factor Login required for the MvvmCross organization from 22 September #2195
- New nav service “deep link” conflict with viewmodel parameters when param is string #2080
- MvxStringToTypeParser doesn’t support decimal. #1635
- 4.5MB of MvxFragmentAttribute generated when starting up https://github.com/Noires/MvxRecyclerViewLeakTest #1368
- Parameterless Prepare() not called #2233
- Feature Suggestion - Side by side Xamarin iOS/Android and Xamarin Forms #1889
Merged pull requests:
- Forms presenters #2269 (Grrbrr404)
- Uwp handling BackRequestedEventArgs.Handled #2266 (duglah)
- Xamarin-Sidebar for iOS updated #2264 (DarthRamone)
- Added mixed navigation scenario #2263 (Grrbrr404)
- Fix Playground.iOS storyboard and add document for iOS UI approaches #2262 (nmilcoff)
- Update the docs for Android presenters for Fragment lifecycle #2260 (KoenDeleij)
- Added documentation to IoC Open-Generic registration #2259 (fedemkr)
- Update File plugin docs #2258 (mauricemarkvoort)
- Fix close for DialogFragments when using MvxNavigationService #2256 (nmilcoff)
- Android ViewPresenter: Copy PresentationValues when Showing a new Activity Host #2255 (nmilcoff)
- 2236 - updated nuspec with Xamarin.Android.Support.Exif dependency #2254 (msioen)
- Updated 3rd party plugins list #2251 (lothrop)
- Separate the transition logic #2250 (KoenDeleij)
- Allow multiple attributes / hosts for Viewpager/TabLayout fragments #2249 (nmilcoff)
- Update docs: getting started/packages #2244 (mauricemarkvoort)
- Added OpenGenerics feature to the IoC #2242 (fedemkr)
- Added & fixed null checks #2241 (F1nZeR)
- MvxAppCompatActivity: Add null check for OnStop #2239 (nmilcoff)
- Update Forms packages #2235 (martijn00)
- [WIP] New Xamarin.Forms presenters #2187 (martijn00)
- Direct Forms bindings with MvxBind and MvxLang #1763 (LRP-sgravel)
5.2.1 (2017-09-26)
Fixed bugs:
- Wrong ViewModel data in cached Fragment #1986
- Binding in an MvxFragment is incorrectly resetting modified values #1264
Closed issues:
- Exception in MvxAppCompatDialogFragment<T> #2220
- Initialize is not called #2212
- MvxNSSwitchOnTargetBinding appears in MvvmCross.Mac and MvvmCross.Binding.Mac #2205
- WindowController from Storyboard (Mac) gets disposed #2198
- Programmatically switching tabbed viewmodels from RootViewModel - Mac #2191
- Where is that IFactory<T>? #2186
- Hang when awaiting code in Initialize in 5.2 #2182
- Support Toolbar and Unified Toolbar bindings by view for Mac #2180
- Missing StarterPack for MvvmCross.Forms #2073
- Wrong behavior on Move in MvxCollectionViewSourceAnimated #2061
- Fragment viewmodel life-cycle events are not called if viewmodel has saved state and calling ShowViewModel<FragmentViewModel>(data) with data #1373
Merged pull requests:
- Documentation improvements for ViewModel lifecycle and Android Presenter #2229 (nmilcoff)
- Fix and workaround IMvxOverridePresentationAttribute Android #2226 (Plac3hold3r)
- Add obsolete attribute #2224 (jz5)
- Add ctor for generic fragment #2221 (martijn00)
- MvvmCross Forms StarterPack update #2219 (mauricemarkvoort)
- MvxListview for Forms with “ItemClick command” #2218 (MarcBruins)
- Updated to new VS2017 extension #2217 (jimbobbennett)
- nspopup goodies #2214 (tofutim)
- Make sure the binding context is created when loading from nib #2213 (mvanbeusekom)
- fix missing OneWay on toggle #2209 (tofutim)
- change FillBindingNames argument to ‘registry’ to be consistent #2208 (tofutim)
- add NSMenuItem command and state binding - Mac #2207 (tofutim)
- remove stray NSSwitchOnTargetBinding #2206 (tofutim)
- Fixed typo #2203 (Digifais)
- Add weak table to tie NSWindow and NSWindowController #2201 (tofutim)
- Android ViewPresenter: Simple caching strategy for fragments #2200 (nmilcoff)
- Add ability to set a default value for an attribute #2197 (martijn00)
- Cache parser variable to improve performance #2196 (willsb)
- Re-add the generic navigate to the interface for unit-tests #2194 (martijn00)
- Feature/mactabviewcontroller #2193 (tofutim)
- Move creating of attributes to method #2190 (martijn00)
- Fix hang in Initialize when called from Navigation app start #2189 (jimbobbennett)
- update MvxWindowPresentation to support creation from Storyboard for Mac #2185 (tofutim)
- Add a constructor with a binding context #2184 (wh1t3cAt1k)
- Update messenger.md #2183 (mauricemarkvoort)