What’s coming in Xamarin.Forms 2.3

Xamarin.Forms is a great way to build your mobile app while reusing as much code as possible (including UI code). However, you might be faced with some limitations if you want an app deeply customized to a specific platform. The upcoming release Xamarin.Forms 2.3 looks at improving some of those limitations.

 

Native Controls

Version 2.3 will provide us with a new way to add native controls to our apps via XAML declaration. The limitation of native embedding, is that PCL projects are not supported. We can only use native controls in Shared Projects, which isn’t always ideal. Here’s a look of how it can be done:

What’s new, is  that it’s now also possible to use XAML instead of code behind. And, unlike native embedding, XAML declaration works in Portable Class Libraries as well. Depending on which control you want to use, you’ll need to add some (or all) of these namespaces:

And then, just use the controls like so (this example is unrelated to the one in code-behind above):

Note that you’ll have to disable XAML compilation for this to work. Also, if you try to access that control in your code behind you will get a compilation error. XAML embedding is a good solution if you’re able to do everything via binding. However, this approach won’t work for controls such as UISegmentedControl that you need to configure via code-behind (as seen in the previous example).

 

Platform Specifics

With Xamarin.Forms 2.3, we’ll be able to use some platform specifics functionalities in our app. As of now, 5 of them are documented:

  • iOS
    • Blur support for any VisualElement
    • Translucent navigation bar
  • Android
    • AdjustResize/AdjustPan
  • Windows Phone
    • Toolbar placement options
    • Partially collapsed navigation bar (with icons) on MasterDetailPage

They are quite easy to integrate in you app. Here’s a simple example that shows how to use the blur and the translucent navigation bar features on iOS:

The method .On<iOS> means that this code will be ignored on Android since those features are not available on that platform. We did run on some limitation while playing with them, notably concerning the blur. For example, it doesn’t seem to work properly with TableView and ViewCell, which can be a problem if you want to blur a screen that contains those controls.

 

Themes

With themes, we’ll be able to easily use pre-built themes such as Dark and Light colour scheme. It also features StyleClasses that can be applied to some controls in a way that will be familiar to web programmers using Bootstrap CSS classes to style their HTML. For instance,

will display a red button.

light-theme-sml

Previewer

A much awaited feature is the previewer, which lets us see our views on the fly without having to deploy the app to a device or a simulator. Here’s a screenshot of how it looks in action:

Xamarin.Forms Previewer

In theory, when you open a xaml file, you’ll see a « Preview » button on the upper right corner. Click on it and the previewer will open. Unfortunately, in real life scenarios, we did not have much luck getting it to work properly. Most of the times the « Preview » button will not show up at all, even after closing and reopening the xaml file. The previewer also wasn’t able to display views that were somewhat complex. The Previewer is still (ironically) in « Preview », so let’s hope that it will be more stable when officially released.

 

Recommended Posts

Laissez un commentaire