If you are new to Xamarin, one of the hardest things to understand in the early stages is which flavour of Xamarin to choose. Should you target specific platform UIs with Xamarin.Platform or write a single XAML UI with Xamarin.Forms?
Why are there two choices? How is the Xamarin newcomer supposed to choose? And why can it seem so difficult to get a straight answer?
What is Xamarin.Platform?
Let’s start by being clear that Xamarin IS native. It was born out of Mono, the original cross-platform version of .Net. By wrapping the standard Android and iOS platform APIs, they allow apps to be written in C#. In this form of Xamarin, user interfaces are created in the same way you would develop a Java Android app or a Swift/Objective-C iOS app.
This traditional way of writing Xamarin apps is officially known as Xamarin.Platform, but as it simply wraps the native APIs, it is also sometimes referred to as Xamarin Native or Native UI.
What is Xamarin.Forms?
Xamarin.Forms is a framework that runs on top of Xamarin.Platform allowing a single XAML or C# UI to be written to target several platforms at once.
Having once been considered a non-starter for high-profile customer-facing apps, Xamarin.Forms continues to grow in stature. Now with a XAML previewer, quick-start scaffolding and theming options and wide community support, Xamarin.Forms has become a serious option for any new project.
Forms is Fast, Native UIs give you control
The benefit of using Xamarin.Forms is greater than just the saving of having to build your UI over again for each new platform. The amount of context switching is massively reduced, and the barrier to entry for new developers is much lower, especially if you’ve done anything with XAML in the past. XAML is a lightweight UI technology and Xamarin.Forms lets you build Android, iOS and Windows applications quickly without having to know about Constraints, XCode, Adapters, Fragments etc. let alone having to master these or hand-off to a platform expert.
However, as with any abstraction layer, if it provides functionality that you don’t use, it may just get in the way. If you are building a highly customised application that doesn’t conform to the standard Xamarin.Forms controls and you find yourself consistently manipulating the underlying native controls using custom renderers and platform features, you may feel that you are better off going native the whole way.
The Pixel Perfect Layout Myth
It used to be said that you choose Native UI over Forms when you require pixel perfect design. I assume this slightly misleading phrase came about through the desire to have a simple rule of thumb to help new Xamarin developers. Unfortunately it has gained traction and seems to imply that in some way layout accuracy is the main difference. It’s just not that simple.
So, which one is right for you?
If you feel like there isn’t great guidance on how to choose, it is because every situation is different. What really matters here is context. The real reason forms might not work for you is if you are not prepared to compromise on a particular UI design and it happens to be one that leads you away from the intended usage of the standard Xamarin.Forms controls.
Custom Renderers and layouts are easy to create, but like any framework, it can only be bent so far. If you have the experience to build your own Android and iOS UIs, you may reach a point where Forms is getting in the way.
Don’t make a Forms vs Native choice based on your expectations of future designs
Agile development is about embracing change, and you can’t be sure how your application design will develop over time. Don’t make a Forms vs Native choice based on your expectations of future designs. Instead, think about the culture in which you work, the skill sets and experience of your team and whether speed of development is considered important enough to compromise on design perfection.
If you don’t have the experience to be sure that Native UI is right for you, choose Xamarin.Forms.
You can think of Native UI as the advanced option. Here’s my suggested rule of thumb: If you don’t have the experience to be sure that Native UI is right for you, choose Xamarin.Forms.
Make Xamarin.Forms the default
If you’re not sure which to choose, the safest option is to start with Forms. It will be good enough for a large percentage of mobile apps. Even if you change later, you’ll have built some lightweight XAML pages and controls having quickly prototyped your app experience and put an early version of your app in people’s hands. The waste is likely to be greater and the experience less useful if you start Native and later choose Forms.
With every new step forward in Xamarin.Forms, the percentage of apps that need to be written natively is slowly reduced. As Xamarin push Forms harder (now making it the core of their certification programme), it may not be long before Forms is the only serious option for cross-platform mobile development.