During the BUILD 2018, I was announcing the arrival of Xamarin Essentials., a software library making life easier for Xamarin developers.

This one just got upgraded to version 1.1 and we're going to find out together what's new.

Original illustration unavailable

The new features

Four new features are emerging:

one to help facilitate the use of colours

a helper to facilitate the use of sizes (Point, Size, Rectangle)

– the ability to customize browser colors

the possibility of detecting an earthquake

Color Helper

In Xamarin applications a helper was always needed to convert colors from one format to another.

To obtain a color from a hexadecimal code it is sufficient to:


System.Drawing.Color red = ColorConverters.FromHex("#FF0000");

Once the colour is created, there are a number of extension methods to change it simply:

All of them

MultiplyAlpha,

WithHue,

WithAlpha,

WithSaturation,

WithLuminosity,

This colour may be easily converted to platform colour by the following method:


var platformColor = red.ToPlatformColor();

The reverse is also possible:


var platformColor = UIColor.Red;
var systemColor = platformColor .ToSystemColor();

More info, this way.

Size Helper

Converting units of measurement (Point, Rectangle, Size...) into universal structures has never been easy.

With these new APIs, everything is managed for us.

Example d’use with the structure Point:


var system = new System.Drawing.Point(x, y);

// Convertit vers CoreGraphics.CGPoint, Android.Graphics.Point, etWindows.Foundation.Point
var platform = system.ToPlatformSize();

// Reconvertit vers System.Drawing.Point
var system2 = platform.ToSystemSize();

Classes System . Drawing . Point, System. Drawing. Rectangle, System. Drawing. Size are managed by default.

More info, this way.

Detecting earthquakes

The first thing to detect tremors is to subscribe to the method ShakeDetected.


Accelerometer.ShakeDetected  += ShakeDetected;

Then we can customize the code when an earthquake is detected.


private void Accelerometer_ShakeDetected (object sender, EventArgs e)
{
     Debug.WriteLine("Secousse détectée");
}

More info, this way.

Open your browser, more personalization

The first version of the Browser.OpenAsync API allowed the browser to be opened without any other burst.

With this API update, Xamarin Essentials gives us access to more personalization:

– ability to customize the color of the browser closing buttons

– the ability to view the TitleBar or not

Open the browser with the new options:


await Browser.OpenAsync(uri, new BrowserLaunchOptions
                {
                    LaunchMode = BrowserLaunchMode.SystemPreferred,
                    TitleMode = BrowserTitleMode.Show,
                    PreferredToolbarColor = Color.Red,
                    PreferredControlColor = Color.Pink
                });

More info, this way.

Fixed bug

This version also contains 6 fixed bugs, 5 of which were corrected by the community.

  • GH-714 Fixes a bug on the launch of iOS Uri .
  • GH-698 Fixes a bug in the connectivity display on Android
  • GH-704 Fixes a bug on the SecureStorage iOS
  • GH-694 VS d’Hyper V emulators are now detected as emulators
  • GH-636 Optimization of preferences
  • GH-707 Fixes the sending of empty mail to UWP

Support for other platforms?

Two platforms are currently supported:

  • macOS
  • Tizen

Adding the macOS backend is more than half of its development.

The addition of Tizen is done in collaboration with Samsung's teams. This one's almost finished.

To conclude:

The arrival of Xamarin Essentials has really made life easier for Xamarin developers, and the fact that the Xamarin teams are enriching this library day by day is good news for us.

Happy coding 🙂

To go further: