Hinge angle sensor for Uno Platform dual-screen apps

Recently, the Uno Platform team brought a significant new feature – full-fledged cross-platform support for dual-screen devices with the TwoPaneView. Today, Uno Platform gets support for another unique aspect of the upcoming Surface devices – the hinge angle sensor, just in time for the Microsoft 365 Developer Day for dual-screen devices! So how does it work?

Uno 💙 Surface
Uno 💙 Surface

UWP & Surface Neo

On Windows 10X with Universal Windows Platform we can use the Windows.Devices.Sensors.HingeAngleSensor API to be notified when the hinge’s angle changes:

var hinge = await HingeAngleSensor.GetDefaultAsync();
hinge.ReadingChanged += (sender, args) => Debug.WriteLine(args.Reading.AngleInDegrees);

view raw
HingeAngleSensor.cs
hosted with ❤ by GitHub

The HingeAngleReading.AngleInDegrees property gives us the hinge’s current angle in degrees. Super easy!

Uno Platform & Surface Duo

Surface Duo runs Android, so its API for hinge sensor is different. However, you don’t need to care about these differences if you use the Uno Platform! Just follow three simple steps:

  1. Reference the Uno.UI.DualScreen NuGet package in the Android project and update all Uno Platform packages to version 2.1.0-dev.1181 or newer
  2. Write your UWP code using Windows.Devices.Sensors.HingeAngleSensor in the shared project
  3. Run on Android!

With Uno Platform, your UWP implementation just works on Android. No platform-specific code required!

Note: The current version of the Surface Duo Emulator does not allow us to change the hinge angle yet. However, this is coming soon, according to the team. In the meantime, you can start developing your app today and it will then just light up once the sensor is available in the emulator.

Sample app

To showcase the cross-platform API, I have created a sample Uno Platform application which is available here on my GitHub.

Sample app running on Surface Duo emulator
Sample app running on Surface Duo emulator

Summary

It’s exciting to see the new dual screen device coming soon! Even though Surface Neo runs Windows 10X and Surface Duo runs Android, we can write our code once and run everywhere thanks to Uno Platform and new TwoPaneView and HingeAngleSensor APIs. So let’s Uno, Duo, Neo!

Buy me a coffeeBuy me a coffee

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.