I need your feedback, and I need it now! I have been working on the next version of Prism for Xamarin.Forms and need your help making sure I’m adding value and solving issues that prevent you from being productive. As of now, you can download the latest Prism for Xamarin.Forms 6.3 Preview from NuGet.
Check out the available NuGet packages here: https://github.com/PrismLibrary/Prism/blob/master/docs/NuGet-Packages.md
I have added a number of new features and improvements based on community feedback, and some of these changes will be breaking. Yes, I know… I hate releasing breaking changes. It annoys me just as much as it annoys you, but sometimes to move something forward we have to correct past oversights and bad decisions. So let’s take a quick look at what you can expect to see and break in this newest 6.3 Preview.
DelegateCommand.FromAsyncHandler is Obsolete
Yes, you read that correctly. DelegateCommand has this static methods that allows you to create an “async command”. The Microsoft team added this in the v5 release and I have never really given it much thought since. Until recently, when a number of people have noticed many issues with DelegateCommand not working as expected. Long story short, trying to have DelegateCommand act async is a bad idea, and needs to be fixed ASAP. You can read more about here is my last post announcing this. This will be a breaking change when we RTM 6.3.
OnNavigatingTo added to INavigationAware – Breaking
Based on very popular demand, there is a new OnNavigatingTo method being added to the INavigationAware interface. This method was added to fix the issue of trying to initialize ViewModels with data being passed in as parameters. Currently, if you pass parameters to the target ViewModel and set properties, there is a visible delay when the View updates to reflect those values. This is because the View has already been pushed onto the navigation stack, and then the bindings are updated after the properties have been set. Now, you can use the new OnNavigatingTo, which is called before the target View is pushed onto the navigation stack, in order to initialize your data. Now, you will no longer have that delay in displaying your data.
IConfirmNavigation/IConfirmNavigationAsync changes – Breaking
This is probably not that big of a deal, but the IConfirmNavigation and IConfirmNavigationAsync interfaces no longer depend on the INavigationAware interface. I had a ton of feedback that when using IConfirmNavigation, you may not always be dealing with handling the INavigationAware methods. So this dependency has been removed. Chances are, you won’t even notice it.
Hardware/software back button support
This was a major limitation in the Prism navigation service. Previously, when you would use the hardware back buttons, or the software back button to navigate back to a previous View, the INavitaionAware methods would never fire. This has now been fixed! The only limitation is when using the hardware/software back buttons, the new OnNavigatingTo method will not be invoked. Only the OnNavigatedFrom and OnNavigatedTo methods will be invoked. This is because when using the hardware/software back buttons, I have no way of invoking the OnNavigatingTo prior to the popping action occurring.
Another pain point in Xamarin.Forms development is memory leaks. Xamarin.Forms is notorious for not cleaning itself up. So, now you can use the IDestructible interface for both Views and ViewModels to clean up any resources you may have. Remove event handlers, unregister from CompositeCommands, close any streams that may be open. Whatever you need. I know what you are going to ask, “but Brian, why didn’t you use IDisposable?”. Well, I tried, but then quickly realized that Prism shouldn’t be the one calling IDisposable. Doing so caused a number of issues and exceptions. So, I had to introduce this new interface.
Another need feature is that TabbedPages can now be IActiveAware. This means that when the ViewModels of your tabs implement IActiveAware, Prism will keep track of which tab is the active tab. This is very powerful when combined with CompositeCommands.
The last feature that was added was a new IDeviceService interface which gives you access to the Xamarin.Froms Device properties and methods. You can now perform Device functions without having to reference a static class in your ViewModels. You are just a little more testable now.
Prism Template Pack
Besides improving the Prism for Xamarin.Forms platform, I also made a number of improvements to the Prism Template Pack.
The project template dialog got a new face lift thanks to the designers at Infragistics. So now it looks much prettier.
There was also a nice productivity change to the item templates provided in the Prism Template Pack. Now when you add a new View by selecting Add New Item –> Prism –> Xamarin.Forms –> Page, not only do you get a new Page, but you get a ViewModel, and the Page is registered for navigation for you automatically in the App.xaml.cs file. Now, you don’t have to do anything! Prism does it for you.
Add a new view:
A View and ViewModel are added to your project:
And the View is registered for navigation automatically:
Hopefully these new Prism Template Pack changes help you be more productive and take away some of that busy work.
As you can see, I have been hard at work trying to add value to Prism for Xamarin.Forms and make you more productive at the same time. Make sure to check out the release notes for a list of all the changes. Please test out all these new features shipping in the new preview. Prepare your apps for the breaking changes.
I will be working on updating the documentation, which as you know is always the last thing that a developer does. I will also work on getting some new samples in the repo that covers all the cool features Prism for Xamarin.Forms provides. I am also starting work on a brand new Prism for Xamarin.Forms Pluralsight course. So keep an eye out on my course list which can be seen on my author page for this new course.
Please, get involved with the project on GitHub. Be sure to provide your feedback, submit issues, submit features, and submit PR’s. This is your project, so make it what you want it to be. As always, feel free contact me on my blog, connect with me on Twitter (@brianlagunas), or leave a comment below for any questions or comments you may have.