Xamarin.Essentials Adds Detect Shake, Browser Customization, Color Helpers, and More!



Xamarin.Essentials is your ultimate open source library to access native features from a single cross-platform API. Since the first release, we have received awesome feedback on GitHub from developers that integrated it into their apps. We have also received some great pull requests to add some new features and bug fixes that have gone into the newest release 1.1.0 that are available today. This includes the ability to detect shake movement of the device, customization when opening the browser, ability to check for mock location, and several platform helpers.

Detect Shake

Sometimes you need to detect shake movement of a device that your app is running on to open a feedback form or put the app into edit mode. Xamarin.Essentials’ built-in Accelerometer API gives you everything you need to calculate this cross-platform. Having to figure out all of the math and queue systems could be a bit much. So we figured why not just create a unique ShakeDetected event that you can register for. You will still have to start the Accelerometer, but now you have the option to get all changes or just when a shake is detected:

Browser Customization

When you need to launch a website the best approach is to use the built-in Open Browser from Xamarin.Essentials. It will automatically handle opening the system optimized browser with SFSafariViewController and Chrome Custom Tabs. In the new release of Xamarin.Essentials you now have more control over the look. You can also get the feel of the browser including the title visibility and the colors of the toolbar and controls.

Platform Helpers

The core goal of Xamarin.Essentials is to simplify cross-platform app development. Most of the APIs that are part of the library up until now have abstracted common platform features into a single API. Xamarin.Essentials 1.0 launched with a plethora of built-in unit converters such as converting Miles to kilometers or Celsius to Fahrenheit. With this release, we are pleased to introduce several key helper utilities for converting between .NET and platform structures such as Color, Rect, Size, and Point.

Color Converters

For System.Drawing.Color we want to bring all of the goodies that Xamarin.Forms developers are able to take advantage of such as creating color from Hsl, Hex, or UInt.

Additionally, you can easily convert System.Drawing.Color to the platform specific color structure:

Rect, Size, and Point Converters

Just like the Color extension methods to convert to and from the platform specific classes can be done with Size, Rect, and Point:

The same can be done for Rect with ToPlatformRectangle and ToSystemRectangle and for Point with ToPlatformPoint and ToSystemPoint.

Community Contributions

We want to call out the amazing community contributions that helped make this release possible:


Chris Dinon

Use Apply on Android Preferences (#636)

Niklas Schilli

Browser Customization APIs (#196)
Fix Launcher Sample (#629)

Pedro Jesus

Add IsFromMockProvider for Geolocation (#676)
Detect Shake API (#126)

We have also received several great bug reports and feature requests from the community, which has been great to see! If you are looking to help out simply head over to the Xamarin.Essentials GitHub page to open an issue or send a pull request.

Learn More

You can learn more by browsing the full Xamarin.Essentials documentation including new documentation for Detect Shake, Color Converters, Platform Extensions, Browser options, and more. Additionally, each week you can find a brand new Xamarin.Essentials API of the Week videos covering a single feature in just a few minutes.

James Montemagno

Principal Program Manager, Mobile Developers Tools

Follow James   

No Comments.