In early December, Brian Lagunas announced a pre-release of Prism for Xamarin.Forms 6.2.0. Over Christmas I checked it out and here’s what I found out.
The big changes are around bootstrapping and navigation, with simplification and new features being the order of the day. There are also some breaking changes, in that INavigationPageProvider and NavigationPageProviderAttribute have both been removed as they are no longer needed due to the INavigationService handling the majority of navigation scenarios now.
Bootstrapping
The CreateMainPage and InitializeShell methods are now deprecated, with the OnInitialized override now being used to navigate to the initial page of the app:
The page being navigated to is registered in the RegisterTypes override, with navigation then being invoked from the OnInitialized override. As well as being a simpler app bootstrapping process, it also removes the problems with some navigation scenarios on startup, such as navigating to a MasterDetailPage and then changing the Detail page,.
Navigation
The INavigationService now supports a number of new features, including passing parameters via the GoBack method, support for URI-based navigation, and deep linking. For information about the new navigation features see Brian’s blog post.
The INavigationService now detects the type type of page being navigated from, and handles the navigation for you. For example, it will detect that navigation is originating from a MasterDetailPage and will set the MasterDetailPage.Detail property to the navigation target, instead of pushing a new page onto the navigation stack.
In addition, the INavigationService supports more complex navigation scenarios. For example, imagine that you want your app to navigate to a MasterDetailPage that sets the Detail page to a NavigationPage, and then displays a ContentPage. As with all Prism-based apps, the pages must first be registered with the navigation service:
After registering the pages, it then becomes possible to perform the required navigation in one call:
The result of the navigation will show a MasterDetailPage whose Detail page is a NavigationPage, with the MonthPage being pushed onto the navigation stack for display. In addition, the navigation stack will be as expected, and so backwards navigation will return down the stack.
For me this is the killer feature in this release of Prism for Xamarin.Forms, as when combined with the URI-based navigation support and parameter passing, it becomes possible to launch a Xamarin.Forms app from a website and deep link to content within the app, while maintaining the correct navigation stack.
Summary
The original release of Prism for Xamarin.Forms was a welcome addition to the Prism family, and simplified the development of Xamarin.Forms apps. However, it was slightly restrictive in some areas, but with the preview release of Prism for Xamarin.Forms 6.2.0 the majority of these restrictions no longer exist.
While not everyone is a believer in using such libraries in mobile app development, Prism for Xamarin.Forms offers a clear productivity boost and simplifies the development of fully unit testable Xamarin.Forms apps that have a clean separation of concerns. Going forward I’ll certainly be using it for my own app development efforts, and I look forward to it moving from a pre-release to a stable release.