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?
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:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|var hinge = await HingeAngleSensor.GetDefaultAsync();|
|hinge.ReadingChanged += (sender, args) => Debug.WriteLine(args.Reading.AngleInDegrees);|
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:
- Reference the
Uno.UI.DualScreenNuGet package in the Android project and update all Uno Platform packages to version 2.1.0-dev.1181 or newer
- Write your UWP code using
Windows.Devices.Sensors.HingeAngleSensorin the shared project
- 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.
We're working on that 🙂
— Guy Merin (@gmerin) February 5, 2020
To showcase the cross-platform API, I have created a sample Uno Platform application which is available here on my GitHub.
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
HingeAngleSensor APIs. So let’s Uno, Duo, Neo!